Import std.math.scalar
std.math.scalar
The scalar Functions: signs, whole parts, remainders, divisors, the steps between two values, powers and logs, trig and its hyperbolic twins, and IEEE's checks, each in its arguments' type, for the number types it makes sense for. Powers are the ** operator. Angles are radians, so Deg(90) is 90 degrees, in radians.
std/math/scalar.fb
Functions
Abs
function
@PanicsAtCaller Public Function Abs<T>(value: T): T
The value without its sign: 0 for -0, and NaN for NaN. An integer's lowest value, which has
none in its type, overflows.
Sign
function
Public Function Sign<T>(value: T): T
1 for a value above 0, -1 for one below, and the value itself for 0 or NaN.
Floor
function
Public Function Floor<T: FloatingPoint>(value: T): T
The largest whole number that isn't above the value.
Ceil
function
Public Function Ceil<T: FloatingPoint>(value: T): T
The smallest whole number that isn't below the value.
Round
function
Public Function Round<T: FloatingPoint>(value: T): T
The nearest whole number, with a value halfway between two going away from 0: 2.5 is 3, and -2.5 is -3.
Trunc
function
Public Function Trunc<T: FloatingPoint>(value: T): T
The whole part, toward 0: Trunc(-2.7) is -2.
Fract
function
Public Function Fract<T>(value: T): T
What Floor takes away, from 0 to 1: Fract(-0.25) is 0.75. A negative value too close to a
whole number for the type to hold the difference gives 1.
Mod
function
@PanicsAtCaller Public Function Mod<T>(a: T, b: T): T
The remainder of a divided by b with the sign of b, as dividing and rounding down leaves
it: Mod(-1, 3) is 2, and Mod(1, -3) is -2. A b of 0 panics.
Mod
function
Public Function Mod<T>(a: T, b: T): T
The remainder of a divided by b with the sign of b, as dividing and rounding down leaves
it: Mod(-1.5, 4.0) is 2.5, and a 0 has b's sign. A b of 0 gives NaN. A remainder too small
beside b for their sum to be below it gives 0, which is as near, a whole b away.
Rem
function
@PanicsAtCaller Public Function Rem<T>(a: T, b: T): T
The remainder of a divided by b with the sign of a, as % gives it: Rem(-1, 3) is -1. A b
of 0 panics.
Rem
function
Public Function Rem<T: FloatingPoint>(a: T, b: T): T
The remainder of a divided by b with the sign of a, exactly, as C's fmod gives it:
Rem(-1.5, 4.0) is -1.5. A b of 0 gives NaN.
Gcd
function
@PanicsAtCaller Public Function Gcd<T>(a: T, b: T): T
The greatest common divisor of the two, which isn't negative: Gcd(12, -18) is 6, and Gcd(0, 0) is 0. One too large for T overflows.
Lcm
function
@PanicsAtCaller Public Function Lcm<T>(a: T, b: T): T
The least common multiple of the two, which isn't negative: Lcm(4, 6) is 12, and 0 when either is 0. One too large for T overflows.
IntSqrt
function
@PanicsAtCaller Public Function IntSqrt<T>(value: T): T
The largest integer whose square isn't above the value: IntSqrt(10) is 3. A negative value
panics.
Lerp
function
Public Function Lerp<T>(a: T, b: T, t: T): T
The value t of the way from a to b: a at 0, b itself at 1, though b - a rounds,
and past them outside 0 to 1.
InverseLerp
function
Public Function InverseLerp<T>(a: T, b: T, value: T): T
How far of the way from a to b the value is, as Lerp's t: 0 at a, 1 at b. With a
equal to b, it's 0.
Remap
function
Public Function Remap<T>(value: T, fromLow: T, fromHigh: T, toLow: T, toHigh: T): T
The value moved from one range to another, as far through toLow to toHigh as it is through
fromLow to fromHigh: Remap(5, 0, 10, 100, 200) is 150.
SmoothStep
function
Public Function SmoothStep<T>(low: T, high: T, value: T): T
0 below low and 1 above high, and a smooth curve between, as GLSL's smoothstep: with low
equal to high, 0 below it and 1 from it up.
Wrap
function
Public Function Wrap<T>(value: T, low: T, high: T): T
The value wrapped into the range from low to high, high left out, as an angle wraps into
a turn: Wrap(370, 0, 360) is 10. With low equal to high, it's low. The distances are
worked out in a UInt64, so a range of any width, in any of the eight types, can't overflow.
Wrap
function
Public Function Wrap<T>(value: T, low: T, high: T): T
The value wrapped into the range from low to high, high left out, as an angle wraps into
a turn: Wrap(370.0, 0.0, 360.0) is 10. With low equal to high, it's low. One that rounds
to high gives low, which is as near, a turn away.
PingPong
function
@PanicsAtCaller Public Function PingPong<T>(value: T, length: T): T
The value going from 0 up to length and back down, over and over: PingPong(3, 2) is 1. A
negative length panics. It's worked out in a UInt64, by whole lengths, so no length of any of
the eight types overflows.
PingPong
function
@PanicsAtCaller Public Function PingPong<T>(value: T, length: T): T
The value going from 0 up to length and back down, over and over: PingPong(3.0, 2.0) is 1. A
negative or NaN length panics.
MoveTowards
function
Public Function MoveTowards<T>(current: T, target: T, maxDelta: T): T
Current moved toward target by maxDelta, or to target when it's no further: a negative
maxDelta moves it away.
IsClose
function
Public Function IsClose<T>(a: T, b: T, tolerance: T): Bool
Whether a and b are no further apart than tolerance.
IsClose
function
Public Function IsClose<T>(a: T, b: T): Bool
Whether a and b are equal but for rounding: no further apart than 0.00001 of the larger
one's size, or of 1 near 0. An infinity is close only to itself, and NaN to nothing.
Sqrt
function
Public Function Sqrt<T: FloatingPoint>(value: T): T
The square root. A negative value's is NaN.
Cbrt
function
Public Function Cbrt<T: FloatingPoint>(value: T): T
The cube root, negative for a negative value.
Exp
function
Public Function Exp<T: FloatingPoint>(value: T): T
E to the power of the value.
Exp2
function
Public Function Exp2<T: FloatingPoint>(value: T): T
2 to the power of the value.
Log
function
Public Function Log<T: FloatingPoint>(value: T): T
The natural logarithm, of base E. 0's is -Inf, and a negative value's NaN.
Log
function
Public Function Log<T>(value: T, base: T): T
The logarithm of the base: Log(8.0, 2.0) is 3.
Log2
function
Public Function Log2<T: FloatingPoint>(value: T): T
The logarithm of base 2.
Log10
function
Public Function Log10<T: FloatingPoint>(value: T): T
The logarithm of base 10.
Sin
function
Public Function Sin<T: FloatingPoint>(angle: T): T
The sine of an angle in radians.
Cos
function
Public Function Cos<T: FloatingPoint>(angle: T): T
The cosine of an angle in radians.
Tan
function
Public Function Tan<T: FloatingPoint>(angle: T): T
The tangent of an angle in radians.
Asin
function
Public Function Asin<T: FloatingPoint>(value: T): T
The angle whose sine is the value, from -Pi / 2 to Pi / 2. Outside -1 to 1, it's NaN.
Acos
function
Public Function Acos<T: FloatingPoint>(value: T): T
The angle whose cosine is the value, from 0 to Pi. Outside -1 to 1, it's NaN.
Atan
function
Public Function Atan<T: FloatingPoint>(value: T): T
The angle whose tangent is the value, from -Pi / 2 to Pi / 2.
Atan2
function
Public Function Atan2<T: FloatingPoint>(y: T, x: T): T
The angle from the X axis to the point (x, y), from -Pi to Pi.
Sinh
function
Public Function Sinh<T: FloatingPoint>(value: T): T
The hyperbolic sine.
Cosh
function
Public Function Cosh<T: FloatingPoint>(value: T): T
The hyperbolic cosine.
Tanh
function
Public Function Tanh<T: FloatingPoint>(value: T): T
The hyperbolic tangent.
Asinh
function
Public Function Asinh<T: FloatingPoint>(value: T): T
The value whose hyperbolic sine this is.
Acosh
function
Public Function Acosh<T: FloatingPoint>(value: T): T
The value, not negative, whose hyperbolic cosine this is. Below 1, it's NaN.
Atanh
function
Public Function Atanh<T: FloatingPoint>(value: T): T
The value whose hyperbolic tangent this is. Outside -1 to 1, it's NaN.
IsNaN
function
Public Function IsNaN<T>(value: T): Bool
Whether the value is NaN, the one value that isn't equal to itself.
IsFinite
function
Public Function IsFinite<T>(value: T): Bool
Whether the value is a number, neither infinite nor NaN.
CopySign
function
Public Function CopySign<T: FloatingPoint>(magnitude: T, sign: T): T
The magnitude with the sign of sign, -0 and NaN's included: CopySign(2.0, -0.0) is -2.
Fma
function
Public Function Fma<T: FloatingPoint>(a: T, b: T, c: T): T
a * b + c, rounded once, at the end.
Deg
function
Public Function Deg(degrees: Int): Float
The angle of so many degrees, in radians, the unit of every angle in std.math: Deg(90) is
Pi / 2.
Deg
function
Public Function Deg<T: FloatingPoint>(degrees: T): T
The angle of so many degrees, in radians, the unit of every angle in std.math: Deg(22.5) is
Pi / 8.
Rad
function
Public Function Rad(radians: Int): Float
The angle of so many radians, which is the number itself, for code that says its units, as
Deg does.
Rad
function
Public Function Rad<T: FloatingPoint>(radians: T): T
The angle of so many radians, which is the number itself, for code that says its units, as
Deg does.
ToRadians
function
Public Function ToRadians(degrees: Int): Float
The angle of so many degrees, in radians, as Deg gives it.
ToRadians
function
Public Function ToRadians<T: FloatingPoint>(degrees: T): T
The angle of so many degrees, in radians, as Deg gives it.
ToDegrees
function
Public Function ToDegrees(radians: Int): Float
The angle of so many radians, in degrees: ToDegrees(1) is about 57.3.
ToDegrees
function
Public Function ToDegrees<T: FloatingPoint>(radians: T): T
The angle in radians, in degrees: ToDegrees(Pi) is 180.
Report an issue with this page or with FutureBlitz on GitHub.