Float32

GitHub   Edit on GitHub

Utilities for working with the Float32 type.

Added in 0.2.0 No other changes yet.
1
from "float32" include Float32
1
4.0f
1
-4.0f
1
Infinityf
1
NaNf

Values

Functions and constants included in the Float32 module.

Float32.infinity

Added in 0.4.0 No other changes yet.
1
infinity: Float32

Infinity represented as a Float32 value. This is an alternative to the Infinityf literal.

Float32.nan

Added in 0.4.0 No other changes yet.
1
nan: Float32

NaN (Not a Number) represented as a Float32 value. This is an alternative to the NaNf literal.

Float32.pi

Added in 0.5.2 No other changes yet.
1
pi: Float32

Pi represented as a Float32 value.

Float32.tau

Added in 0.5.2 No other changes yet.
1
tau: Float32

Tau represented as a Float32 value.

Float32.e

Added in 0.5.2 No other changes yet.
1
e: Float32

Euler’s number represented as a Float32 value.

Float32.fromNumber

Added in 0.2.0 No other changes yet.
1
fromNumber: (number: Number) => Float32

Converts a Number to a Float32.

Parameters:

param type description
number Number The value to convert

Returns:

type description
Float32 The Number represented as a Float32

Float32.toNumber

Added in 0.2.0 No other changes yet.
1
toNumber: (float: Float32) => Number

Converts a Float32 to a Number.

Parameters:

param type description
float Float32 The value to convert

Returns:

type description
Number The Float32 represented as a Number

Float32.reinterpretInt32

Added in 0.7.0 No other changes yet.
1
reinterpretInt32: (value: Int32) => Float32

Interprets an Int32 as a Float32.

Parameters:

param type description
value Int32 The value to convert

Returns:

type description
Float32 The Int32 interpreted as an Float32

Examples:

1
assert Float32.reinterpretInt32(1065353216l) == 1.0f
1
assert Float32.reinterpretInt32(-1082130432l) == -1.0f

Float32.reinterpretUint32

Added in 0.7.0 No other changes yet.
1
reinterpretUint32: (value: Uint32) => Float32

Interprets an Uint32 as a Float32.

Parameters:

param type description
value Uint32 The value to convert

Returns:

type description
Float32 The Uint32 interpreted as an Float32

Examples:

1
assert Float32.reinterpretUint32(1065353216ul) == 1.0f
1
assert Float32.reinterpretUint32(3212836864ul) == -1.0f

Float32.(+)

Added in 0.6.0
versionchanges
0.2.0Originally named `add`
1
(+): (x: Float32, y: Float32) => Float32

Computes the sum of its operands.

Parameters:

param type description
x Float32 The first operand
y Float32 The second operand

Returns:

type description
Float32 The sum of the two operands

Examples:

1
2
use Float32.{ (+) }
assert 1.0f + 1.0f == 2.0f

Float32.(-)

Added in 0.6.0
versionchanges
0.2.0Originally named `sub`
1
(-): (x: Float32, y: Float32) => Float32

Computes the difference of its operands.

Parameters:

param type description
x Float32 The first operand
y Float32 The second operand

Returns:

type description
Float32 The difference of the two operands

Examples:

1
2
use Float32.{ (-) }
assert 1.0f - 1.0f == 0.0f

Float32.(*)

Added in 0.6.0
versionchanges
0.2.0Originally named `mul`
1
(*): (x: Float32, y: Float32) => Float32

Computes the product of its operands.

Parameters:

param type description
x Float32 The first operand
y Float32 The second operand

Returns:

type description
Float32 The product of the two operands

Examples:

1
2
use Float32.{ (*) }
assert 2.0f * 2.0f == 4.0f

Float32.(/)

Added in 0.6.0
versionchanges
0.2.0Originally named `div`
1
(/): (x: Float32, y: Float32) => Float32

Computes the quotient of its operands.

Parameters:

param type description
x Float32 The first operand
y Float32 The second operand

Returns:

type description
Float32 The quotient of the two operands

Examples:

1
2
use Float32.{ (/) }
assert 10.0f / 4.0f == 2.5f

Float32.(**)

Added in 0.7.0 No other changes yet.
1
(**): (base: Float32, power: Float32) => Float32

Computes the exponentiation of the given base and power.

Parameters:

param type description
base Float32 The base float
power Float32 The exponent float

Returns:

type description
Float32 The base raised to the given power

Examples:

1
2
use Float64.{ (**) }
assert 2.0f ** 2.0f == 4.0f

Float32.(<)

Added in 0.6.0
versionchanges
0.2.0Originally named `lt`
1
(<): (x: Float32, y: Float32) => Bool

Checks if the first value is less than the second value.

Parameters:

param type description
x Float32 The first value
y Float32 The second value

