zoukankan      html  css  js  c++  java
  • [haskell] 数值的类型

    Table 6.1. Selected Numeric Types

    TypeDescription
    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 two Integers.
    Word Fixed-precision unsigned integer; storage size same as Int
    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

    TypeBitsBoundedFloatingFractionalIntegralNumRealRealFrac
    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  
    Rational or any Ratio       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 TypeDestination Type
    DoubleFloatIntWordIntegerRational
    DoubleFloat fromRational . toRational truncate * truncate * toRational
    IntWord fromIntegral fromIntegral fromIntegral fromIntegral
    Integer fromIntegral fromIntegral N/A fromIntegral
    Rational fromRational truncate * truncate * N/A
     

    Table 6.2. Selected Numeric Functions and Constants

    ItemTypeModuleDescription
    (+) Num a => a -> a -> a Prelude Addition
    (-) Num a => a -> a -> a Prelude Subtraction
    (*) Num a => a -> a -> a Prelude Multiplication
    (/) Fractional a => a -> a -> a Prelude Fractional division
    (**) Floating a => a -> a -> a Prelude Raise to the power of
    (^) (Num a, Integral b) => a -> b -> a Prelude Raise a number to a non-negative, integral power
    (^^) (Fractional a, Integral b) => a -> b -> a Prelude Raise a fractional number to any integral power
    (%) Integral a => a -> a -> Ratio a Data.Ratio Ratio composition
    (.&.) Bits a => a -> a -> a Data.Bits Bitwise and
    (.|.) Bits a => a -> a -> a Data.Bits Bitwise or
    abs Num a => a -> a Prelude Absolute value
    approxRational RealFrac a => a -> a -> Rational Data.Ratio Approximate rational composition based on fractional numerators and denominators
    cos Floating a => a -> a Prelude Cosine. Also provided are acoscosh, and acosh, with the same type.
    div Integral a => a -> a -> a Prelude Integer division always truncated down; see also quot
    fromInteger Num a => Integer -> a Prelude Conversion from an Integer to any numeric type
    fromIntegral (Integral a, Num b) => a -> b Prelude More general conversion from any Integral to any numeric type
    fromRational Fractional a => Rational -> a Prelude Conversion from a Rational. May be lossy.
    log Floating a => a -> a Prelude Natural logarithm
    logBase Floating a => a -> a -> a Prelude Log with explicit base
    maxBound Bounded a => a Prelude The maximum value of a bounded type
    minBound Bounded a => a Prelude The minimum value of a bounded type
    mod Integral a => a -> a -> a Prelude Integer modulus
    pi Floating a => a Prelude Mathematical constant pi
    quot Integral a => a -> a -> a Prelude Integer division; fractional part of quotient truncated towards zero
    recip Fractional a => a -> a Prelude Reciprocal
    rem Integral a => a -> a -> a Prelude Remainder of integer division
    round (RealFrac a, Integral b) => a -> b Prelude Rounds to nearest integer
    shift Bits a => a -> Int -> a Bits Shift left by the specified number of bits, which may be negative for a right shift.
    sin Floating a => a -> a Prelude Sine. Also provided are asinsinh, and asinh, with the same type.
    sqrt Floating a => a -> a Prelude Square root
    tan Floating a => a -> a Prelude Tangent. Also provided are atantanh, and atanh, with the same type.
    toInteger Integral a => a -> Integer Prelude Convert any Integral to an Integer
    toRational Real a => a -> Rational Prelude Convert losslessly to Rational
    truncate (RealFrac a, Integral b) => a -> b Prelude Truncates number towards zero
    xor Bits a => a -> a -> a Data.Bits Bitwise exclusive or

     
     
  • 相关阅读:
    Linux下新磁盘挂载
    Centos6.5下Haproxy负载均衡搭建
    Linux下redis搭建与配置
    iptables-nat实现反向代理功能
    iptables防火墙规则的添加、删除、保存
    [Python]-tools
    [Python]-Game
    .[Linux]-部署Nagios监控
    [HTML]-web前端
    [Linux]-部署Zabbix监控
  • 原文地址:https://www.cnblogs.com/jiangzhen/p/2333184.html
Copyright © 2011-2022 走看看