Number

GitHub   Edit on GitHub

Utilities for working with numbers.

Added in 0.4.0 No other changes yet.
1
import Number from "number"

Constants

Number constant values.

Number.nan

Added in 0.5.4 No other changes yet.
1
nan : Number

NaN represented as a Number value.

Number.infinity

Added in 0.5.4 No other changes yet.
1
infinity : Number

Infinity represented as a Number value.

Number.pi

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

Pi represented as a Number value.

Number.tau

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

Tau represented as a Number value.

Number.e

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

Euler’s number represented as a Number value.


Operations

Functions for operating on values of the Number type.

Number.add

Added in 0.4.0 No other changes yet.
1
add : (Number, Number) -> Number

Computes the sum of its operands.

Parameters:

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

Returns:

type description
Number The sum of the two operands

Number.sub

Added in 0.4.0 No other changes yet.
1
sub : (Number, Number) -> Number

Computes the difference of its operands.

Parameters:

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

Returns:

type description
Number The difference of the two operands

Number.mul

Added in 0.4.0 No other changes yet.
1
mul : (Number, Number) -> Number

Computes the product of its operands.

Parameters:

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

Returns:

type description
Number The product of the two operands

Number.div

Added in 0.4.0 No other changes yet.
1
div : (Number, Number) -> Number

Computes the quotient of its operands.

Parameters:

param type description
x Number The dividend
y Number The divisor

Returns:

type description
Number The quotient of the two operands

Number.pow

Added in 0.5.4 No other changes yet.
1
pow : (Number, Number) -> Number

Computes the exponentiation of the given base and power.

Parameters:

param type description
base Number The base number
power Number The exponent number

Returns:

type description
Number The base raised to the given power

Number.exp

Added in 0.5.4 No other changes yet.
1
exp : Number -> Number

Computes the exponentiation of Euler’s number to the given power.

Parameters:

param type description
power Number The exponent number

Returns:

type description
Number The Number.e value raised to the given power

Number.sqrt

Added in 0.4.0 No other changes yet.
1
sqrt : Number -> Number

Computes the square root of its operand.

Parameters:

param type description
x Number The number to square root

Returns:

type description
Number The square root of the operand

Number.sign

1
sign : Number -> Number

Determine the positivity or negativity of a Number.

Parameters:

param type description
x Number The number to inspect

Returns:

type description
Number -1 if the number is negative, 1 if positive, or 0 otherwise; signedness of -0.0 is preserved

Examples:

1
Number.sign(-10000) == -1
1
Number.sign(222222) == 1
1
Number.sign(0) == 0

Number.min

Added in 0.4.0
versionchanges
0.5.4Handle NaN properly
1
min : (Number, Number) -> Number

Returns the smaller of its operands.

Parameters:

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

Returns:

type description
Number The smaller of the two operands

Number.max

Added in 0.4.0
versionchanges
0.5.4Handle NaN properly
1
max : (Number, Number) -> Number

Returns the larger of its operands.

Parameters:

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

Returns:

type description
Number The larger of the two operands

Number.ceil

Added in 0.4.0
versionchanges
0.5.4Handle NaN and Infinity properly
1
ceil : Number -> Number

Rounds its operand up to the next largest integer.

Parameters:

param type description
x Number The number to round

Returns:

type description
Number The next largest integer of the operand

Number.floor

Added in 0.4.0
versionchanges
0.5.4Handle NaN and Infinity properly
1
floor : Number -> Number

Rounds its operand down to the largest integer less than the operand.

Parameters:

param type description
x Number The number to round

Returns:

type description
Number The previous integer of the operand

Number.trunc

Added in 0.4.0
versionchanges
0.5.4Handle NaN and Infinity properly
1
trunc : Number -> Number

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

Parameters:

param type description
x Number The number to truncate

Returns:

type description
Number The integer part of the operand

Number.round

Added in 0.4.0
versionchanges
0.5.4Handle NaN and Infinity properly
1
round : Number -> Number

Returns its operand rounded to its nearest integer.

Parameters:

param type description
x Number The number to round

Returns:

type description
Number The nearest integer to the operand

Number.abs

Added in 0.4.0 No other changes yet.
1
abs : Number -> Number

Returns the absolute value of a number. 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 Number The operand

Returns:

type description
Number The absolute value of the operand

Number.neg

Added in 0.4.0 No other changes yet.
1
neg : Number -> Number

Returns the negation of its operand.

Parameters:

param type description
x Number The number to negate

Returns:

type description
Number The negated operand

Number.isFloat

Added in 0.5.3 No other changes yet.
1
isFloat : Number -> Bool

Checks if a number is a floating point value.

Parameters:

param type description
x Number The number to check