Returns:

type description
Bool true if the first value is less than the second value or false otherwise

Examples:

1
2
use Float32.{ (<) }
assert 1.0f < 2.0f

Float32.(>)

Added in 0.6.0
versionchanges
0.2.0Originally named `gt`
1
(>): (x: Float32, y: Float32) => Bool

Checks if the first value is greater than the second value.

Parameters:

param type description
x Float32 The first value
y Float32 The second value

Returns:

type description
Bool true if the first value is greater than the second value or false otherwise

Examples:

1
2
use Float32.{ (>) }
assert 2.0f > 1.0f

Float32.(<=)

Added in 0.6.0
versionchanges
0.2.0Originally named `lte`
1
(<=): (x: Float32, y: Float32) => Bool

Checks if the first value is less than or equal to the second value.

Parameters:

param type description
x Float32 The first value
y Float32 The second value

Returns:

type description
Bool true if the first value is less than or equal to the second value or false otherwise

Examples:

1
2
use Float32.{ (<=) }
assert -1.0f <= 1.0f
1
2
use Float32.{ (<=) }
assert -2.0f <= -2.0f

Float32.(>=)

Added in 0.6.0
versionchanges
0.2.0Originally named `gte`
1
(>=): (x: Float32, y: Float32) => Bool

Checks if the first value is greater than or equal to the second value.

Parameters:

param type description
x Float32 The first value
y Float32 The second value

Returns:

type description
Bool true if the first value is greater than or equal to the second value or false otherwise

Examples:

1
2
use Float32.{ (>=) }
assert 4.0f >= 1.0f
1
2
use Float32.{ (>=) }
assert 3.0f >= 3.0f

Float32.isFinite

Added in 0.7.0 No other changes yet.
1
isFinite: (x: Float32) => Bool

Checks if a float is finite. All values are finite exept for NaN, infinity or negative infinity.

Parameters:

param type description
x Float32 The number to check

Returns:

type description
Bool true if the value is finite or false otherwise

Examples:

1
Float32.isFinite(0.5f)
1
Float32.isFinite(1.0f)
1
Float32.isFinite(Infinityf) == false
1
Float32.isFinite(-Infinityf) == false
1
Float32.isFinite(NaNf) == false

Float32.isNaN

Added in 0.6.5 No other changes yet.
1
isNaN: (x: Float32) => Bool

Checks if the value is a float NaN value (Not A Number).

Parameters:

param type description
x Float32 The value to check

Returns:

type description
Bool true if the value is NaN, otherwise false

Examples:

1
Float32.isNaN(NaNf)
1
Float32.isNaN(Infinityf) == false
1
Float32.isNaN(-Infinityf) == false
1
Float32.isNaN(0.5f) == false
1
Float32.isNaN(1.0f) == false

Float32.isInfinite

Added in 0.6.5 No other changes yet.
1
isInfinite: (x: Float32) => Bool

Checks if a float is infinite, that is either of positive or negative infinity.

Parameters:

param type description
x Float32 The value to check

Returns:

type description
Bool true if the value is infinite or false otherwise

Examples:

1
Float32.isInfinite(Infinityf)
1
Float32.isInfinite(-Infinityf)
1
Float32.isInfinite(NaNf) == false
1
Float32.isInfinite(0.5f) == false
1
Float32.isInfinite(1.0f) == false

Float32.min

Added in 0.7.0 No other changes yet.
1
min: (x: Float32, y: Float32) => Float32

Returns the smaller of its operands.

Parameters:

param type description
x Float32 The first operand
y Float32 The second operand

Returns:

type description
Float32 The smaller of the two operands

Examples:

1
Float32.min(5.0f, 2.0f) == 2.0f

Float32.max

Added in 0.7.0 No other changes yet.
1
max: (x: Float32, y: Float32) => Float32

Returns the larger of its operands.

Parameters:

param type description
x Float32 The first operand
y Float32 The second operand

Returns:

type description
Float32 The larger of the two operands

Examples:

1
Float32.max(5.0f, 2.0f) == 5.0f

Float32.abs

Added in 0.6.5 No other changes yet.
1
abs: (x: Float32) => Float32

Returns the absolute value. That is, it returns x if x is positive or zero and the negation of x if x is negative.

Parameters:

param type description
x Float32 The operand

Returns:

type description
Float32 The absolute value of the operand

Examples:

1
Float32.abs(-1.0f) == 1.0f
1
Float32.abs(5.0f) == 5.0f

Float32.neg

Added in 0.6.5 No other changes yet.
1
neg: (x: Float32) => Float32

Returns the negation of its operand.

Parameters:

param type description
x Float32 The operand

Returns:

type description
Float32 The negated operand

Examples:

