Num
Functions over single numbers, integer or double, and eight constants (Num.pi, Num.tau,
Num.e, Num.infinity and the integer and double limits). A checked operation returns the
failure as a tag where R would return NA, NaN or Inf with a warning; its unchecked twin
(Num.add beside Num.add_checked) stops with an error in that case. A NaN result, such as
Inf - Inf or Num.sin(Inf), is :Err(:Undefined) from a checked operation and an error from
any other. The bit operations take integers as 32-bit two’s complement.
| Function | Summary |
|---|---|
Num.to_str |
The number as text, with up to 15 significant digits. |
Num.compare |
:LT, :EQ or :GT, comparing first with second. |
Num.min |
The smaller number. |
Num.max |
The larger number. |
Num.is_lt |
Whether first < second. |
Num.is_gt |
Whether first > second. |
Num.is_lte |
Whether first <= second. |
Num.is_gte |
Whether first >= second. |
Num.is_approx_eq |
Whether two numbers are equal within a relative tolerance rtol (default 1e-5) or an absolute tolerance atol (default 1e-8). |
Num.is_zero |
Whether the number is zero. |
Num.is_positive |
Whether the number is greater than zero. |
Num.is_negative |
Whether the number is less than zero. |
Num.is_even |
Whether the number is a whole, even number. |
Num.is_odd |
Whether the number is a whole, odd number. |
Num.is_multiple_of |
Whether first is a whole multiple of second. |
Num.is_finite |
Whether the number is neither infinite nor NaN. |
Num.is_infinite |
Whether the number is Inf or -Inf. |
Num.abs |
The absolute value. |
Num.abs_diff |
The absolute difference of two numbers. |
Num.neg |
The number with its sign flipped. |
Num.ceiling |
Rounds up to a whole number, keeping the number type. |
Num.floor |
Rounds down to a whole number, keeping the number type. |
Num.round |
Rounds to the nearest whole number, halves away from zero, keeping the number type. |
Num.pow |
base raised to exponent. |
Num.sin |
The sine of an angle in radians. |
Num.cos |
The cosine of an angle in radians. |
Num.tan |
The tangent of an angle in radians. |
Num.atan |
The arctangent, in radians. |
Num.add_checked |
The sum, or :Err(:Overflow); a NaN sum such as Inf + -Inf is :Err(:Undefined). |
Num.sub_checked |
The difference, or :Err(:Overflow). |
Num.mul_checked |
The product, or :Err(:Overflow); a finite double that would become infinite overflows too. |
Num.add_saturated |
Adds two numbers, clamping an integer result to the largest or smallest integer. |
Num.sub_saturated |
Subtracts second from first, clamping an integer result. |
Num.mul_saturated |
Multiplies two numbers, clamping an integer result. |
Num.div_checked |
The quotient as a double, or :Err(:DivByZero). |
Num.div_trunc_checked |
The quotient rounded toward zero, or :Err(:DivByZero); Inf divided by Inf is :Err(:Undefined). |
Num.div_ceil_checked |
Divides and rounds up, or :Err(:DivByZero). |
Num.rem_checked |
The remainder of the truncated division, with the sign of first, or :Err(:DivByZero). |
Num.sqrt_checked |
The square root, or :Err(:SqrtOfNegative). |
Num.log_checked |
The natural logarithm, or :Err(:LogNeedsPositive). |
Num.to_double |
The number as a double. |
Num.to_integer_checked |
The number truncated toward zero as an integer, or :Err(:OutOfBounds) when it does not fit. |
Num.to_integer |
The number truncated toward zero as an integer. |
Num.add |
The sum. |
Num.sub |
second subtracted from first. |
Num.mul |
The product. |
Num.div |
The quotient as a double. |
Num.div_trunc |
The quotient rounded toward zero. |
Num.div_ceil |
The quotient rounded up. |
Num.rem |
The remainder of the truncated division, with the sign of first. |
Num.pow_int |
base raised to a non-negative exponent, as an integer. |
Num.sqrt |
The square root. |
Num.log |
The natural logarithm. |
Num.asin |
The arcsine in radians. |
Num.acos |
The arccosine in radians. |
Num.is_nan |
Whether the number is NaN. |
Num.bitwise_and |
The bits set in both integers, in 32-bit two’s complement. |
Num.bitwise_or |
The bits set in either integer. |
Num.bitwise_xor |
The bits set in exactly one of the integers. |
Num.bitwise_not |
The integer with every bit flipped, which is -number - 1. |
Num.shift_left_by |
Shifts the bits left by bits, from 0 to 31. |
Num.shift_right_by |
Shifts the bits right by bits, copying the sign bit in, so a negative number stays negative. |
Num.shift_right_zf_by |
Shifts the bits right by bits, filling with zeros. |
Num.count_one_bits |
The number of set bits. |
Num.count_leading_zero_bits |
The number of zero bits above the highest set bit, 32 for zero. |
Num.count_trailing_zero_bits |
The number of zero bits below the lowest set bit, 32 for zero. |
Num.pi |
The ratio of a circle’s circumference to its diameter. |
Num.tau |
The ratio of a circle’s circumference to its radius, 2 * Num.pi. |
Num.e |
Euler’s number, the base of the natural logarithm. |
Num.max_integer |
The largest integer, 2147483647L. |
Num.min_integer |
The smallest integer, -2147483647L. |
Num.max_double |
The largest finite double. |
Num.min_double |
The most negative finite double, the negation of Num.max_double. |
Num.infinity |
Positive infinity, R’s Inf. |
Num.to_str
Section titled “Num.to_str”Num.to_str <- function<T: scalar numeric>(number: T) -> character#: <T: scalar numeric> fn(number: T) -> characterNum.to_str <- function(number)The number as text, with up to 15 significant digits.
Num.to_str(1 / 3)#> "0.333333333333333"Num.compare
Section titled “Num.compare”Num.compare <- function<T: scalar numeric>(first: T, second: T) -> :LT | :EQ | :GT#: <T: scalar numeric> fn(first: T, second: T) -> :LT | :EQ | :GTNum.compare <- function(first, second):LT, :EQ or :GT, comparing first with second.
Num.compare(2L, 1L)#> :GTNum.min
Section titled “Num.min”Num.min <- function<T: scalar numeric>(first: T, second: T) -> T#: <T: scalar numeric> fn(first: T, second: T) -> TNum.min <- function(first, second)The smaller number.
Num.min(2L, 1L)#> 1LNum.max
Section titled “Num.max”Num.max <- function<T: scalar numeric>(first: T, second: T) -> T#: <T: scalar numeric> fn(first: T, second: T) -> TNum.max <- function(first, second)The larger number.
Num.max(2.5, 1)#> 2.5Num.is_lt
Section titled “Num.is_lt”Num.is_lt <- function<T: scalar numeric>(first: T, second: T) -> logical#: <T: scalar numeric> fn(first: T, second: T) -> logicalNum.is_lt <- function(first, second)Whether first < second.
Num.is_lt(1L, 2L)#> TRUENum.is_gt
Section titled “Num.is_gt”Num.is_gt <- function<T: scalar numeric>(first: T, second: T) -> logical#: <T: scalar numeric> fn(first: T, second: T) -> logicalNum.is_gt <- function(first, second)Whether first > second.
Num.is_gt(1L, 2L)#> FALSENum.is_lte
Section titled “Num.is_lte”Num.is_lte <- function<T: scalar numeric>(first: T, second: T) -> logical#: <T: scalar numeric> fn(first: T, second: T) -> logicalNum.is_lte <- function(first, second)Whether first <= second.
Num.is_lte(2, 2L)#> TRUENum.is_gte
Section titled “Num.is_gte”Num.is_gte <- function<T: scalar numeric>(first: T, second: T) -> logical#: <T: scalar numeric> fn(first: T, second: T) -> logicalNum.is_gte <- function(first, second)Whether first >= second.
Num.is_gte(1.5, 2)#> FALSENum.is_approx_eq
Section titled “Num.is_approx_eq”#: <T: scalar numeric> fn(first: T, second: T, [rtol]: double, [atol]: double) -> logicalNum.is_approx_eq <- function(first, second, rtol, atol)Whether two numbers are equal within a relative tolerance rtol (default 1e-5) or an absolute
tolerance atol (default 1e-8).
Num.is_approx_eq(0.1 + 0.2, 0.3)#> TRUENum.is_zero
Section titled “Num.is_zero”Num.is_zero <- function<T: scalar numeric>(number: T) -> logical#: <T: scalar numeric> fn(number: T) -> logicalNum.is_zero <- function(number)Whether the number is zero.
Num.is_zero(-0)#> TRUENum.is_positive
Section titled “Num.is_positive”Num.is_positive <- function<T: scalar numeric>(number: T) -> logical#: <T: scalar numeric> fn(number: T) -> logicalNum.is_positive <- function(number)Whether the number is greater than zero.
Num.is_positive(0L)#> FALSENum.is_negative
Section titled “Num.is_negative”Num.is_negative <- function<T: scalar numeric>(number: T) -> logical#: <T: scalar numeric> fn(number: T) -> logicalNum.is_negative <- function(number)Whether the number is less than zero.
Num.is_negative(-1)#> TRUENum.is_even
Section titled “Num.is_even”Num.is_even <- function<T: scalar numeric>(number: T) -> logical#: <T: scalar numeric> fn(number: T) -> logicalNum.is_even <- function(number)Whether the number is a whole, even number.
Num.is_even(4L)#> TRUENum.is_odd
Section titled “Num.is_odd”Num.is_odd <- function<T: scalar numeric>(number: T) -> logical#: <T: scalar numeric> fn(number: T) -> logicalNum.is_odd <- function(number)Whether the number is a whole, odd number.
Num.is_odd(-3L)#> TRUENum.is_multiple_of
Section titled “Num.is_multiple_of”Num.is_multiple_of <- function<T: scalar numeric>(first: T, second: T) -> logical#: <T: scalar numeric> fn(first: T, second: T) -> logicalNum.is_multiple_of <- function(first, second)Whether first is a whole multiple of second. Only zero is a multiple of zero.
Num.is_multiple_of(12L, 4L)#> TRUENum.is_finite
Section titled “Num.is_finite”Num.is_finite <- function<T: scalar numeric>(number: T) -> logical#: <T: scalar numeric> fn(number: T) -> logicalNum.is_finite <- function(number)Whether the number is neither infinite nor NaN.
Num.is_finite(1 / 0)#> FALSENum.is_infinite
Section titled “Num.is_infinite”Num.is_infinite <- function<T: scalar numeric>(number: T) -> logical#: <T: scalar numeric> fn(number: T) -> logicalNum.is_infinite <- function(number)Whether the number is Inf or -Inf.
Num.is_infinite(-1 / 0)#> TRUENum.abs
Section titled “Num.abs”Num.abs <- function<T: scalar numeric>(number: T) -> T#: <T: scalar numeric> fn(number: T) -> TNum.abs <- function(number)The absolute value.
Num.abs(-3L)#> 3LNum.abs_diff
Section titled “Num.abs_diff”Num.abs_diff <- function<T: scalar numeric>(first: T, second: T) -> T#: <T: scalar numeric> fn(first: T, second: T) -> TNum.abs_diff <- function(first, second)The absolute difference of two numbers. An integer result that overflows is an error.
Num.abs_diff(3L, 10L)#> 7LNum.neg
Section titled “Num.neg”Num.neg <- function<T: scalar numeric>(number: T) -> T#: <T: scalar numeric> fn(number: T) -> TNum.neg <- function(number)The number with its sign flipped.
Num.neg(2.5)#> -2.5Num.ceiling
Section titled “Num.ceiling”Num.ceiling <- function<T: scalar numeric>(number: T) -> T#: <T: scalar numeric> fn(number: T) -> TNum.ceiling <- function(number)Rounds up to a whole number, keeping the number type.
Num.ceiling(1.2)#> 2Num.floor
Section titled “Num.floor”Num.floor <- function<T: scalar numeric>(number: T) -> T#: <T: scalar numeric> fn(number: T) -> TNum.floor <- function(number)Rounds down to a whole number, keeping the number type.
Num.floor(-1.2)#> -2Num.round
Section titled “Num.round”Num.round <- function<T: scalar numeric>(number: T) -> T#: <T: scalar numeric> fn(number: T) -> TNum.round <- function(number)Rounds to the nearest whole number, halves away from zero, keeping the number type.
Num.round(2.5)#> 3Num.pow
Section titled “Num.pow”Num.pow <- function<T: scalar numeric>(base: T, exponent: T) -> double#: <T: scalar numeric> fn(base: T, exponent: T) -> doubleNum.pow <- function(base, exponent)base raised to exponent. A result that is not a real number, as for Num.pow(-1, 0.5), is an
error.
Num.pow(2L, 10L)#> 1024Num.sin
Section titled “Num.sin”Num.sin <- function<T: scalar numeric>(number: T) -> double#: <T: scalar numeric> fn(number: T) -> doubleNum.sin <- function(number)The sine of an angle in radians. An infinite angle is an error, because its sine is undefined;
the same holds for Num.cos and Num.tan.
Num.sin(0)#> 0Num.cos
Section titled “Num.cos”Num.cos <- function<T: scalar numeric>(number: T) -> double#: <T: scalar numeric> fn(number: T) -> doubleNum.cos <- function(number)The cosine of an angle in radians.
Num.cos(0)#> 1Num.tan
Section titled “Num.tan”Num.tan <- function<T: scalar numeric>(number: T) -> double#: <T: scalar numeric> fn(number: T) -> doubleNum.tan <- function(number)The tangent of an angle in radians.
Num.tan(0)#> 0Num.atan
Section titled “Num.atan”Num.atan <- function<T: scalar numeric>(number: T) -> double#: <T: scalar numeric> fn(number: T) -> doubleNum.atan <- function(number)The arctangent, in radians.
Num.atan(1) * 4#> 3.14159265358979Num.add_checked
Section titled “Num.add_checked”Num.add_checked <- function<T: scalar numeric>(first: T, second: T) -> Result<T, :Overflow | :Undefined>#: <T: scalar numeric> fn(first: T, second: T) -> Result<T, :Overflow | :Undefined>Num.add_checked <- function(first, second)The sum, or :Err(:Overflow); a NaN sum such as Inf + -Inf is :Err(:Undefined).
Num.add_checked(.Machine$integer.max, 1L)#> :Err(:Overflow)Num.sub_checked
Section titled “Num.sub_checked”Num.sub_checked <- function<T: scalar numeric>(first: T, second: T) -> Result<T, :Overflow | :Undefined>#: <T: scalar numeric> fn(first: T, second: T) -> Result<T, :Overflow | :Undefined>Num.sub_checked <- function(first, second)The difference, or :Err(:Overflow).
Num.sub_checked(10L, 3L)#> :Ok(7L)Num.mul_checked
Section titled “Num.mul_checked”Num.mul_checked <- function<T: scalar numeric>(first: T, second: T) -> Result<T, :Overflow | :Undefined>#: <T: scalar numeric> fn(first: T, second: T) -> Result<T, :Overflow | :Undefined>Num.mul_checked <- function(first, second)The product, or :Err(:Overflow); a finite double that would become infinite overflows too.
Num.mul_checked(1e308, 10)#> :Err(:Overflow)Num.add_saturated
Section titled “Num.add_saturated”Num.add_saturated <- function<T: scalar numeric>(first: T, second: T) -> T#: <T: scalar numeric> fn(first: T, second: T) -> TNum.add_saturated <- function(first, second)Adds two numbers, clamping an integer result to the largest or smallest integer.
Num.add_saturated(2147483647L, 1L)#> 2147483647LNum.sub_saturated
Section titled “Num.sub_saturated”Num.sub_saturated <- function<T: scalar numeric>(first: T, second: T) -> T#: <T: scalar numeric> fn(first: T, second: T) -> TNum.sub_saturated <- function(first, second)Subtracts second from first, clamping an integer result.
Num.sub_saturated(-2147483647L, 1L)#> -2147483647LNum.mul_saturated
Section titled “Num.mul_saturated”Num.mul_saturated <- function<T: scalar numeric>(first: T, second: T) -> T#: <T: scalar numeric> fn(first: T, second: T) -> TNum.mul_saturated <- function(first, second)Multiplies two numbers, clamping an integer result.
Num.mul_saturated(100000L, 100000L)#> 2147483647LNum.div_checked
Section titled “Num.div_checked”Num.div_checked <- function<T: scalar numeric>(first: T, second: T) -> Result<double, :DivByZero | :Undefined>#: <T: scalar numeric> fn(first: T, second: T) -> Result<double, :DivByZero | :Undefined>Num.div_checked <- function(first, second)The quotient as a double, or :Err(:DivByZero).
Num.div_checked(7L, 2L)#> :Ok(3.5)Num.div_trunc_checked
Section titled “Num.div_trunc_checked”Num.div_trunc_checked <- function<T: scalar numeric>(first: T, second: T) -> Result<T, :DivByZero | :Undefined>#: <T: scalar numeric> fn(first: T, second: T) -> Result<T, :DivByZero | :Undefined>Num.div_trunc_checked <- function(first, second)The quotient rounded toward zero, or :Err(:DivByZero); Inf divided by Inf is
:Err(:Undefined).
Num.div_trunc_checked(-7L, 2L)#> :Ok(-3L)Num.div_trunc_checked(Inf, Inf)#> :Err(:Undefined)Num.div_ceil_checked
Section titled “Num.div_ceil_checked”Num.div_ceil_checked <- function<T: scalar numeric>(first: T, second: T) -> Result<T, :DivByZero | :Undefined>#: <T: scalar numeric> fn(first: T, second: T) -> Result<T, :DivByZero | :Undefined>Num.div_ceil_checked <- function(first, second)Divides and rounds up, or :Err(:DivByZero).
Num.div_ceil_checked(7L, 2L)#> :Ok(4L)Num.rem_checked
Section titled “Num.rem_checked”Num.rem_checked <- function<T: scalar numeric>(first: T, second: T) -> Result<T, :DivByZero | :Undefined>#: <T: scalar numeric> fn(first: T, second: T) -> Result<T, :DivByZero | :Undefined>Num.rem_checked <- function(first, second)The remainder of the truncated division, with the sign of first, or :Err(:DivByZero).
Num.rem_checked(-7L, 2L)#> :Ok(-1L)Num.sqrt_checked
Section titled “Num.sqrt_checked”Num.sqrt_checked <- function<T: scalar numeric>(number: T) -> Result<double, :SqrtOfNegative>#: <T: scalar numeric> fn(number: T) -> Result<double, :SqrtOfNegative>Num.sqrt_checked <- function(number)The square root, or :Err(:SqrtOfNegative).
Num.sqrt_checked(-1)#> :Err(:SqrtOfNegative)Num.log_checked
Section titled “Num.log_checked”Num.log_checked <- function<T: scalar numeric>(number: T) -> Result<double, :LogNeedsPositive>#: <T: scalar numeric> fn(number: T) -> Result<double, :LogNeedsPositive>Num.log_checked <- function(number)The natural logarithm, or :Err(:LogNeedsPositive).
Num.log_checked(exp(2))#> :Ok(2)Num.to_double
Section titled “Num.to_double”Num.to_double <- function<T: scalar numeric>(number: T) -> double#: <T: scalar numeric> fn(number: T) -> doubleNum.to_double <- function(number)The number as a double.
Num.to_double(3L)#> 3Num.to_integer_checked
Section titled “Num.to_integer_checked”Num.to_integer_checked <- function<T: scalar numeric>(number: T) -> Result<integer, :OutOfBounds>#: <T: scalar numeric> fn(number: T) -> Result<integer, :OutOfBounds>Num.to_integer_checked <- function(number)The number truncated toward zero as an integer, or :Err(:OutOfBounds) when it does not fit.
Num.to_integer_checked(-3.7)#> :Ok(-3L)Num.to_integer
Section titled “Num.to_integer”Num.to_integer <- function<T: scalar numeric>(number: T) -> integer#: <T: scalar numeric> fn(number: T) -> integerNum.to_integer <- function(number)The number truncated toward zero as an integer. A number that does not fit an integer is an
error; Num.to_integer_checked returns :Err(:OutOfBounds) instead.
Num.to_integer(-3.7)#> -3LNum.add
Section titled “Num.add”Num.add <- function<T: scalar numeric>(first: T, second: T) -> T#: <T: scalar numeric> fn(first: T, second: T) -> TNum.add <- function(first, second)The sum. An integer sum that overflows stops with an error, so use Num.add_checked when
overflow is possible. Unlike +, it can be passed by name.
List.walk(list(1L, 2L, 3L), 0L, Num.add)#> 6LNum.sub
Section titled “Num.sub”Num.sub <- function<T: scalar numeric>(first: T, second: T) -> T#: <T: scalar numeric> fn(first: T, second: T) -> TNum.sub <- function(first, second)second subtracted from first. An integer result that overflows is an error, and so is a
NaN result such as Inf - Inf.
Num.sub(10L, 4L)#> 6LNum.mul
Section titled “Num.mul”Num.mul <- function<T: scalar numeric>(first: T, second: T) -> T#: <T: scalar numeric> fn(first: T, second: T) -> TNum.mul <- function(first, second)The product. An integer product that overflows is an error.
Num.mul(6L, 7L)#> 42LNum.div
Section titled “Num.div”Num.div <- function<T: scalar numeric>(first: T, second: T) -> double#: <T: scalar numeric> fn(first: T, second: T) -> doubleNum.div <- function(first, second)The quotient as a double. A zero divisor is an error; Num.div_checked returns
:Err(:DivByZero) instead.
Num.div(7L, 2L)#> 3.5Num.div_trunc
Section titled “Num.div_trunc”Num.div_trunc <- function<T: scalar numeric>(first: T, second: T) -> T#: <T: scalar numeric> fn(first: T, second: T) -> TNum.div_trunc <- function(first, second)The quotient rounded toward zero. A zero divisor is an error.
Num.div_trunc(-7L, 2L)#> -3LNum.div_ceil
Section titled “Num.div_ceil”Num.div_ceil <- function<T: scalar numeric>(first: T, second: T) -> T#: <T: scalar numeric> fn(first: T, second: T) -> TNum.div_ceil <- function(first, second)The quotient rounded up. A zero divisor is an error.
Num.div_ceil(7L, 2L)#> 4LNum.rem
Section titled “Num.rem”Num.rem <- function<T: scalar numeric>(first: T, second: T) -> T#: <T: scalar numeric> fn(first: T, second: T) -> TNum.rem <- function(first, second)The remainder of the truncated division, with the sign of first. A zero divisor is an error.
Num.rem(-7L, 2L)#> -1LNum.pow_int
Section titled “Num.pow_int”Num.pow_int <- function(base: integer, exponent: integer) -> integer#: fn(base: integer, exponent: integer) -> integerNum.pow_int <- function(base, exponent)base raised to a non-negative exponent, as an integer. A result that overflows is an error;
Num.pow returns a double instead.
Num.pow_int(3L, 4L)#> 81LNum.sqrt
Section titled “Num.sqrt”Num.sqrt <- function<T: scalar numeric>(number: T) -> double#: <T: scalar numeric> fn(number: T) -> doubleNum.sqrt <- function(number)The square root. A negative number is an error; Num.sqrt_checked returns
:Err(:SqrtOfNegative) instead.
Num.sqrt(16L)#> 4Num.log
Section titled “Num.log”Num.log <- function<T: scalar numeric>(number: T) -> double#: <T: scalar numeric> fn(number: T) -> doubleNum.log <- function(number)The natural logarithm. A number that is not positive is an error; Num.log_checked returns
:Err(:LogNeedsPositive) instead.
Num.log(Num.e)#> 1Num.asin
Section titled “Num.asin”Num.asin <- function<T: scalar numeric>(number: T) -> double#: <T: scalar numeric> fn(number: T) -> doubleNum.asin <- function(number)The arcsine in radians. A number outside -1 to 1 is an error.
Num.asin(1)#> 1.5707963267949Num.acos
Section titled “Num.acos”Num.acos <- function<T: scalar numeric>(number: T) -> double#: <T: scalar numeric> fn(number: T) -> doubleNum.acos <- function(number)The arccosine in radians. A number outside -1 to 1 is an error.
Num.acos(1)#> 0Num.is_nan
Section titled “Num.is_nan”Num.is_nan <- function<T: scalar numeric>(number: T) -> logical#: <T: scalar numeric> fn(number: T) -> logicalNum.is_nan <- function(number)Whether the number is NaN. It is the one library function that accepts NaN; NA is still an
error.
Num.is_nan(0 / 0)#> TRUENum.bitwise_and
Section titled “Num.bitwise_and”Num.bitwise_and <- function(first: integer, second: integer) -> integer#: fn(first: integer, second: integer) -> integerNum.bitwise_and <- function(first, second)The bits set in both integers, in 32-bit two’s complement.
Num.bitwise_and(12L, 10L)#> 8LNum.bitwise_or
Section titled “Num.bitwise_or”Num.bitwise_or <- function(first: integer, second: integer) -> integer#: fn(first: integer, second: integer) -> integerNum.bitwise_or <- function(first, second)The bits set in either integer.
Num.bitwise_or(12L, 10L)#> 14LNum.bitwise_xor
Section titled “Num.bitwise_xor”Num.bitwise_xor <- function(first: integer, second: integer) -> integer#: fn(first: integer, second: integer) -> integerNum.bitwise_xor <- function(first, second)The bits set in exactly one of the integers. A result whose bit pattern is -2147483648 is an
error, because R uses that value for NA; the same holds for every bit operation.
Num.bitwise_xor(12L, 10L)#> 6LNum.bitwise_not
Section titled “Num.bitwise_not”Num.bitwise_not <- function(number: integer) -> integer#: fn(number: integer) -> integerNum.bitwise_not <- function(number)The integer with every bit flipped, which is -number - 1.
Num.bitwise_not(5L)#> -6LNum.shift_left_by
Section titled “Num.shift_left_by”Num.shift_left_by <- function(number: integer, bits: integer) -> integer#: fn(number: integer, bits: integer) -> integerNum.shift_left_by <- function(number, bits)Shifts the bits left by bits, from 0 to 31. Bits shifted past the top are lost, as in Roc.
Num.shift_left_by(1L, 4L)#> 16LNum.shift_right_by
Section titled “Num.shift_right_by”Num.shift_right_by <- function(number: integer, bits: integer) -> integer#: fn(number: integer, bits: integer) -> integerNum.shift_right_by <- function(number, bits)Shifts the bits right by bits, copying the sign bit in, so a negative number stays negative.
Num.shift_right_by(-16L, 2L)#> -4LNum.shift_right_zf_by
Section titled “Num.shift_right_zf_by”Num.shift_right_zf_by <- function(number: integer, bits: integer) -> integer#: fn(number: integer, bits: integer) -> integerNum.shift_right_zf_by <- function(number, bits)Shifts the bits right by bits, filling with zeros.
Num.shift_right_zf_by(-16L, 28L)#> 15LNum.count_one_bits
Section titled “Num.count_one_bits”Num.count_one_bits <- function(number: integer) -> integer#: fn(number: integer) -> integerNum.count_one_bits <- function(number)The number of set bits.
Num.count_one_bits(255L)#> 8LNum.count_leading_zero_bits
Section titled “Num.count_leading_zero_bits”Num.count_leading_zero_bits <- function(number: integer) -> integer#: fn(number: integer) -> integerNum.count_leading_zero_bits <- function(number)The number of zero bits above the highest set bit, 32 for zero.
Num.count_leading_zero_bits(1L)#> 31LNum.count_trailing_zero_bits
Section titled “Num.count_trailing_zero_bits”Num.count_trailing_zero_bits <- function(number: integer) -> integer#: fn(number: integer) -> integerNum.count_trailing_zero_bits <- function(number)The number of zero bits below the lowest set bit, 32 for zero.
Num.count_trailing_zero_bits(8L)#> 3LNum.pi
Section titled “Num.pi”#: doubleNum.piThe ratio of a circle’s circumference to its diameter. It is a value, not a function.
Num.pi#> 3.14159265358979Num.tau
Section titled “Num.tau”#: doubleNum.tauThe ratio of a circle’s circumference to its radius, 2 * Num.pi.
Num.tau#> 6.28318530717959#: doubleNum.eEuler’s number, the base of the natural logarithm.
Num.e#> 2.71828182845905Num.max_integer
Section titled “Num.max_integer”#: integerNum.max_integerThe largest integer, 2147483647L. It is a value, not a function.
Num.max_integer#> 2147483647LNum.min_integer
Section titled “Num.min_integer”#: integerNum.min_integerThe smallest integer, -2147483647L. R stores NA in the one value below it, so that value is
not an integer here.
Num.min_integer#> -2147483647LNum.max_double
Section titled “Num.max_double”#: doubleNum.max_doubleThe largest finite double.
Num.max_double#> 1.79769313486232e+308Num.min_double
Section titled “Num.min_double”#: doubleNum.min_doubleThe most negative finite double, the negation of Num.max_double.
Num.min_double#> -1.79769313486232e+308Num.infinity
Section titled “Num.infinity”#: doubleNum.infinityPositive infinity, R’s Inf.
c(Num.infinity, -Num.infinity)#> c(Inf, -Inf)