# Num

{/* Generated from types/std.Rtypes by `just docs-std`. Do not edit this file. */}

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`](#numto_str) | The number as text, with up to 15 significant digits. |
| [`Num.compare`](#numcompare) | `:LT`, `:EQ` or `:GT`, comparing `first` with `second`. |
| [`Num.min`](#nummin) | The smaller number. |
| [`Num.max`](#nummax) | The larger number. |
| [`Num.is_lt`](#numis_lt) | Whether `first < second`. |
| [`Num.is_gt`](#numis_gt) | Whether `first > second`. |
| [`Num.is_lte`](#numis_lte) | Whether `first <= second`. |
| [`Num.is_gte`](#numis_gte) | Whether `first >= second`. |
| [`Num.is_approx_eq`](#numis_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`](#numis_zero) | Whether the number is zero. |
| [`Num.is_positive`](#numis_positive) | Whether the number is greater than zero. |
| [`Num.is_negative`](#numis_negative) | Whether the number is less than zero. |
| [`Num.is_even`](#numis_even) | Whether the number is a whole, even number. |
| [`Num.is_odd`](#numis_odd) | Whether the number is a whole, odd number. |
| [`Num.is_multiple_of`](#numis_multiple_of) | Whether `first` is a whole multiple of `second`. |
| [`Num.is_finite`](#numis_finite) | Whether the number is neither infinite nor `NaN`. |
| [`Num.is_infinite`](#numis_infinite) | Whether the number is `Inf` or `-Inf`. |
| [`Num.abs`](#numabs) | The absolute value. |
| [`Num.abs_diff`](#numabs_diff) | The absolute difference of two numbers. |
| [`Num.neg`](#numneg) | The number with its sign flipped. |
| [`Num.ceiling`](#numceiling) | Rounds up to a whole number, keeping the number type. |
| [`Num.floor`](#numfloor) | Rounds down to a whole number, keeping the number type. |
| [`Num.round`](#numround) | Rounds to the nearest whole number, halves away from zero, keeping the number type. |
| [`Num.pow`](#numpow) | `base` raised to `exponent`. |
| [`Num.sin`](#numsin) | The sine of an angle in radians. |
| [`Num.cos`](#numcos) | The cosine of an angle in radians. |
| [`Num.tan`](#numtan) | The tangent of an angle in radians. |
| [`Num.atan`](#numatan) | The arctangent, in radians. |
| [`Num.add_checked`](#numadd_checked) | The sum, or `:Err(:Overflow)`; a `NaN` sum such as `Inf + -Inf` is `:Err(:Undefined)`. |
| [`Num.sub_checked`](#numsub_checked) | The difference, or `:Err(:Overflow)`. |
| [`Num.mul_checked`](#nummul_checked) | The product, or `:Err(:Overflow)`; a finite double that would become infinite overflows too. |
| [`Num.add_saturated`](#numadd_saturated) | Adds two numbers, clamping an integer result to the largest or smallest integer. |
| [`Num.sub_saturated`](#numsub_saturated) | Subtracts `second` from `first`, clamping an integer result. |
| [`Num.mul_saturated`](#nummul_saturated) | Multiplies two numbers, clamping an integer result. |
| [`Num.div_checked`](#numdiv_checked) | The quotient as a double, or `:Err(:DivByZero)`. |
| [`Num.div_trunc_checked`](#numdiv_trunc_checked) | The quotient rounded toward zero, or `:Err(:DivByZero)`; `Inf` divided by `Inf` is `:Err(:Undefined)`. |
| [`Num.div_ceil_checked`](#numdiv_ceil_checked) | Divides and rounds up, or `:Err(:DivByZero)`. |
| [`Num.rem_checked`](#numrem_checked) | The remainder of the truncated division, with the sign of `first`, or `:Err(:DivByZero)`. |
| [`Num.sqrt_checked`](#numsqrt_checked) | The square root, or `:Err(:SqrtOfNegative)`. |
| [`Num.log_checked`](#numlog_checked) | The natural logarithm, or `:Err(:LogNeedsPositive)`. |
| [`Num.to_double`](#numto_double) | The number as a double. |
| [`Num.to_integer_checked`](#numto_integer_checked) | The number truncated toward zero as an integer, or `:Err(:OutOfBounds)` when it does not fit. |
| [`Num.to_integer`](#numto_integer) | The number truncated toward zero as an integer. |
| [`Num.add`](#numadd) | The sum. |
| [`Num.sub`](#numsub) | `second` subtracted from `first`. |
| [`Num.mul`](#nummul) | The product. |
| [`Num.div`](#numdiv) | The quotient as a double. |
| [`Num.div_trunc`](#numdiv_trunc) | The quotient rounded toward zero. |
| [`Num.div_ceil`](#numdiv_ceil) | The quotient rounded up. |
| [`Num.rem`](#numrem) | The remainder of the truncated division, with the sign of `first`. |
| [`Num.pow_int`](#numpow_int) | `base` raised to a non-negative `exponent`, as an integer. |
| [`Num.sqrt`](#numsqrt) | The square root. |
| [`Num.log`](#numlog) | The natural logarithm. |
| [`Num.asin`](#numasin) | The arcsine in radians. |
| [`Num.acos`](#numacos) | The arccosine in radians. |
| [`Num.is_nan`](#numis_nan) | Whether the number is `NaN`. |
| [`Num.bitwise_and`](#numbitwise_and) | The bits set in both integers, in 32-bit two's complement. |
| [`Num.bitwise_or`](#numbitwise_or) | The bits set in either integer. |
| [`Num.bitwise_xor`](#numbitwise_xor) | The bits set in exactly one of the integers. |
| [`Num.bitwise_not`](#numbitwise_not) | The integer with every bit flipped, which is `-number - 1`. |
| [`Num.shift_left_by`](#numshift_left_by) | Shifts the bits left by `bits`, from 0 to 31. |
| [`Num.shift_right_by`](#numshift_right_by) | Shifts the bits right by `bits`, copying the sign bit in, so a negative number stays negative. |
| [`Num.shift_right_zf_by`](#numshift_right_zf_by) | Shifts the bits right by `bits`, filling with zeros. |
| [`Num.count_one_bits`](#numcount_one_bits) | The number of set bits. |
| [`Num.count_leading_zero_bits`](#numcount_leading_zero_bits) | The number of zero bits above the highest set bit, 32 for zero. |
| [`Num.count_trailing_zero_bits`](#numcount_trailing_zero_bits) | The number of zero bits below the lowest set bit, 32 for zero. |
| [`Num.pi`](#numpi) | The ratio of a circle's circumference to its diameter. |
| [`Num.tau`](#numtau) | The ratio of a circle's circumference to its radius, `2 * Num.pi`. |
| [`Num.e`](#nume) | Euler's number, the base of the natural logarithm. |
| [`Num.max_integer`](#nummax_integer) | The largest integer, `2147483647L`. |
| [`Num.min_integer`](#nummin_integer) | The smallest integer, `-2147483647L`. |
| [`Num.max_double`](#nummax_double) | The largest finite double. |
| [`Num.min_double`](#nummin_double) | The most negative finite double, the negation of `Num.max_double`. |
| [`Num.infinity`](#numinfinity) | Positive infinity, R's `Inf`. |

## `Num.to_str`

### Inline

```r
Num.to_str <- function<T: scalar numeric>(number: T) -> character
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> character
Num.to_str <- function(number)
```

The number as text, with up to 15 significant digits.

```r
Num.to_str(1 / 3)
#> "0.333333333333333"
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1128)

## `Num.compare`

### Inline

```r
Num.compare <- function<T: scalar numeric>(first: T, second: T) -> :LT | :EQ | :GT
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> :LT | :EQ | :GT
Num.compare <- function(first, second)
```

`:LT`, `:EQ` or `:GT`, comparing `first` with `second`.

```r
Num.compare(2L, 1L)
#> :GT
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1136)

## `Num.min`

### Inline

```r
Num.min <- function<T: scalar numeric>(first: T, second: T) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> T
Num.min <- function(first, second)
```

The smaller number.

```r
Num.min(2L, 1L)
#> 1L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1144)

## `Num.max`

### Inline

```r
Num.max <- function<T: scalar numeric>(first: T, second: T) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> T
Num.max <- function(first, second)
```

The larger number.

```r
Num.max(2.5, 1)
#> 2.5
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1152)

## `Num.is_lt`

### Inline

```r
Num.is_lt <- function<T: scalar numeric>(first: T, second: T) -> logical
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> logical
Num.is_lt <- function(first, second)
```

Whether `first < second`.

```r
Num.is_lt(1L, 2L)
#> TRUE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1160)

## `Num.is_gt`

### Inline

```r
Num.is_gt <- function<T: scalar numeric>(first: T, second: T) -> logical
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> logical
Num.is_gt <- function(first, second)
```

Whether `first > second`.

```r
Num.is_gt(1L, 2L)
#> FALSE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1168)

## `Num.is_lte`

### Inline

```r
Num.is_lte <- function<T: scalar numeric>(first: T, second: T) -> logical
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> logical
Num.is_lte <- function(first, second)
```

Whether `first <= second`.

```r
Num.is_lte(2, 2L)
#> TRUE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1176)

## `Num.is_gte`

### Inline

```r
Num.is_gte <- function<T: scalar numeric>(first: T, second: T) -> logical
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> logical
Num.is_gte <- function(first, second)
```

Whether `first >= second`.

```r
Num.is_gte(1.5, 2)
#> FALSE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1184)

## `Num.is_approx_eq`

```r
#: <T: scalar numeric> fn(first: T, second: T, [rtol]: double, [atol]: double) -> logical
Num.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`).

```r
Num.is_approx_eq(0.1 + 0.2, 0.3)
#> TRUE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1193)

## `Num.is_zero`

### Inline

```r
Num.is_zero <- function<T: scalar numeric>(number: T) -> logical
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> logical
Num.is_zero <- function(number)
```

Whether the number is zero.

```r
Num.is_zero(-0)
#> TRUE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1201)

## `Num.is_positive`

### Inline

```r
Num.is_positive <- function<T: scalar numeric>(number: T) -> logical
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> logical
Num.is_positive <- function(number)
```

Whether the number is greater than zero.

```r
Num.is_positive(0L)
#> FALSE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1209)

## `Num.is_negative`

### Inline

```r
Num.is_negative <- function<T: scalar numeric>(number: T) -> logical
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> logical
Num.is_negative <- function(number)
```

Whether the number is less than zero.

```r
Num.is_negative(-1)
#> TRUE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1217)

## `Num.is_even`

### Inline

```r
Num.is_even <- function<T: scalar numeric>(number: T) -> logical
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> logical
Num.is_even <- function(number)
```

Whether the number is a whole, even number.

```r
Num.is_even(4L)
#> TRUE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1225)

## `Num.is_odd`

### Inline

```r
Num.is_odd <- function<T: scalar numeric>(number: T) -> logical
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> logical
Num.is_odd <- function(number)
```

Whether the number is a whole, odd number.

```r
Num.is_odd(-3L)
#> TRUE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1233)

## `Num.is_multiple_of`

### Inline

```r
Num.is_multiple_of <- function<T: scalar numeric>(first: T, second: T) -> logical
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> logical
Num.is_multiple_of <- function(first, second)
```

Whether `first` is a whole multiple of `second`. Only zero is a multiple of zero.

```r
Num.is_multiple_of(12L, 4L)
#> TRUE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1241)

## `Num.is_finite`

### Inline

```r
Num.is_finite <- function<T: scalar numeric>(number: T) -> logical
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> logical
Num.is_finite <- function(number)
```

Whether the number is neither infinite nor `NaN`.

```r
Num.is_finite(1 / 0)
#> FALSE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1249)

## `Num.is_infinite`

### Inline

```r
Num.is_infinite <- function<T: scalar numeric>(number: T) -> logical
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> logical
Num.is_infinite <- function(number)
```

Whether the number is `Inf` or `-Inf`.

```r
Num.is_infinite(-1 / 0)
#> TRUE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1257)

## `Num.abs`

### Inline

```r
Num.abs <- function<T: scalar numeric>(number: T) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> T
Num.abs <- function(number)
```

The absolute value.

```r
Num.abs(-3L)
#> 3L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1265)

## `Num.abs_diff`

### Inline

```r
Num.abs_diff <- function<T: scalar numeric>(first: T, second: T) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> T
Num.abs_diff <- function(first, second)
```

The absolute difference of two numbers. An integer result that overflows is an error.

```r
Num.abs_diff(3L, 10L)
#> 7L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1273)

## `Num.neg`

### Inline

```r
Num.neg <- function<T: scalar numeric>(number: T) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> T
Num.neg <- function(number)
```

The number with its sign flipped.

```r
Num.neg(2.5)
#> -2.5
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1281)

## `Num.ceiling`

### Inline

```r
Num.ceiling <- function<T: scalar numeric>(number: T) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> T
Num.ceiling <- function(number)
```

Rounds up to a whole number, keeping the number type.

```r
Num.ceiling(1.2)
#> 2
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1289)

## `Num.floor`

### Inline

```r
Num.floor <- function<T: scalar numeric>(number: T) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> T
Num.floor <- function(number)
```

Rounds down to a whole number, keeping the number type.

```r
Num.floor(-1.2)
#> -2
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1297)

## `Num.round`

### Inline

```r
Num.round <- function<T: scalar numeric>(number: T) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> T
Num.round <- function(number)
```

Rounds to the nearest whole number, halves away from zero, keeping the number type.

```r
Num.round(2.5)
#> 3
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1305)

## `Num.pow`

### Inline

```r
Num.pow <- function<T: scalar numeric>(base: T, exponent: T) -> double
```

### Comments

```r
#: <T: scalar numeric> fn(base: T, exponent: T) -> double
Num.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.

```r
Num.pow(2L, 10L)
#> 1024
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1314)

## `Num.sin`

### Inline

```r
Num.sin <- function<T: scalar numeric>(number: T) -> double
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> double
Num.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`.

```r
Num.sin(0)
#> 0
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1323)

## `Num.cos`

### Inline

```r
Num.cos <- function<T: scalar numeric>(number: T) -> double
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> double
Num.cos <- function(number)
```

The cosine of an angle in radians.

```r
Num.cos(0)
#> 1
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1331)

## `Num.tan`

### Inline

```r
Num.tan <- function<T: scalar numeric>(number: T) -> double
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> double
Num.tan <- function(number)
```

The tangent of an angle in radians.

```r
Num.tan(0)
#> 0
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1339)

## `Num.atan`

### Inline

```r
Num.atan <- function<T: scalar numeric>(number: T) -> double
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> double
Num.atan <- function(number)
```

The arctangent, in radians.

```r
Num.atan(1) * 4
#> 3.14159265358979
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1347)

## `Num.add_checked`

### Inline

```r
Num.add_checked <- function<T: scalar numeric>(first: T, second: T) -> Result<T, :Overflow | :Undefined>
```

### Comments

```r
#: <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)`.

```r
Num.add_checked(.Machine$integer.max, 1L)
#> :Err(:Overflow)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1355)

## `Num.sub_checked`

### Inline

```r
Num.sub_checked <- function<T: scalar numeric>(first: T, second: T) -> Result<T, :Overflow | :Undefined>
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> Result<T, :Overflow | :Undefined>
Num.sub_checked <- function(first, second)
```

The difference, or `:Err(:Overflow)`.

```r
Num.sub_checked(10L, 3L)
#> :Ok(7L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1363)

## `Num.mul_checked`

### Inline

```r
Num.mul_checked <- function<T: scalar numeric>(first: T, second: T) -> Result<T, :Overflow | :Undefined>
```

### Comments

```r
#: <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.

```r
Num.mul_checked(1e308, 10)
#> :Err(:Overflow)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1371)

## `Num.add_saturated`

### Inline

```r
Num.add_saturated <- function<T: scalar numeric>(first: T, second: T) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> T
Num.add_saturated <- function(first, second)
```

Adds two numbers, clamping an integer result to the largest or smallest integer.

```r
Num.add_saturated(2147483647L, 1L)
#> 2147483647L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1379)

## `Num.sub_saturated`

### Inline

```r
Num.sub_saturated <- function<T: scalar numeric>(first: T, second: T) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> T
Num.sub_saturated <- function(first, second)
```

Subtracts `second` from `first`, clamping an integer result.

```r
Num.sub_saturated(-2147483647L, 1L)
#> -2147483647L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1387)

## `Num.mul_saturated`

### Inline

```r
Num.mul_saturated <- function<T: scalar numeric>(first: T, second: T) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> T
Num.mul_saturated <- function(first, second)
```

Multiplies two numbers, clamping an integer result.

```r
Num.mul_saturated(100000L, 100000L)
#> 2147483647L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1395)

## `Num.div_checked`

### Inline

```r
Num.div_checked <- function<T: scalar numeric>(first: T, second: T) -> Result<double, :DivByZero | :Undefined>
```

### Comments

```r
#: <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)`.

```r
Num.div_checked(7L, 2L)
#> :Ok(3.5)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1403)

## `Num.div_trunc_checked`

### Inline

```r
Num.div_trunc_checked <- function<T: scalar numeric>(first: T, second: T) -> Result<T, :DivByZero | :Undefined>
```

### Comments

```r
#: <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)`.

```r
Num.div_trunc_checked(-7L, 2L)
#> :Ok(-3L)
Num.div_trunc_checked(Inf, Inf)
#> :Err(:Undefined)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1414)

## `Num.div_ceil_checked`

### Inline

```r
Num.div_ceil_checked <- function<T: scalar numeric>(first: T, second: T) -> Result<T, :DivByZero | :Undefined>
```

### Comments

```r
#: <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)`.

```r
Num.div_ceil_checked(7L, 2L)
#> :Ok(4L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1422)

## `Num.rem_checked`

### Inline

```r
Num.rem_checked <- function<T: scalar numeric>(first: T, second: T) -> Result<T, :DivByZero | :Undefined>
```

### Comments

```r
#: <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)`.

```r
Num.rem_checked(-7L, 2L)
#> :Ok(-1L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1430)

## `Num.sqrt_checked`

### Inline

```r
Num.sqrt_checked <- function<T: scalar numeric>(number: T) -> Result<double, :SqrtOfNegative>
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> Result<double, :SqrtOfNegative>
Num.sqrt_checked <- function(number)
```

The square root, or `:Err(:SqrtOfNegative)`.

```r
Num.sqrt_checked(-1)
#> :Err(:SqrtOfNegative)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1438)

## `Num.log_checked`

### Inline

```r
Num.log_checked <- function<T: scalar numeric>(number: T) -> Result<double, :LogNeedsPositive>
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> Result<double, :LogNeedsPositive>
Num.log_checked <- function(number)
```

The natural logarithm, or `:Err(:LogNeedsPositive)`.

```r
Num.log_checked(exp(2))
#> :Ok(2)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1446)

## `Num.to_double`

### Inline

```r
Num.to_double <- function<T: scalar numeric>(number: T) -> double
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> double
Num.to_double <- function(number)
```

The number as a double.

```r
Num.to_double(3L)
#> 3
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1454)

## `Num.to_integer_checked`

### Inline

```r
Num.to_integer_checked <- function<T: scalar numeric>(number: T) -> Result<integer, :OutOfBounds>
```

### Comments

```r
#: <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.

```r
Num.to_integer_checked(-3.7)
#> :Ok(-3L)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1462)

## `Num.to_integer`

### Inline

```r
Num.to_integer <- function<T: scalar numeric>(number: T) -> integer
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> integer
Num.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.

```r
Num.to_integer(-3.7)
#> -3L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1471)

## `Num.add`

### Inline

```r
Num.add <- function<T: scalar numeric>(first: T, second: T) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> T
Num.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.

```r
List.walk(list(1L, 2L, 3L), 0L, Num.add)
#> 6L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1480)

## `Num.sub`

### Inline

```r
Num.sub <- function<T: scalar numeric>(first: T, second: T) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> T
Num.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`.

```r
Num.sub(10L, 4L)
#> 6L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1489)

## `Num.mul`

### Inline

```r
Num.mul <- function<T: scalar numeric>(first: T, second: T) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> T
Num.mul <- function(first, second)
```

The product. An `integer` product that overflows is an error.

```r
Num.mul(6L, 7L)
#> 42L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1497)

## `Num.div`

### Inline

```r
Num.div <- function<T: scalar numeric>(first: T, second: T) -> double
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> double
Num.div <- function(first, second)
```

The quotient as a double. A zero divisor is an error; `Num.div_checked` returns
`:Err(:DivByZero)` instead.

```r
Num.div(7L, 2L)
#> 3.5
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1506)

## `Num.div_trunc`

### Inline

```r
Num.div_trunc <- function<T: scalar numeric>(first: T, second: T) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> T
Num.div_trunc <- function(first, second)
```

The quotient rounded toward zero. A zero divisor is an error.

```r
Num.div_trunc(-7L, 2L)
#> -3L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1514)

## `Num.div_ceil`

### Inline

```r
Num.div_ceil <- function<T: scalar numeric>(first: T, second: T) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> T
Num.div_ceil <- function(first, second)
```

The quotient rounded up. A zero divisor is an error.

```r
Num.div_ceil(7L, 2L)
#> 4L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1522)

## `Num.rem`

### Inline

```r
Num.rem <- function<T: scalar numeric>(first: T, second: T) -> T
```

### Comments

```r
#: <T: scalar numeric> fn(first: T, second: T) -> T
Num.rem <- function(first, second)
```

The remainder of the truncated division, with the sign of `first`. A zero divisor is an error.

```r
Num.rem(-7L, 2L)
#> -1L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1530)

## `Num.pow_int`

### Inline

```r
Num.pow_int <- function(base: integer, exponent: integer) -> integer
```

### Comments

```r
#: fn(base: integer, exponent: integer) -> integer
Num.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.

```r
Num.pow_int(3L, 4L)
#> 81L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1539)

## `Num.sqrt`

### Inline

```r
Num.sqrt <- function<T: scalar numeric>(number: T) -> double
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> double
Num.sqrt <- function(number)
```

The square root. A negative number is an error; `Num.sqrt_checked` returns
`:Err(:SqrtOfNegative)` instead.

```r
Num.sqrt(16L)
#> 4
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1548)

## `Num.log`

### Inline

```r
Num.log <- function<T: scalar numeric>(number: T) -> double
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> double
Num.log <- function(number)
```

The natural logarithm. A number that is not positive is an error; `Num.log_checked` returns
`:Err(:LogNeedsPositive)` instead.

```r
Num.log(Num.e)
#> 1
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1557)

## `Num.asin`

### Inline

```r
Num.asin <- function<T: scalar numeric>(number: T) -> double
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> double
Num.asin <- function(number)
```

The arcsine in radians. A number outside -1 to 1 is an error.

```r
Num.asin(1)
#> 1.5707963267949
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1565)

## `Num.acos`

### Inline

```r
Num.acos <- function<T: scalar numeric>(number: T) -> double
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> double
Num.acos <- function(number)
```

The arccosine in radians. A number outside -1 to 1 is an error.

```r
Num.acos(1)
#> 0
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1573)

## `Num.is_nan`

### Inline

```r
Num.is_nan <- function<T: scalar numeric>(number: T) -> logical
```

### Comments

```r
#: <T: scalar numeric> fn(number: T) -> logical
Num.is_nan <- function(number)
```

Whether the number is `NaN`. It is the one library function that accepts `NaN`; `NA` is still an
error.

```r
Num.is_nan(0 / 0)
#> TRUE
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1582)

## `Num.bitwise_and`

### Inline

```r
Num.bitwise_and <- function(first: integer, second: integer) -> integer
```

### Comments

```r
#: fn(first: integer, second: integer) -> integer
Num.bitwise_and <- function(first, second)
```

The bits set in both integers, in 32-bit two's complement.

```r
Num.bitwise_and(12L, 10L)
#> 8L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1590)

## `Num.bitwise_or`

### Inline

```r
Num.bitwise_or <- function(first: integer, second: integer) -> integer
```

### Comments

```r
#: fn(first: integer, second: integer) -> integer
Num.bitwise_or <- function(first, second)
```

The bits set in either integer.

```r
Num.bitwise_or(12L, 10L)
#> 14L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1598)

## `Num.bitwise_xor`

### Inline

```r
Num.bitwise_xor <- function(first: integer, second: integer) -> integer
```

### Comments

```r
#: fn(first: integer, second: integer) -> integer
Num.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.

```r
Num.bitwise_xor(12L, 10L)
#> 6L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1607)

## `Num.bitwise_not`

### Inline

```r
Num.bitwise_not <- function(number: integer) -> integer
```

### Comments

```r
#: fn(number: integer) -> integer
Num.bitwise_not <- function(number)
```

The integer with every bit flipped, which is `-number - 1`.

```r
Num.bitwise_not(5L)
#> -6L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1615)

## `Num.shift_left_by`

### Inline

```r
Num.shift_left_by <- function(number: integer, bits: integer) -> integer
```

### Comments

```r
#: fn(number: integer, bits: integer) -> integer
Num.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.

```r
Num.shift_left_by(1L, 4L)
#> 16L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1623)

## `Num.shift_right_by`

### Inline

```r
Num.shift_right_by <- function(number: integer, bits: integer) -> integer
```

### Comments

```r
#: fn(number: integer, bits: integer) -> integer
Num.shift_right_by <- function(number, bits)
```

Shifts the bits right by `bits`, copying the sign bit in, so a negative number stays negative.

```r
Num.shift_right_by(-16L, 2L)
#> -4L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1631)

## `Num.shift_right_zf_by`

### Inline

```r
Num.shift_right_zf_by <- function(number: integer, bits: integer) -> integer
```

### Comments

```r
#: fn(number: integer, bits: integer) -> integer
Num.shift_right_zf_by <- function(number, bits)
```

Shifts the bits right by `bits`, filling with zeros.

```r
Num.shift_right_zf_by(-16L, 28L)
#> 15L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1639)

## `Num.count_one_bits`

### Inline

```r
Num.count_one_bits <- function(number: integer) -> integer
```

### Comments

```r
#: fn(number: integer) -> integer
Num.count_one_bits <- function(number)
```

The number of set bits.

```r
Num.count_one_bits(255L)
#> 8L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1647)

## `Num.count_leading_zero_bits`

### Inline

```r
Num.count_leading_zero_bits <- function(number: integer) -> integer
```

### Comments

```r
#: fn(number: integer) -> integer
Num.count_leading_zero_bits <- function(number)
```

The number of zero bits above the highest set bit, 32 for zero.

```r
Num.count_leading_zero_bits(1L)
#> 31L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1655)

## `Num.count_trailing_zero_bits`

### Inline

```r
Num.count_trailing_zero_bits <- function(number: integer) -> integer
```

### Comments

```r
#: fn(number: integer) -> integer
Num.count_trailing_zero_bits <- function(number)
```

The number of zero bits below the lowest set bit, 32 for zero.

```r
Num.count_trailing_zero_bits(8L)
#> 3L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1663)

## `Num.pi`

```r
#: double
Num.pi
```

The ratio of a circle's circumference to its diameter. It is a value, not a function.

```r
Num.pi
#> 3.14159265358979
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1671)

## `Num.tau`

```r
#: double
Num.tau
```

The ratio of a circle's circumference to its radius, `2 * Num.pi`.

```r
Num.tau
#> 6.28318530717959
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1679)

## `Num.e`

```r
#: double
Num.e
```

Euler's number, the base of the natural logarithm.

```r
Num.e
#> 2.71828182845905
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1687)

## `Num.max_integer`

```r
#: integer
Num.max_integer
```

The largest integer, `2147483647L`. It is a value, not a function.

```r
Num.max_integer
#> 2147483647L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1695)

## `Num.min_integer`

```r
#: integer
Num.min_integer
```

The smallest integer, `-2147483647L`. R stores `NA` in the one value below it, so that value is
not an integer here.

```r
Num.min_integer
#> -2147483647L
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1704)

## `Num.max_double`

```r
#: double
Num.max_double
```

The largest finite double.

```r
Num.max_double
#> 1.79769313486232e+308
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1712)

## `Num.min_double`

```r
#: double
Num.min_double
```

The most negative finite double, the negation of `Num.max_double`.

```r
Num.min_double
#> -1.79769313486232e+308
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1720)

## `Num.infinity`

```r
#: double
Num.infinity
```

Positive infinity, R's `Inf`.

```r
c(Num.infinity, -Num.infinity)
#> c(Inf, -Inf)
```

[Source](https://github.com/felix-andreas/ry/blob/main/types/std.Rtypes#L1728)
