Import std.math.numbers
std.math.numbers
The Interfaces the number types share, for generic math: Bounded, Integer, and FloatingPoint.
What the built-in number types share, for std.math's generic Functions: Bounded, the types with
a lowest and a highest value, which every number type is; Integer, the eight integer types; and
FloatingPoint, Float32 and Float64, over C's libm. A Function that takes a T of one of them gets
its type from its arguments, so Lerp(0, 10, t) works in t's type, and its literals follow. Their
Static Methods are for generic code, through a type parameter, as in T.MinValue(); for the types
themselves, std.math's Functions are the way, as MinValue<Int>() and Floor(x).
Examples
Function Ones<T: Integer>(value: T): Int => PopCount(value)
Function Whole<T: FloatingPoint>(value: T): T => Floor(value)
Expect(Ones(0b111 As UInt8) == 3)
Expect(Whole(2.5) == 2.0)
Expect(MinValue<Int8>() == -128 && MaxValue<Int8>() == 127)std/math/numbers.fb
Types
Bounded
interface
Public Interface Bounded
The types with a lowest and a highest value: every number type. A float's are its lowest and highest finite values, not the infinities. Each is a Double too, for math like a Mean.
Examples
Function Highest<T: Bounded>(): T => MaxValue<T>()
Expect(Highest<UInt16>() == 65535)
Expect(Highest<Int8>() == 127)-
The type's lowest value: a float's lowest finite one.
-
The type's highest value: a float's highest finite one.
-
The
valueas a Double, rounded to the nearest one where a Long's is too large to hold.
Integer
interface
Public Interface Integer Extends Bounded
The eight integer types, whose bits generic code works on through a UInt64.
-
How many bits the type has: 8, 16, 32, or 64.
-
The
value's bits, BitWidth of them, in a UInt64's low bits, the rest 0. -
The value whose bits are the low BitWidth of
bits.
FloatingPoint
interface
Public Interface FloatingPoint Extends Bounded
Float32 and Float64, with what C's libm works out for each. Rounding is half away from 0, and Rem is C's fmod, which is exact.
-
The gap between 1 and the next value above it.
-
The Double as this type, rounded to the nearest
valueit holds. -
The largest whole number no larger than
value. -
The smallest whole number no smaller than
value. -
The whole number nearest
value, a half away from 0. -
valuewithout what's after its point: the whole number toward 0. -
The square root of
value, or NaN for a negative one. -
The cube root of
value. -
e to the power of
value. -
2 to the power of
value. -
The natural logarithm of
value. -
The base 2 logarithm of
value. -
The base 10 logarithm of
value. -
The sine of
value, in radians. -
The cosine of
value, in radians. -
The tangent of
value, in radians. -
The angle, in radians, whose sine is
value. -
The angle, in radians, whose cosine is
value. -
The angle, in radians, whose tangent is
value. -
The angle, in radians, of the point (
x,y) from the positive x axis, from -pi to pi. -
The hyperbolic sine of
value. -
The hyperbolic cosine of
value. -
The hyperbolic tangent of
value. -
The inverse hyperbolic sine of
value. -
The inverse hyperbolic cosine of
value. -
The inverse hyperbolic tangent of
value. -
What's left of
adivided byb, witha's sign, as C's fmod gives it. -
magnitude's size withsign's sign. -
atimesb, plusc, rounded once.
Functions
MinValue
function
Public Function MinValue<T: Bounded>(): T
The lowest value a T holds: for a float, its lowest finite one.
MaxValue
function
Public Function MaxValue<T: Bounded>(): T
The highest value a T holds: for a float, its highest finite one.
Examples
Expect(MaxValue<UInt8>() == 255)
Expect(MinValue<Int16>() == -32768)Extends
Int8
extend
Extend Int8 Implements Integer
Makes Int8 one of the Integer types, for std.math's generic Functions.
Int16
extend
Extend Int16 Implements Integer
Makes Int16 one of the Integer types, for std.math's generic Functions.
Int32
extend
Extend Int32 Implements Integer
Makes Int32 one of the Integer types, for std.math's generic Functions.
Int64
extend
Extend Int64 Implements Integer
Makes Int64 one of the Integer types, for std.math's generic Functions.
UInt8
extend
Extend UInt8 Implements Integer
Makes UInt8 one of the Integer types, for std.math's generic Functions.
UInt16
extend
Extend UInt16 Implements Integer
Makes UInt16 one of the Integer types, for std.math's generic Functions.
UInt32
extend
Extend UInt32 Implements Integer
Makes UInt32 one of the Integer types, for std.math's generic Functions.
UInt64
extend
Extend UInt64 Implements Integer
Makes UInt64 one of the Integer types, for std.math's generic Functions.
Float32
extend
Extend Float32 Implements FloatingPoint
Makes Float32 one of the FloatingPoint types, over C's libm's float Functions.
Float64
extend
Extend Float64 Implements FloatingPoint
Makes Float64 one of the FloatingPoint types, over C's libm's double Functions.
Float32
extend
Extend Float32
A Float32's IEEE 754 bits, and the Float32 of some.
-
The Float's bits, as IEEE 754 lays them out.
-
The Float whose IEEE 754
bitsthese are.
Float64
extend
Extend Float64
A Float64's IEEE 754 bits, and the Float64 of some.
-
The Double's bits, as IEEE 754 lays them out.
-
The Double whose IEEE 754
bitsthese are.
Report an issue with this page or with FutureBlitz on GitHub.