Utils Functions (18)

Utility functions for type checking and formatting

bin
Format a number as binary
Syntax
bin(value)
Type Signatures
number | BigNumber, number | BigNumber, number | BigNumber
Parameters
NameTypeDescription
valuenumber | BigNumberValue to be stringified
wordSizenumber | BigNumberOptional word size (see `format`)
Returns
string — The formatted value
Examples
bin(2)
See Also
oct hex
clone
Clone a variable. Creates a copy of primitive variables, and a deep copy of matrices
Syntax
clone(x)
Parameters
NameTypeDescription
x*Object to be cloned
Returns
* — A clone of object x
Examples
clone(3.5)
clone(2 - 4i)
clone(45 deg)
clone([1
2; 3
See Also
format
Format a value of any type as string.
Syntax
format(value) | format(value | precision)
Parameters
NameTypeDescription
value*Value to be stringified
optionsObject | Function | numberFormatting options
Returns
string — The formatted value
Examples
format(2.3)
format(3 - 4i)
format([
See Also
print
hasNumericValue
Test whether a value is an numeric value.
Syntax
hasNumericValue(x)
Parameters
NameTypeDescription
x*Value to be tested
Returns
boolean — Returns true when `x` is a `number`, `BigNumber`,
Examples
hasNumericValue(2)
hasNumericValue("2")
isNumeric("2")
hasNumericValue(0)
hasNumericValue(bignumber(500))
hex
Format a number as hexadecimal
Syntax
hex(value)
Type Signatures
number | BigNumber, number | BigNumber, number | BigNumber
Parameters
NameTypeDescription
valuenumber | BigNumberValue to be stringified
wordSizenumber | BigNumberOptional word size (see `format`)
Returns
string — The formatted value
Examples
hex(240)
See Also
bin oct
isBounded
Test whether a value or its entries are bounded.
Syntax
isBounded(x)
Parameters
NameTypeDescription
xnumber | BigNumber | bigint | Complex | Fraction | Unit | Array | MatrixValue to be tested
Returns
boolean — Returns true when `x` is bounded.
Examples
isBounded(Infinity)
isBounded(bigint(3))
isBounded([3
-Infinity
-3
isFinite
Test whether a value is finite, elementwise on collections.
Syntax
isFinite(x)
Parameters
NameTypeDescription
xnumber | BigNumber | bigint | Complex | Fraction | Unit | Array | MatrixValue to be tested
Returns
boolean | Array | Matrix —
Examples
isFinite(Infinity)
isFinite(bigint(3))
isFinite([3
-Infinity
-3
isInteger
Test whether a value is an integer number.
Syntax
isInteger(x)
Parameters
NameTypeDescription
xnumber | BigNumber | bigint | Fraction | Array | MatrixValue to be tested
Returns
boolean — Returns true when `x` contains a numeric, integer value.
Examples
isInteger(2)
isInteger(3.5)
isInteger([3
0.5
-2
isNaN
Test whether a value is NaN (not a number)
Syntax
isNaN(x)
Parameters
NameTypeDescription
xnumber | BigNumber | bigint | Fraction | Unit | Array | MatrixValue to be tested
Returns
boolean — Returns true when `x` is NaN.
Examples
isNaN(2)
isNaN(0 / 0)
isNaN(NaN)
isNaN(Infinity)
isNegative
Test whether a value is negative: smaller than zero.
Syntax
isNegative(x)
Parameters
NameTypeDescription
xnumber | BigNumber | bigint | Fraction | Unit | Array | MatrixValue to be tested
Returns
boolean — Returns true when `x` is larger than zero.
Examples
isNegative(2)
isNegative(0)
isNegative(-4)
isNegative([3
0.5
isNumeric
Test whether a value is a numeric value.
Syntax
isNumeric(x)
Parameters
NameTypeDescription
x*Value to be tested
Returns
boolean — Returns true when `x` is a `number`, `BigNumber`,
Examples
isNumeric(2)
isNumeric("2")
hasNumericValue("2")
isNumeric(0)
isNumeric(bignumber(500))
isPositive
Test whether a value is positive: larger than zero.
Syntax
isPositive(x)
Parameters
NameTypeDescription
xnumber | BigNumber | bigint | Fraction | Unit | Array | MatrixValue to be tested
Returns
boolean — Returns true when `x` is larger than zero.
Examples
isPositive(2)
isPositive(0)
isPositive(-4)
isPositive([3
0.5
isPrime
Test whether a value is prime: has no divisors other than itself and one.
Syntax
isPrime(x)
Parameters
NameTypeDescription
xnumber | BigNumber | bigint | Array | MatrixValue to be tested
Returns
boolean — Returns true when `x` is larger than zero.
Examples
isPrime(3)
isPrime(-2)
isPrime([2
17
100
isZero
Test whether a value is zero.
Syntax
isZero(x)
Parameters
NameTypeDescription
xnumber | BigNumber | bigint | Complex | Fraction | Unit | Array | MatrixValue to be tested
Returns
boolean — Returns true when `x` is zero.
Examples
isZero(2)
isZero(0)
isZero(-4)
isZero([3
0
numeric
Convert a numeric input to a specific numeric type: number, BigNumber, bigint, or Fraction.
Syntax
numeric(x)
Parameters
NameTypeDescription
valuestring | number | BigNumber | bigint | Fraction
outputTypestring
Returns
number | BigNumber | bigint | Fraction —
Examples
numeric("4")
numeric("4
number")
numeric("4
bigint")
oct
Format a number as octal
Syntax
oct(value)
Type Signatures
number | BigNumber, number | BigNumber, number | BigNumber
Parameters
NameTypeDescription
valuenumber | BigNumberValue to be stringified
wordSizenumber | BigNumberOptional word size (see `format`)
Returns
string — The formatted value
Examples
oct(56)
See Also
bin hex
print
Interpolate values into a string template.
Syntax
print(template | values) | print(template
Parameters
NameTypeDescription
templatestringA string containing variable placeholders.
valuesObject | Array | MatrixAn object or array containing variables
optionsnumber | ObjectFormatting options,
Returns
string — Interpolated string
Examples
print("Lucy is $age years old
{age: 5})
print("The value of pi is $pi
{pi: pi}
3)
See Also
format
typeOf
Get the type of a variable.
Syntax
typeOf(x)
Parameters
NameTypeDescription
x*The variable for which to test the type.
Returns
string — Returns the name of the type. Primitive types are lower case,
Examples
typeOf(3.5)
typeOf(2 - 4i)
typeOf(45 deg)
typeOf("hello world")