Returns:

type description
Bool true if the value is a floating point number or false otherwise

Number.isInteger

Added in 0.5.3 No other changes yet.
1
isInteger : Number -> Bool

Checks if a number is an integer.

Parameters:

param type description
x Number The number to check

Returns:

type description
Bool true if the value is an integer or false otherwise

Number.isRational

Added in 0.5.3 No other changes yet.
1
isRational : Number -> Bool

Checks if a number is a non-integer rational value.

Parameters:

param type description
x Number The number to check

Returns:

type description
Bool true if the value is a non-integer rational number or false otherwise

Number.isFinite

Added in 0.4.0 No other changes yet.
1
isFinite : Number -> Bool

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

Parameters:

param type description
x Number The number to check

Returns:

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

Number.isNaN

Added in 0.4.0 No other changes yet.
1
isNaN : Number -> Bool

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

Parameters:

param type description
x Number The number to check

Returns:

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

Number.isInfinite

Added in 0.4.0 No other changes yet.
1
isInfinite : Number -> Bool

Checks if a number is infinite, that is either of floating point positive or negative infinity. Note that this function is not the exact opposite of isFinite(Number) in that it doesn’t return true for NaN.

Parameters:

param type description
x Number The number to check

Returns:

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

Number.parseInt

Added in 0.4.5 No other changes yet.
1
parseInt : (String, Number) -> Result<Number, String>

Parses a string representation of an integer into a Number using the specified radix (also known as a number system “base”).

If the string has a radix prefix (i.e. “0x”/“0X”, “0o”/“0O”, or “0b”/“0B” for radixes 16, 8, or 2 respectively), the supplied radix is ignored in favor of the prefix. Underscores that appear in the numeric portion of the input are ignored.

Parameters:

param type description
input String The string to parse
radix Number The number system base to use when parsing the input string

Returns:

type description
Result<Number, String> Ok(value) containing the parsed number on a successful parse or Err(msg) containing an error message string otherwise

Number.parseFloat

Added in 0.5.5 No other changes yet.
1
parseFloat : String -> Result<Number, String>

Parses a string representation of a float into a Number. Underscores that appear in numeric portions of the input are ignored.

Parameters:

param type description
input String The string to parse

Returns:

type description
Result<Number, String> Ok(value) containing the parsed number on a successful parse or Err(msg) containing an error message string otherwise

Number.parse

Added in 0.5.5 No other changes yet.
1
parse : String -> Result<Number, String>

Parses a string representation of an integer, float, or rational into a Number. Underscores that appear in the numeric portion of the input are ignored.

Parameters:

param type description
input String The string to parse

Returns:

type description
Result<Number, String> Ok(value) containing the parsed number on a successful parse or Err(msg) containing an error message string otherwise

Number.sin

Added in 0.5.2
versionchanges
0.5.4Handle NaN and Infinity
1
sin : Number -> Number

Computes the sine of a number (in radians) using Chebyshev polynomials.

Parameters:

param type description
radians Number The input in radians

Returns:

type description
Number The computed sine

Number.cos

Added in 0.5.2
versionchanges
0.5.4Handle NaN and Infinity
1
cos : Number -> Number

Computes the cosine of a number (in radians) using Chebyshev polynomials.

Parameters:

param type description
radians Number The input in radians

Returns:

type description
Number The computed cosine

Number.tan

Added in 0.5.4 No other changes yet.
1
tan : Number -> Number

Computes the tangent of a number (in radians) using Chebyshev polynomials.

Parameters:

param type description
radians Number The input in radians

Returns:

type description
Number The computed tangent

Number.gamma

Added in 0.5.4 No other changes yet.
1
gamma : Number -> Number

Computes the gamma function of a value using Lanczos approximation.

Parameters:

param type description
z Number The value to interpolate

Returns:

type description
Number The gamma of the given value

Throws:

InvalidArgument(String)

  • When z is zero

Number.factorial

Added in 0.5.4 No other changes yet.
1
factorial : Number -> Number

Computes the product of consecutive integers for an integer input and computes the gamma function for non-integer inputs.

Parameters:

param type description
n Number The value to factorialize

Returns:

type description
Number The factorial of the given value

Throws:

InvalidArgument(String)

  • When n is negative

Number.toRadians

Added in 0.5.4 No other changes yet.
1
toRadians : Number -> Number

Converts degrees to radians.

Parameters:

param type description
degrees Number The value to convert

Returns:

type description
Number The value in radians

Number.toDegrees

Added in 0.5.4 No other changes yet.
1
toDegrees : Number -> Number

Converts radians to degrees.

Parameters:

param type description
radians Number The value to convert

Returns:

type description
Number The value in degrees
This is a notification!