Prelude.Classy, plus some mathematical/floating-point functions
- module Prelude.Classy
- gcd :: Integral a => a -> a -> a
- lcm :: Integral a => a -> a -> a
- module Data.Ratio
- data Float
- data Double
- class Num a => Fractional a where
- (/) :: a -> a -> a
- recip :: a -> a
- fromRational :: Rational -> a
- class Fractional a => Floating a where
- class (Real a, Fractional a) => RealFrac a where
- class (RealFrac a, Floating a) => RealFloat a where
- floatRadix :: a -> Integer
- floatDigits :: a -> Int
- floatRange :: a -> (Int, Int)
- decodeFloat :: a -> (Integer, Int)
- encodeFloat :: Integer -> Int -> a
- exponent :: a -> Int
- significand :: a -> a
- scaleFloat :: Int -> a -> a
- isNaN :: a -> Bool
- isInfinite :: a -> Bool
- isDenormalized :: a -> Bool
- isNegativeZero :: a -> Bool
- isIEEE :: a -> Bool
- atan2 :: a -> a -> a
- (^^) :: (Fractional a, Integral b) => a -> b -> a
- realToFrac :: (Real a, Fractional b) => a -> b
Documentation
module Prelude.Classy
Mathematical functions
Fixed/floating-point math
module Data.Ratio
data Float
Single-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE single-precision type.
data Double
Double-precision floating point numbers. It is desirable that this type be at least equal in range and precision to the IEEE double-precision type.
class Num a => Fractional a where
Fractional numbers, supporting real division.
Minimal complete definition: fromRational
and (recip
or (
)
/
)
(/) :: a -> a -> a
fractional division
recip :: a -> a
reciprocal fraction
fromRational :: Rational -> a
Conversion from a Rational
(that is
).
A floating literal stands for an application of Ratio
Integer
fromRational
to a value of type Rational
, so such literals have type
(
.
Fractional
a) => a
Fractional Double | |
Fractional Float | |
Integral a => Fractional (Ratio a) |
class Fractional a => Floating a where
Trigonometric and hyperbolic functions and related functions.
Minimal complete definition:
pi
, exp
, log
, sin
, cos
, sinh
, cosh
,
asin
, acos
, atan
, asinh
, acosh
and atanh
class (Real a, Fractional a) => RealFrac a where
Extracting components of fractions.
Minimal complete definition: properFraction
properFraction :: Integral b => a -> (b, a)
The function properFraction
takes a real fractional number x
and returns a pair (n,f)
such that x = n+f
, and:
-
n
is an integral number with the same sign asx
; and -
f
is a fraction with the same type and sign asx
, and with absolute value less than1
.
The default definitions of the ceiling
, floor
, truncate
and round
functions are in terms of properFraction
.
truncate :: Integral b => a -> b
returns the integer nearest truncate
xx
between zero and x
returns the nearest integer to round
xx
;
the even integer if x
is equidistant between two integers
ceiling :: Integral b => a -> b
returns the least integer not less than ceiling
xx
returns the greatest integer not greater than floor
xx
class (RealFrac a, Floating a) => RealFloat a where
Efficient, machine-independent access to the components of a floating-point number.
Minimal complete definition:
all except exponent
, significand
, scaleFloat
and atan2
floatRadix :: a -> Integer
a constant function, returning the radix of the representation
(often 2
)
floatDigits :: a -> Int
a constant function, returning the number of digits of
floatRadix
in the significand
floatRange :: a -> (Int, Int)
a constant function, returning the lowest and highest values the exponent may assume
decodeFloat :: a -> (Integer, Int)
The function decodeFloat
applied to a real floating-point
number returns the significand expressed as an Integer
and an
appropriately scaled exponent (an Int
). If
yields decodeFloat
x(m,n)
, then x
is equal in value to m*b^^n
, where b
is the floating-point radix, and furthermore, either m
and n
are both zero or else b^(d-1) <= m < b^d
, where d
is the value
of
. In particular, floatDigits
x
.
decodeFloat
0 = (0,0)
encodeFloat :: Integer -> Int -> a
encodeFloat
performs the inverse of decodeFloat
the second component of decodeFloat
.
significand :: a -> a
the first component of decodeFloat
, scaled to lie in the open
interval (-1
,1
)
scaleFloat :: Int -> a -> a
multiplies a floating-point number by an integer power of the radix
True
if the argument is an IEEE "not-a-number" (NaN) value
isInfinite :: a -> Bool
True
if the argument is an IEEE infinity or negative infinity
isDenormalized :: a -> Bool
True
if the argument is too small to be represented in
normalized format
isNegativeZero :: a -> Bool
True
if the argument is an IEEE negative zero
True
if the argument is an IEEE floating point number
atan2 :: a -> a -> a
a version of arctangent taking two real floating-point arguments.
For real floating x
and y
,
computes the angle
(from the positive x-axis) of the vector from the origin to the
point atan2
y x(x,y)
.
returns a value in the range [atan2
y x-pi
,
pi
]. It follows the Common Lisp semantics for the origin when
signed zeroes are supported.
, with atan2
y 1y
in a type
that is RealFloat
, should return the same value as
.
A default definition of atan
yatan2
is provided, but implementors
can provide a more accurate implementation.
(^^) :: (Fractional a, Integral b) => a -> b -> a
raise a number to an integral power
realToFrac :: (Real a, Fractional b) => a -> b
general coercion to fractional types