1
Float32.neg(-1.0f) == 1.0f
1
Float32.neg(1.0f) == -1.0f

Float32.ceil

Added in 0.7.0 No other changes yet.
1
ceil: (x: Float32) => Float32

Rounds its operand up to the next largest whole value.

Parameters:

param type description
x Float32 The operand to ceil

Returns:

type description
Float32 The next largest whole value of the operand

Examples:

1
Float32.ceil(5.5f) == 6.0f
1
Float32.ceil(-5.5f) == -5.0f

Float32.floor

Added in 0.7.0 No other changes yet.
1
floor: (x: Float32) => Float32

Rounds its operand down to the largest whole value less than the operand.

Parameters:

param type description
x Float32 The operand to floor

Returns:

type description
Float32 The previous whole value of the operand

Examples:

1
Float32.floor(5.5f) == 5.0f
1
Float32.floor(-5.5f) == -6.0f

Float32.trunc

Added in 0.7.0 No other changes yet.
1
trunc: (x: Float32) => Float32

Returns the whole value part of its operand, removing any fractional value.

Parameters:

param type description
x Float32 The operand to truncate

Returns:

type description
Float32 The whole value part of the operand

Examples:

1
Float32.trunc(5.5f) == 5.0f

Float32.round

Added in 0.7.0 No other changes yet.
1
round: (x: Float32) => Float32

Returns its operand rounded to its nearest integer.

Parameters:

param type description
x Float32 The operand to round

Returns:

type description
Float32 The nearest integer to the operand

Examples:

1
Float32.round(5.5f) == 6.0f
1
Float32.round(5.4f) == 5.0f
1
Float32.round(-5.5f) == -6.0f
1
Float32.round(-5.4f) == -5.0f

Float32.sqrt

Added in 0.7.0 No other changes yet.
1
sqrt: (x: Float32) => Float32

Computes the square root of its operand.

Parameters:

param type description
x Float32 The operand to square root

Returns:

type description
Float32 The square root of the operand

Examples:

1
Float32.sqrt(25.0f) == 5.0f

Float32.copySign

Added in 0.7.0 No other changes yet.
1
copySign: (x: Float32, y: Float32) => Float32

Copys the sign of the second operand to the first operand.

Parameters:

param type description
x Float32 The operand to modify
y Float32 The operand to copy the sign from

Returns:

type description
Float32 The first operand with the sign of the second operand

Examples:

1
Float32.copySign(2.0f, 1.0f) == 2.0f
1
Float32.copySign(3.0f, -1.0f) == -3.0f
1
Float32.copySign(-5.0f, 1.0f) == 5.0f

Float32.isClose

Added in 0.7.0 No other changes yet.
1
2
3
isClose:
(a: Float32, b: Float32, ?relativeTolerance: Float32,
?absoluteTolerance: Float32) => Bool

Determines whether two values are considered close to each other using a relative and absolute tolerance.

Parameters:

param type description
a Float32 The first value
b Float32 The second value
?relativeTolerance Float32 The maximum tolerance to use relative to the larger absolute value a or b
?absoluteTolerance Float32 The absolute tolerance to use, regardless of the values of a or b

Returns:

type description
Bool true if the values are considered close to each other or false otherwise

Examples:

1
Float32.isClose(1.233f, 1.233f)
1
Float32.isClose(1.233f, 1.233000001f)
1
Float32.isClose(8.005f, 8.450f, absoluteTolerance=0.5f)
1
Float32.isClose(4.0f, 4.1f, relativeTolerance=0.025f)
1
Float32.isClose(1.233f, 1.24f) == false
1
Float32.isClose(1.233f, 1.4566f) == false
1
Float32.isClose(8.005f, 8.450f, absoluteTolerance=0.4f) == false
1
Float32.isClose(4.0f, 4.1f, relativeTolerance=0.024f) == false

Float32.sin

Added in 0.7.0 No other changes yet.
1
sin: (radians: Float32) => Float32

Computes the sine of a float (in radians).

Parameters:

param type description
radians Float32 The input in radians

Returns:

type description
Float32 The computed sine

Examples:

1
Float32.sin(0.0f) == 0.0f

Float32.cos

Added in 0.7.0 No other changes yet.
1
cos: (radians: Float32) => Float32

Computes the cosine of a float (in radians).

Parameters:

param type description
radians Float32 The input in radians

Returns:

type description
Float32 The computed cosine

Examples:

1
Float32.cos(0.0f) == 1.0f

Float32.tan

Added in 0.7.0 No other changes yet.
1
tan: (radians: Float32) => Float32

Computes the tangent of a number (in radians).

Parameters:

param type description
radians Float32 The input in radians

Returns:

type description
Float32 The computed tangent

Examples:

1
Float32.tan(0.0f) == 0.0f
This is a notification!