Module std.math
Contains the elementary mathematical functions (powers, roots,
and trigonometric functions), and low-level floating-point operations.
Mathematical special functions are available in
.
std.mathspecial
Category | Members |
---|---|
Constants | E PI PI_2 PI_4 M_1_PI
M_2_PI M_2_SQRTPI LN10 LN2
LOG2 LOG2E LOG2T LOG10E
SQRT2 SQRT1_2
|
Classics | abs fabs sqrt cbrt hypot poly
|
Trigonometry | sin cos tan asin acos
atan atan2 sinh cosh tanh
asinh acosh atanh expi
|
Rounding | ceil floor round lround
trunc rint lrint nearbyint
rndtol
|
Exponentiation & Logarithms | pow exp exp2 expm1 ldexp
frexp log log2 log10 logb
ilogb log1p scalbn
|
Modulus | fmod modf remainder
|
Floating-point operations | approxEqual feqrel fdim fmax
fmin fma nextDown nextUp
nextafter NaN getNaNPayload
cmp
|
Introspection | isFinite isIdentical isInfinity isNaN
isNormal isSubnormal signbit sgn
copysign
|
Complex Numbers | abs conj sin cos expi
|
Hardware Control | IeeeFlags FloatingPointControl
|
The functionality closely follows the IEEE754-2008 standard for
floating-point arithmetic, including the use of camelCase names rather
than C99-style lower case names. All of these functions behave correctly
when presented with an infinity or NaN
.
The following IEEE 'real' formats are currently supported:
- 64 bit Big-endian 'double' (eg PowerPC)
- 128 bit Big-endian 'quadruple' (eg SPARC)
- 64 bit Little-endian 'double' (eg x86-SSE2)
- 80 bit Little-endian, with implied bit 'real80' (eg x87, Itanium)
- 128 bit Little-endian 'quadruple' (not implemented on any known processor!)
- Non-IEEE 128 bit Big-endian 'doubledouble' (eg PowerPC) has partial support
Status
The semantics and names of feqrel
and approxEqual
will be revised.
Functions
Name | Description |
---|---|
abs
|
Calculates the absolute value of a number |
acos
|
Calculates the arc cosine of x ,
returning a value ranging from 0 to π.
|
acosh
|
Calculates the inverse hyperbolic cosine of x .
|
approxEqual
|
Returns .
|
approxEqual
|
Computes whether is approximately equal to
admitting a maximum relative difference and a
maximum absolute difference .
|
asin
|
Calculates the arc sine of x ,
returning a value ranging from -π/2 to π/2.
|
asinh
|
Calculates the inverse hyperbolic sine of x .
|
atan
|
Calculates the arc tangent of x ,
returning a value ranging from -π/2 to π/2.
|
atan2
|
Calculates the arc tangent of y / x ,
returning a value ranging from -π to π.
|
atanh
|
Calculates the inverse hyperbolic tangent of x ,
returning a value from ranging from -1 to 1.
|
cbrt
|
Calculates the cube root of x .
|
ceil
|
Returns the value of x rounded upward to the next integer
(toward positive infinity).
|
cmp
|
Defines a total order on all floating-point numbers. |
conj
|
Complex conjugate |
copysign
|
Return a value composed of to with from 's sign bit.
|
cos
|
cosine, complex and imaginary |
cos
|
Returns cosine of x . x is in radians.
|
cos
|
cosine, complex and imaginary |
cosh
|
Calculates the hyperbolic cosine of x .
|
exp
|
Calculates ex .
|
exp2
|
Calculates 2x .
|
expi
|
Calculate cos (y ) + i sin (y ).
|
expm1
|
Calculates the value of the natural logarithm base (e)
raised to the power of x , minus 1.
|
fabs
|
Returns |x |
|
fdim
|
Returns the positive difference between x and y .
|
feqrel
|
To what precision is x equal to y ?
|
floor
|
Returns the value of x rounded downward to the next integer
(toward negative infinity).
|
fma
|
Returns (x * y ) + z , rounding only once according to the
current rounding mode.
|
fmax
|
Returns the larger of x and y .
|
fmin
|
Returns the smaller of x and y .
|
fmod
|
Calculates the remainder from the calculation x /y .
|
frexp
|
Separate floating point value into significand and exponent.
|
getNaNPayload
|
Extract an integral payload from a . |
hypot
|
Calculates the length of the
hypotenuse of a right-angled triangle with sides of length x and y .
The hypotenuse is the value of the square root of
the sums of the squares of x and y :
|
ieeeFlags
|
Return a snapshot of the current state of the floating-point status flags. |
ilogb
|
Extracts the exponent of x as a signed integral value.
|
isFinite
|
Determines if x is finite.
|
isIdentical
|
Is the binary representation of x identical to y ?
|
isInfinity
|
Determines if x is ±∞.
|
isNaN
|
Determines if x is NaN .
|
isNormal
|
Determines if x is normalized.
|
isSubnormal
|
Determines if x is subnormal.
|
ldexp
|
Compute n * 2exp
|
log
|
Calculate the natural logarithm of x .
|
log10
|
Calculate the base-10 logarithm of x .
|
log1p
|
Calculates the natural logarithm of 1 + x .
|
log2
|
Calculates the base-2 logarithm of x :
⊂x
|
logb
|
Extracts the exponent of x as a signed integral value.
|
lrint
|
Rounds x to the nearest integer value, using the current rounding
mode.
|
lround
|
Return the value of x rounded to the nearest integer.
|
modf
|
Breaks x into an integral part and a fractional part, each of which has
the same sign as x . The integral part is stored in i .
|
NaN
|
Create a quiet , storing an integer inside the payload .
|
nearbyint
|
Rounds x to the nearest integer value, using the current rounding
mode.
|
nextafter
|
Calculates the next representable value after x in the direction of y .
|
nextDown
|
Calculate the next smallest floating point value before x .
|
nextUp
|
Calculate the next largest floating point value after x .
|
poly
|
Evaluate polynomial A (x ) = ⊂ + ⊂x + ⊂x ,2
+ ⊂x ,3; ...
|
pow
|
Compute the value of x n , where n is an integer
|
pow
|
Compute the value of an integer x , raised to the power of a positive
integer n .
|
pow
|
Computes integer to floating point powers. |
pow
|
Calculates x y .
|
remainder
|
Calculate the remainder x REM y , following IEC 60559.
|
resetIeeeFlags
|
Set all of the floating-point status flags to false. |
rint
|
Rounds x to the nearest integer value, using the current rounding
mode.
If the return value is not equal to x , the FE_INEXACT
exception is raised.
nearbyint performs
the same operation, but does not set the FE_INEXACT exception.
|
rndtol
|
Returns x rounded to a long value using the current rounding mode.
If the integer value of x is
greater than long.max, the result is
indeterminate.
|
rndtonl
|
Returns x rounded to a long value using the FE_TONEAREST rounding mode.
If the integer value of x is
greater than long.max, the result is
indeterminate.
|
round
|
Return the value of x rounded to the nearest integer.
If the fractional part of x is exactly 0.5, the return value is rounded to
the even integer.
|
scalbn
|
Efficiently calculates x * 2n .
|
sgn
|
Returns -1 if , if , 1 if
, and if x ==.
|
signbit
|
Return 1 if sign bit of e is set, 0 if not. |
sin
|
Returns sine for complex and imaginary arguments. |
sin
|
Returns sine of x . x is in radians.
|
sin
|
Returns sine for complex and imaginary arguments. |
sinh
|
Calculates the hyperbolic sine of x .
|
sqrt
|
Compute square root of x .
|
tan
|
Returns tangent of x . x is in radians.
|
tanh
|
Calculates the hyperbolic tangent of x .
|
trunc
|
Returns the integer portion of x , dropping the fractional portion.
|
Structs
Name | Description |
---|---|
FloatingPointControl
|
Control the Floating point hardware |
IeeeFlags
|
IEEE exception status flags ('sticky bits') |
Enum values
Name | Type | Description |
---|---|---|
E
|
e = 2.718281... | |
LN10
|
ln 10 = 2.302585... | |
LN2
|
ln 2 = 0.693147... | |
LOG10E
|
⊂e = 0.434294... | |
LOG2
|
⊂2 = 0.301029... | |
LOG2E
|
⊂e = 1.442695... | |
LOG2T
|
⊂10 = 3.321928... | |
M_1_PI
|
1 / π = 0.318309... | |
M_2_PI
|
2 / π = 0.636619... | |
M_2_SQRTPI
|
2 / π = 1.128379... | |
PI
|
= 3.141592... | |
PI_2
|
π / 2 = 1.570796... | |
PI_4
|
π / 4 = 0.785398... | |
SQRT1_2
|
= 0.707106... | |
SQRT2
|
2 = 1.414213... |
Authors
Walter Bright, Don Clugston, Conversion of CEPHES math library to D by Iain Buclaw