[Haskell] numeric type

Source: Internet
Author: User
Tags integer division natural logarithm

Table 6.1. Selected numeric types

Type Description
Double Double-precision floating point. A common choice for floating-point data.
Float Single-precision floating point. Often used when interfacing with C.
Int Fixed-precision signed integer; minimum range [-2 ^ 29 .. 2 ^ 29-1]. commonly used.
Int8 8-bit signed integer
Int16 16-bit signed integer
Int32 32-bit signed integer
Int64 64-bit signed integer
Integer Arbitrary-precision signed integer; range limited only by machine resources. commonly used.
Rational Arbitrary-precision rational numbers. stored as a ratio of twoIntegerS.
Word Fixed-precision unsigned integer; storage size sameInt
Word8 8-bit unsigned integer
Word16 16-bit unsigned integer
Word32 32-bit unsigned integer
Word64 64-bit unsigned integer

Table 6.3. typeclass instances for numeric types

Type Bits Bounded Floating Fractional Integral Num Real Realfrac
Double     X X   X X X
Float     X X   X X X
Int X X     X X X  
Int16 X X     X X X  
Int32 X X     X X X  
Int64 X X     X X X  
Integer X       X X X  
RationalOr anyRatio       X   X X X
Word X X     X X X  
Word16 X X     X X X  
Word32 X X     X X X  
Word64 X X     X X X

 

Table 6.4. Conversion between numeric types

Source Type Destination type
Double,Float Int,Word Integer Rational
Double,Float Fromrational. torational Truncate* Truncate* Torational
Int,Word Fromintegral Fromintegral Fromintegral Fromintegral
Integer Fromintegral Fromintegral N/ Fromintegral
Rational Fromrational Truncate* Truncate* N/

Table 6.2. Selected numeric functions and constants

Item Type Module Description
(+) Num A => A-> Prelude Addition
(-) Num A => A-> Prelude Subtraction
(*) Num A => A-> Prelude Multiplication
(/) Fractional A => A-> Prelude Fractional Division
(**) Floating A => A-> Prelude Raise to the power
(^) (Num A, integral B) => A-> B-> Prelude Raise a number to a non-negative, integral power
(^) (Fractional A, integral B) => A-> B-> Prelude Raise a fractional number to any integral power
(%) Integral A => A-> Ratio Data. Ratio Ratio Composition
(.&.) Bits A => A-> Data. Bits Bitwise AND
(. | .) Bits A => A-> Data. Bits Bitwise OR
ABS Num A => A-> Prelude Absolute Value
Approxrational Realfrac A => A-> rational Data. Ratio Approximate rational composition based on Fractional numerators and denominators
Cos Floating A => A-> Prelude Cosine. Also provided areACOs,Cosh, AndAcossh, With the same type.
Div Integral A => A-> Prelude Integer Division always truncated down; see alsoQuot
Frominteger Num A => integer-> Prelude Conversion fromIntegerTo any numeric type
Fromintegral (Integral A, num B) => A-> B Prelude More general conversion from anyIntegralTo any numeric type
Fromrational Fractional A => rational-> Prelude Conversion fromRational. May be lossy.
Log Floating A => A-> Prelude Natural logarithm
Logbase Floating A => A-> Prelude Log with explicit Base
Maxbound Bounded A => Prelude The maximum value of a bounded type
Minbound Bounded A => Prelude The minimum value of a bounded type
MoD Integral A => A-> Prelude Integer Modulus
Pi Floating A => Prelude Mathematical constant pi
Quot Integral A => A-> Prelude Integer Division; fractional part of quotient truncated towards zero
Recip Fractional A => A-> Prelude Reciprocal
Rem Integral A => A-> Prelude Remainder of Integer Division
Round (Realfrac A, integral B) => A-> B Prelude Rounds to nearest integer
Shift Bits A => A-> int-> Bits Shift left by the specified number of BITs, which may be negative for a right shift.
Sin Floating A => A-> Prelude SINE. Also provided areAsin,Sinh, AndAsinh, With the same type.
SQRT Floating A => A-> Prelude Square Root
Tan Floating A => A-> Prelude Tangent. Also provided areAtan,Tanh, AndAtanh, With the same type.
Tointeger Integral A => A-> integer Prelude Convert anyIntegralToInteger
Torational Real A => A-> rational Prelude Convert losslesslyRational
Truncate (Realfrac A, integral B) => A-> B Prelude Truncates number towards zero
XOR Bits A => A-> Data. Bits Bitwise exclusive or

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.