[haskell] 数值的类型

Table 6.1. Selected Numeric Types

TypeDescription
DoubleDouble-precision floating point. A common choice for floating-point data.
FloatSingle-precision floating point. Often used when interfacing with C.
IntFixed-precision signed integer; minimum range [-2^29..2^29-1]. Commonly used.
Int88-bit signed integer
Int1616-bit signed integer
Int3232-bit signed integer
Int6464-bit signed integer
IntegerArbitrary-precision signed integer; range limited only by machine resources. Commonly used.
RationalArbitrary-precision rational numbers. Stored as a ratio of two Integers.
WordFixed-precision unsigned integer; storage size same as Int
Word88-bit unsigned integer
Word1616-bit unsigned integer
Word3232-bit unsigned integer
Word6464-bit unsigned integer

Table 6.3. Typeclass Instances for Numeric Types

TypeBitsBoundedFloatingFractionalIntegralNumRealRealFrac
Double  XX XXX
Float  XX XXX
IntXX  XXX 
Int16XX  XXX 
Int32XX  XXX 
Int64XX  XXX 
IntegerX   XXX 
Rational or any Ratio   X XXX
WordXX  XXX 
Word16XX  XXX 
Word32XX  XXX 
Word64XX  XXX

 

 

Table 6.4. Conversion Between Numeric Types

Source TypeDestination Type
DoubleFloatIntWordIntegerRational
DoubleFloatfromRational . toRationaltruncate *truncate *toRational
IntWordfromIntegralfromIntegralfromIntegralfromIntegral
IntegerfromIntegralfromIntegralN/AfromIntegral
RationalfromRationaltruncate *truncate *N/A
 

Table 6.2. Selected Numeric Functions and Constants

ItemTypeModuleDescription
(+)Num a => a -> a -> aPreludeAddition
(-)Num a => a -> a -> aPreludeSubtraction
(*)Num a => a -> a -> aPreludeMultiplication
(/)Fractional a => a -> a -> aPreludeFractional division
(**)Floating a => a -> a -> aPreludeRaise to the power of
(^)(Num a, Integral b) => a -> b -> aPreludeRaise a number to a non-negative, integral power
(^^)(Fractional a, Integral b) => a -> b -> aPreludeRaise a fractional number to any integral power
(%)Integral a => a -> a -> Ratio aData.RatioRatio composition
(.&.)Bits a => a -> a -> aData.BitsBitwise and
(.|.)Bits a => a -> a -> aData.BitsBitwise or
absNum a => a -> aPreludeAbsolute value
approxRationalRealFrac a => a -> a -> RationalData.RatioApproximate rational composition based on fractional numerators and denominators
cosFloating a => a -> aPreludeCosine. Also provided are acoscosh, and acosh, with the same type.
divIntegral a => a -> a -> aPreludeInteger division always truncated down; see also quot
fromIntegerNum a => Integer -> aPreludeConversion from an Integer to any numeric type
fromIntegral(Integral a, Num b) => a -> bPreludeMore general conversion from any Integral to any numeric type
fromRationalFractional a => Rational -> aPreludeConversion from a Rational. May be lossy.
logFloating a => a -> aPreludeNatural logarithm
logBaseFloating a => a -> a -> aPreludeLog with explicit base
maxBoundBounded a => aPreludeThe maximum value of a bounded type
minBoundBounded a => aPreludeThe minimum value of a bounded type
modIntegral a => a -> a -> aPreludeInteger modulus
piFloating a => aPreludeMathematical constant pi
quotIntegral a => a -> a -> aPreludeInteger division; fractional part of quotient truncated towards zero
recipFractional a => a -> aPreludeReciprocal
remIntegral a => a -> a -> aPreludeRemainder of integer division
round(RealFrac a, Integral b) => a -> bPreludeRounds to nearest integer
shiftBits a => a -> Int -> aBitsShift left by the specified number of bits, which may be negative for a right shift.
sinFloating a => a -> aPreludeSine. Also provided are asinsinh, and asinh, with the same type.
sqrtFloating a => a -> aPreludeSquare root
tanFloating a => a -> aPreludeTangent. Also provided are atantanh, and atanh, with the same type.
toIntegerIntegral a => a -> IntegerPreludeConvert any Integral to an Integer
toRationalReal a => a -> RationalPreludeConvert losslessly to Rational
truncate(RealFrac a, Integral b) => a -> bPreludeTruncates number towards zero
xorBits a => a -> a -> aData.BitsBitwise exclusive or

 
 

转载于:https://www.cnblogs.com/jiangzhen/archive/2012/01/31/2333184.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值