Skip to content
FutureBlitz

    Install

    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.

    std/math/scalar.fb, line 12

    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.

    std/math/scalar.fb, line 19

    Floor function

    Public Function Floor<T: FloatingPoint>(value: T): T

    The largest whole number that isn't above the value.

    std/math/scalar.fb, line 27

    Ceil function

    Public Function Ceil<T: FloatingPoint>(value: T): T

    The smallest whole number that isn't below the value.

    std/math/scalar.fb, line 30

    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.

    std/math/scalar.fb, line 34

    Trunc function

    Public Function Trunc<T: FloatingPoint>(value: T): T

    The whole part, toward 0: Trunc(-2.7) is -2.

    std/math/scalar.fb, line 37

    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.

    std/math/scalar.fb, line 41

    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.

    std/math/scalar.fb, line 56

    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.

    std/math/scalar.fb, line 66

    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.

    std/math/scalar.fb, line 77

    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.

    std/math/scalar.fb, line 85

    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.

    std/math/scalar.fb, line 89

    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.

    std/math/scalar.fb, line 104

    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.

    std/math/scalar.fb, line 113

    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.

    std/math/scalar.fb, line 138

    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.

    std/math/scalar.fb, line 145

    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.

    std/math/scalar.fb, line 153

    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.

    std/math/scalar.fb, line 160

    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.

    std/math/scalar.fb, line 177

    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.

    std/math/scalar.fb, line 193

    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.

    std/math/scalar.fb, line 204

    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.

    std/math/scalar.fb, line 224

    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.

    std/math/scalar.fb, line 236

    IsClose function

    Public Function IsClose<T>(a: T, b: T, tolerance: T): Bool

    Whether a and b are no further apart than tolerance.

    std/math/scalar.fb, line 243

    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.

    std/math/scalar.fb, line 250

    Sqrt function

    Public Function Sqrt<T: FloatingPoint>(value: T): T

    The square root. A negative value's is NaN.

    std/math/scalar.fb, line 259

    Cbrt function

    Public Function Cbrt<T: FloatingPoint>(value: T): T

    The cube root, negative for a negative value.

    std/math/scalar.fb, line 262

    Exp function

    Public Function Exp<T: FloatingPoint>(value: T): T

    E to the power of the value.

    std/math/scalar.fb, line 265

    Exp2 function

    Public Function Exp2<T: FloatingPoint>(value: T): T

    2 to the power of the value.

    std/math/scalar.fb, line 268

    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.

    std/math/scalar.fb, line 271

    Log function

    Public Function Log<T>(value: T, base: T): T

    The logarithm of the base: Log(8.0, 2.0) is 3.

    std/math/scalar.fb, line 274

    Log2 function

    Public Function Log2<T: FloatingPoint>(value: T): T

    The logarithm of base 2.

    std/math/scalar.fb, line 280

    Log10 function

    Public Function Log10<T: FloatingPoint>(value: T): T

    The logarithm of base 10.

    std/math/scalar.fb, line 283

    Sin function

    Public Function Sin<T: FloatingPoint>(angle: T): T

    The sine of an angle in radians.

    std/math/scalar.fb, line 286

    Cos function

    Public Function Cos<T: FloatingPoint>(angle: T): T

    The cosine of an angle in radians.

    std/math/scalar.fb, line 289

    Tan function

    Public Function Tan<T: FloatingPoint>(angle: T): T

    The tangent of an angle in radians.

    std/math/scalar.fb, line 292

    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.

    std/math/scalar.fb, line 295

    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.

    std/math/scalar.fb, line 298

    Atan function

    Public Function Atan<T: FloatingPoint>(value: T): T

    The angle whose tangent is the value, from -Pi / 2 to Pi / 2.

    std/math/scalar.fb, line 301

    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.

    std/math/scalar.fb, line 304

    Sinh function

    Public Function Sinh<T: FloatingPoint>(value: T): T

    The hyperbolic sine.

    std/math/scalar.fb, line 307

    Cosh function

    Public Function Cosh<T: FloatingPoint>(value: T): T

    The hyperbolic cosine.

    std/math/scalar.fb, line 310

    Tanh function

    Public Function Tanh<T: FloatingPoint>(value: T): T

    The hyperbolic tangent.

    std/math/scalar.fb, line 313

    Asinh function

    Public Function Asinh<T: FloatingPoint>(value: T): T

    The value whose hyperbolic sine this is.

    std/math/scalar.fb, line 316

    Acosh function

    Public Function Acosh<T: FloatingPoint>(value: T): T

    The value, not negative, whose hyperbolic cosine this is. Below 1, it's NaN.

    std/math/scalar.fb, line 319

    Atanh function

    Public Function Atanh<T: FloatingPoint>(value: T): T

    The value whose hyperbolic tangent this is. Outside -1 to 1, it's NaN.

    std/math/scalar.fb, line 322

    IsNaN function

    Public Function IsNaN<T>(value: T): Bool

    Whether the value is NaN, the one value that isn't equal to itself.

    std/math/scalar.fb, line 325

    IsFinite function

    Public Function IsFinite<T>(value: T): Bool

    Whether the value is a number, neither infinite nor NaN.

    std/math/scalar.fb, line 331

    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.

    std/math/scalar.fb, line 337

    Fma function

    Public Function Fma<T: FloatingPoint>(a: T, b: T, c: T): T

    a * b + c, rounded once, at the end.

    std/math/scalar.fb, line 342

    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.

    std/math/scalar.fb, line 346

    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.

    std/math/scalar.fb, line 350

    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.

    std/math/scalar.fb, line 356

    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.

    std/math/scalar.fb, line 360

    ToRadians function

    Public Function ToRadians(degrees: Int): Float

    The angle of so many degrees, in radians, as Deg gives it.

    std/math/scalar.fb, line 363

    ToRadians function

    Public Function ToRadians<T: FloatingPoint>(degrees: T): T

    The angle of so many degrees, in radians, as Deg gives it.

    std/math/scalar.fb, line 366

    ToDegrees function

    Public Function ToDegrees(radians: Int): Float

    The angle of so many radians, in degrees: ToDegrees(1) is about 57.3.

    std/math/scalar.fb, line 369

    ToDegrees function

    Public Function ToDegrees<T: FloatingPoint>(radians: T): T

    The angle in radians, in degrees: ToDegrees(Pi) is 180.

    std/math/scalar.fb, line 372

    Report an issue with this page or with FutureBlitz on GitHub.