Extend a float32std/core/types/float32: V
to a float64std/core/types/float64: V
.
Convert an 64-bit integer to a float64std/core/types/float64: V
.
The maximum of a list of absolute values.
The square root of the sum of squares of a list of floats. Prevents overflow for large numbers and uses Kahan-Babuškan-Neumaier summation for precision.
The square root of the sum of the squares of three floats. Prevents overflow for large numbers.
Are two floating point number not equal?
Modulus of two floating point numbers.
Multiply two floating point numbers.
Add two floating point numbers.
Subtract two floating point numbers.
Divide two floating point numbers.
Is the first floating point number smaller than the second?
Is the first floating point number smaller or equal to the second?
Are two floating point number equal?
Is the first floating point number greater than the second?
Is the first floating point number greater or equal to the second?
Returns the value f
raised to the power p
.
Negate a float64std/core/types/float64: V
.
Return if two floats are nearly equal with respect to an epsilon
of 8*flt-epsilonstd/num/float64/flt-epsilon: float64
.
See also nearly-eqstd/num/float64/nearly-eq: (x : float64, y : float64, epsilon : ? float64) -> bool
which takes an explicit epsilon
.
Return the absolute value of a float64std/core/types/float64: V
f
.
The maximum of the absolute values.
Return the arc-cosine of d
.
The area hyperbolic cosine of d
.
Return the arc-sine of d
.
The area hyperbolic sine of d
.
Return the arc-tangent of d
.
Return the arc-tangent of a point (x
,y
).
The area hyperbolic tangent of d
.
Return the cubic root of a value d
Returns nanstd/num/float64/nan: float64
if d == nanstd/num/float64/nan: float64
or if d
is negative.
Returns inf
if d == inf
.
Return the smallest integer equal or larger than d
.
Compare floats using a total ordering on the float64std/core/types/float64: V
.
The ordering follows the totalOrder
predicate as defined in IEEE 754-2008 exactly.
The values are ordered in following order:
negative quiet nan,
negative signaling nan,
neginfstd/num/float64/neginf: float64
,
-finite,
-0.0,
+0.0,
finite,
posinfstd/num/float64/posinf: float64
,
signaling nan,
and quiet nan.
Return the cosine of an angle in radians d
.
The hyperbolic cosine of d
.
Decode a float64 d
into a tuple (m,e)
of a mantissa m
and exponent e
such that m
·2e
= d
exactly. The mantissa m
is
always either 0 or in the range [252, 253). See also frexpstd/num/float64/frexp: (x : float64) -> (float64, int)
.
Convert radians to degrees.
Create a float64 d
given a mantissa man
and exponent expstd/num/float64/exp: (p : float64) -> float64
such that man
·2expstd/num/float64/exp: (p : float64) -> float64
= d
exactly (if it is representable
by a float64std/core/types/float64: V
). See also ldexpstd/num/float64/ldexp: (x : float64, e : int) -> float64
.
Return e to the power of p
.
Return the 10 to the power of p
.
Return the 2 to the power of p
.
Calculate 2·e
for an integer e
.
Uses efficient bit conversion for exponents between -1022 and 1023 and
otherwise falls back to the regular exp2
function converting e
to a float64.
Return expstd/num/float64/exp: (p : float64) -> float64(x - 1.0)
.
Avoids rounding errors for values of x
very close to 1.0
.
Short version of float32
for convenience, e.g. 1.337.f32std/num/float64/f32: (f : float64) -> float32
. For example:
> 1.337.show-hex ++ " != " ++ 1.337.f32.float64.show-hex "0x1.5645A1CAC0831p+0 != 0x1.5645A2p+0" > 1.337.show-hex ++ " != " ++ 1.337.f32std/num/float64/f32: (f : float64) -> float32.float64.show-hex "0x1.5645A1CAC0831p+0 != 0x1.5645A2p+0"
.
Return the ‘floored’ fraction of d
, always greater or equal to zero.
d.floorstd/num/float64/floor: (d : float64) -> float64 + d.ffractionstd/num/float64/ffraction: (d : float64) -> float64 (===)std/core/sslice/(===): (slice1 : sslice, slice2 : sslice) -> bool d
(-2.4).ffractionstd/num/float64/ffraction: (d : float64) -> float64 (===)std/core/sslice/(===): (slice1 : sslice, slice2 : sslice) -> bool 0.6
.
Convert an integer to a float32std/core/types/float32: V
. May return nanstd/num/float64/nan: float64
if the integer is too large to represent as a float32std/core/types/float32: V
.
Convert an integer to a float64std/core/types/float64: V
. May return nanstd/num/float64/nan: float64
if the integer is too large to represent as a float64std/core/types/float64: V
.
Low-level: create a float64std/core/types/float64: V
from the given 64-bit integer.
Low-level: return the bits of a 64-bit float64std/core/types/float64: V
as in int64std/core/types/int64: V
.
Return the largest integer equal or less than d
.
The e) constant.
Machine epsilon: the difference between 1.0 and the next representable float64std/core/types/float64: V
value.
The natural logarithm of 10.
The natural logarithm of 2.
The base-10 logarithm of e.
The base-2 logarithm of e.
Maximum float64 value.
Maximal precision in decimal digits of a float64std/core/types/float64: V
.
Smallest positive normalized float64 value.
π/2.
3π/4.
π/4.
The square-root of 2.
Smallest positive subnormal value (i.e. DBL_TRUE_MIN
).
Fused multiply-add. Computes (x*y)+z
as if to infinite precision
with only the final result rounded back to a float64std/core/types/float64: V
.
Return the fractional part of a float64std/core/types/float64: V
d
.
d.truncate + d.fractionstd/num/float64/fraction: (d : float64) -> float64 (===)std/core/sslice/(===): (slice1 : sslice, slice2 : sslice) -> bool d
(-2.4).fractionstd/num/float64/fraction: (d : float64) -> float64 (===)std/core/sslice/(===): (slice1 : sslice, slice2 : sslice) -> bool -0.4
.
‘Fraction/exponent’: return the normalized fraction f
and exponent expstd/num/float64/exp: (p : float64) -> float64
for a number x
such that x == f
·2expstd/num/float64/exp: (p : float64) -> float64
.
The absolute value of the fraction f
is always in the range [0.5, 1.0), or
one of 0.0
, -0.0
, neginfstd/num/float64/neginf: float64
, posinfstd/num/float64/posinf: float64
, or nanstd/num/float64/nan: float64
.
See also decodestd/num/float64/decode: (d : float64) -> (int, int)
which decodes to an integer mantissa.
The hypotenuse of x
and y
: sqrtstd/num/float64/sqrt: (d : float64) -> float64(x*x + y*y)
.
Prevents overflow for large numbers.
Convert a float64std/core/types/float64: V
to an intstd/core/types/int: V
using roundstd/num/float64/round: (d : float64) -> float64
to round to its nearest integer.
(rounding to an even number on a tie)
Returns 0
if the argument is not finite?
.
Is this a finite number (i.e. not nanstd/num/float64/nan: float64
or infinity).
Is this value equal to negative or positive infinity ?
Is this value equal to NaN ?
Is the value negative?
Is this value equal to negative infinity ?
Is this a negative zero value?
Is the value positive?
Is this value equal to positive infinity ?
Is this a subnormal value?
(i.e. 0 < d.abs < flt-minstd/num/float64/flt-min: float64
).
Is the value zero?
‘Load exponent’: returns x
·2e
for a is-finitestd/num/float64/is-finite: (d : float64) -> bool
x
and
otherwise x
itself. See also encodestd/num/float64/encode: (man : int, exp : int) -> float64
which loads an integer mantissa.
Linear interpolation, calculating x + t*(y - x)
but avoids troublesome edge cases.
Follows the C++20 specification.
In particular, if x.is-finitestd/num/float64/is-finite: (d : float64) -> bool (&&)std/core/types/(&&): (x : bool, y : bool) -> bool y.is-finitestd/num/float64/is-finite: (d : float64) -> bool
, then:
- exact: lerpstd/num/float64/lerp: (x : float64, y : float64, t : float64) -> float64(x,y,0.0) == x
and lerpstd/num/float64/lerp: (x : float64, y : float64, t : float64) -> float64(x,y,1.0) == y
- monotonic: if x <= y
and t1 <= t2
, then cmp( lerpstd/num/float64/lerp: (x : float64, y : float64, t : float64) -> float64(x,y,t1), lerpstd/num/float64/lerp: (x : float64, y : float64, t : float64) -> float64(x,y,t2) ) <= Eqstd/core/types/Eq: order
(and other cases)
- deterministic: only lerpstd/num/float64/lerp: (x : float64, y : float64, t : float64) -> float64(x,x,flt-inf)
results in nanstd/num/float64/nan: float64
- bounded: t<0.0 || t>1.0 || is-finitestd/num/float64/is-finite: (d : float64) -> bool(lerpstd/num/float64/lerp: (x : float64, y : float64, t : float64) -> float64(x,y,t))
- consistent: lerpstd/num/float64/lerp: (x : float64, y : float64, t : float64) -> float64(x,x,t) == x
.
Return the natural logarithm (in base e) of a float64std/core/types/float64: V
f
.
Return lnstd/num/float64/ln: (f : float64) -> float64(1.0 + x)
.
Avoids potential imprecision for small x
where adding 1.0
explicitly
may lead to rounding errors.
Returns lnstd/num/float64/ln: (f : float64) -> float64(expstd/num/float64/exp: (p : float64) -> float64(x) + expstd/num/float64/exp: (p : float64) -> float64(y))
.
Avoids overlow/underflow errors.
Return the logarithm in base base
of a float64std/core/types/float64: V
f
.
Return the logarithm in base 10 of a float64std/core/types/float64: V
f
.
Return the logarithm in base 2 of a float64std/core/types/float64: V
f
.
Returns log2std/num/float64/log2: (f : float64) -> float64( exp2(x) + exp2(y) )
.
Avoids overlow/underflow errors.
Returns the largest of two floats.
Returns the largest element of a list of floats (or 0
for the empty list).
The midpoint is the average of x
and y
.
Avoids overflow on large numbers.
Returns the smallest of two floats.
Returns the smallest element of a list of floats (or 0
for the empty list).
Represents a value that is not a number (NaN).
Return if two floats are nearly equal with respect to some epsilon
(=8*flt-epsilonstd/num/float64/flt-epsilon: float64
).
The epsilon is the nearest difference for numbers around 1.0. The routine automatically
scales the epsilon for larger and smaller numbers, and for subnormal numbers.
Negative infinity.
Returns the greatest float64std/core/types/float64: V
less than x
.
This behaves exactly as nextDown
in the IEEE 754-2008 standard.
The identity x.next-downstd/num/float64/next-down: (x : float64) -> float64 == next-downstd/num/float64/next-down: (x : float64) -> float64(x)
holds for all x
.
When x
is finite x == x.next-downstd/num/float64/next-down: (x : float64) -> float64.next-upstd/num/float64/next-up: (x : float64) -> float64
also holds.
Returns the least float64std/core/types/float64: V
greater than x
.
This behaves exactly as nextUp
in the IEEE 754-2008 standard.
The identity x.next-upstd/num/float64/next-up: (x : float64) -> float64 == next-downstd/num/float64/next-down: (x : float64) -> float64(x)
holds for all x
.
When x
is finite x == x.next-upstd/num/float64/next-up: (x : float64) -> float64.next-downstd/num/float64/next-down: (x : float64) -> float64
also holds.
Parse a float64 number. Can be “NaN”, “Inf(inity)” (case-insensitive),
a fix-point number (1.2
) or in scientific notation (-2.3e-5
).
Also allows floats in hexadecimal notation (0xA.Fp-10
) that can
be represented precisely (and are the preferred round trip format).
π.
Positive infinity.
Return the d
raised to the power of p
.
Convert degrees to radians.
Round a float64 to its nearest integral value. If the value is halfway between two integers, the value is rounded towards the even one.
Round a float64 to a specified precision. Rounds to the even number in case of a tie.
123.456.round-to-precstd/num/float64/round-to-prec: (d : float64, prec : int) -> float64(2) == 123.46
123.456.round-to-precstd/num/float64/round-to-prec: (d : float64, prec : int) -> float64(-1) == 120.0
.
Show a float64std/core/types/float64: V
as a string.
If d >= 1.0e-5
and d < 1.0e+21
, show-fixedstd/num/float64/show-fixed: (d : float64, precision : ? int) -> string
is used and otherwise show-expstd/num/float64/show-exp: (d : float64, precision : ? int) -> string
.
Default precision
is -17
.
Show a float64std/core/types/float64: V
in exponential (scientific) notation.
The optional precision
(= -17
) specifies the precision.
If >=0
it specifies the number of digits behind the dot (up to 17
max).
If negative, then at most the absolute value of precision
digits behind the dot are used.
Show a float64std/core/types/float64: V
fixed-point notation.
The optional precision
(= -2
) specifies the maximum precision.
If >=0
it specifies the number of digits behind the dot (up to 20
max).
If negative, then at most the absolute value of precision
digits behind the dot are used.
This may still show a number in exponential notation if the it is too small or large,
in particular, for a d
where d > 1.0e21
or d < 1.0e-15
, or if
precision.abs > 17
, the show-expstd/num/float64/show-exp: (d : float64, precision : ? int) -> string
routine is used.
Show a float64 in hexadecimal notation.
An advantage of this format is that it precisely represents the float64std/core/types/float64: V
and can
reliably (and efficiently) be parsed back, i.e. d.show-hex.parse-float64std/num/float64/parse-float64: (s : string) -> maybe<float64> == Juststd/core/types/Just: forall<a> (value : a) -> maybe<a>(d)
.
The significant is the hexadecimal fraction while the
exponent after the p
is the decimal power of 2.
For example, 0xA.Fp-10
= (10 + 15/16)·2-10 (not 2-16!) = 0.01068115234375.
Equivalently, 0xA.Fp-10 == 0x5.78p-9 == 0x2.BCp-8 == 0x1.5Ep-7
.
> flt-min.show-hex "0x1.0p-1022" > 0.1.show-hex "0x1.999999999999Ap-4" > flt-max.show-hex "0x1.FFFFFFFFFFFFFp+1023" > -0.0.show-hex "-0x0.0p+0" > nan.show-hex "NaN" > 0.01068115234375.show-hex "0x1.5Ep-7" > flt-minstd/num/float64/flt-min: float64.show-hex "0x1.0p-1022" > 0.1.show-hex "0x1.999999999999Ap-4" > flt-maxstd/num/float64/flt-max: float64.show-hex "0x1.FFFFFFFFFFFFFp+1023" > -0.0.show-hex "-0x0.0p+0" > nanstd/num/float64/nan: float64.show-hex "NaN" > 0.01068115234375.show-hex "0x1.5Ep-7"
.
Compare the argument to zero.
Return the sine of an angle in radians d
.
The hyperbolic sine of d
.
The square of a float64.
Return the square root of a value d
Returns nanstd/num/float64/nan: float64
if d == nanstd/num/float64/nan: float64
or if d
is negative.
Returns inf
if d == inf
.
Return the sum of a list of floats.
Uses Kahan-Babuškan-Neumaier summation
to minimize rounding errors. This
is more precise as Kahan summation and about as fast.
[1.0e3,1.0e97,1.0e3,-1.0e97].sum == 2000.0
while
[1.0e3,1.0e97,1.0e3,-1.0e97].foldlstd/core/list/foldl: forall<a,b,e> (xs : list<a>, z : b, f : (b, a) -> e b) -> e b(0.0,(+)) == 0.0
(!)
A. Neumaier, Rundungsfehleranalyse einiger Verfahren zur Summation endlicher Summen.
Math. Mechanik, 54:39–51, 1974.
Return the tangent of an angle in radians d
.
The hyperbolic tangent of d
.
Return the integral part of a float64std/core/types/float64: V
d
.
If d >= 0.0
, return the largest integer equal or less to d
,
If d < 0.0
, return the smallest integer equal or larger to d
.
Return x
with the sign of y
.
64-bit IEEE floating point numbers.
Also described as double precision or binary64 numbers in the standards. See also https://en.wikipedia.org/wiki/Double-precision_floating-point_format.