# 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 work on an `I64`'s 64-bit two's complement, and on an R number's
32 bits when no argument is an `I64`.

| 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, as an `I64`. |
| [`Num.round`](#numround) | Rounds to the nearest whole number, halves away from zero, as an `I64`. |
| [`Num.truncate`](#numtruncate) | Drops the fraction, rounding toward zero, as an `I64`. |
| [`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.add_wrap`](#numadd_wrap) | Adds two integers, wrapping around on overflow as two's complement arithmetic does. |
| [`Num.sub_wrap`](#numsub_wrap) | Subtracts `second` from `first`, wrapping around on overflow. |
| [`Num.mul_wrap`](#nummul_wrap) | Multiplies two integers, wrapping around on overflow. |
| [`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.from_r`](#numfrom_r) | Converts an R number into a ry number, refusing `NA` and a length other than one: a `double` becomes an `F64` and an `integer` an `I64`. |
| [`Num.to_r`](#numto_r) | Converts a ry number into an R number: an `F64` becomes a `double`, and an `I64` an `integer` when it fits in 32 bits and a `double` otherwise. |
| [`Num.to_f64`](#numto_f64) | The number as an `F64`. |
| [`Num.to_i64_checked`](#numto_i64_checked) | The number as an `I64`, or `:Err(:OutOfBounds)` when an `I64` cannot hold it exactly, such as a number with a fraction. |
| [`Num.to_i64`](#numto_i64) | The number as an `I64`. |
| [`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.exp`](#numexp) | The number e raised to `number`: the exponential function, which is the inverse of `Num.log`. |
| [`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. |
| [`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 63 for an `I64` and from 0 to 31 for an R number. |
| [`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_i64`](#nummax_i64) | The largest `I64`, `9223372036854775807i64`. |
| [`Num.min_i64`](#nummin_i64) | The smallest `I64`, `-9223372036854775808i64`. |
| [`Num.max_f64`](#nummax_f64) | The largest finite double. |
| [`Num.min_f64`](#nummin_f64) | The most negative finite double, the negation of `Num.max_f64`. |
| [`Num.infinity_f64`](#numinfinity_f64) | Positive infinity, R's `Inf`. |
| [`Num.nan_f64`](#numnan_f64) | Not a number, the `F64` that arithmetic such as `0 / 0` produces. |

## `Num.to_str`

### Inline

```r
Num.to_str <- function<T: number>(number: T) -> Str
```

### Comments

```r
#: <T: number> fn(number: T) -> Str
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#L1073)

## `Num.compare`

### Inline

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

### Comments

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

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

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

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

## `Num.min`

### Inline

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

### Comments

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

The smaller number.

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

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

## `Num.max`

### Inline

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

### Comments

```r
#: <T: number> 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#L1097)

## `Num.is_lt`

### Inline

```r
Num.is_lt <- function<T: number>(first: T, second: T) -> Bool
```

### Comments

```r
#: <T: number> fn(first: T, second: T) -> Bool
Num.is_lt <- function(first, second)
```

Whether `first < second`.

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

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

## `Num.is_gt`

### Inline

```r
Num.is_gt <- function<T: number>(first: T, second: T) -> Bool
```

### Comments

```r
#: <T: number> fn(first: T, second: T) -> Bool
Num.is_gt <- function(first, second)
```

Whether `first > second`.

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

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

## `Num.is_lte`

### Inline

```r
Num.is_lte <- function<T: number>(first: T, second: T) -> Bool
```

### Comments

```r
#: <T: number> fn(first: T, second: T) -> Bool
Num.is_lte <- function(first, second)
```

Whether `first <= second`.

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

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

## `Num.is_gte`

### Inline

```r
Num.is_gte <- function<T: number>(first: T, second: T) -> Bool
```

### Comments

```r
#: <T: number> fn(first: T, second: T) -> Bool
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#L1129)

## `Num.is_approx_eq`

```r
#: fn(first: F64, second: F64, [rtol]: F64, [atol]: F64) -> Bool
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#L1138)

## `Num.is_zero`

### Inline

```r
Num.is_zero <- function<T: number>(number: T) -> Bool
```

### Comments

```r
#: <T: number> fn(number: T) -> Bool
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#L1146)

## `Num.is_positive`

### Inline

```r
Num.is_positive <- function<T: number>(number: T) -> Bool
```

### Comments

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

Whether the number is greater than zero.

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

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

## `Num.is_negative`

### Inline

```r
Num.is_negative <- function<T: number>(number: T) -> Bool
```

### Comments

```r
#: <T: number> fn(number: T) -> Bool
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#L1162)

## `Num.is_even`

### Inline

```r
Num.is_even <- function(number: I64) -> Bool
```

### Comments

```r
#: fn(number: I64) -> Bool
Num.is_even <- function(number)
```

Whether the number is a whole, even number.

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

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

## `Num.is_odd`

### Inline

```r
Num.is_odd <- function(number: I64) -> Bool
```

### Comments

```r
#: fn(number: I64) -> Bool
Num.is_odd <- function(number)
```

Whether the number is a whole, odd number.

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

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

## `Num.is_multiple_of`

### Inline

```r
Num.is_multiple_of <- function(first: I64, second: I64) -> Bool
```

### Comments

```r
#: fn(first: I64, second: I64) -> Bool
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(12, 4)
#> TRUE
```

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

## `Num.is_finite`

### Inline

```r
Num.is_finite <- function(number: F64) -> Bool
```

### Comments

```r
#: fn(number: F64) -> Bool
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#L1194)

## `Num.is_infinite`

### Inline

```r
Num.is_infinite <- function(number: F64) -> Bool
```

### Comments

```r
#: fn(number: F64) -> Bool
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#L1202)

## `Num.abs`

### Inline

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

### Comments

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

The absolute value.

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

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

## `Num.abs_diff`

### Inline

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

### Comments

```r
#: <T: number> 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(3, 10)
#> 7i64
```

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

## `Num.neg`

### Inline

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

### Comments

```r
#: <T: number> 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#L1226)

## `Num.ceiling`

### Inline

```r
Num.ceiling <- function(number: F64) -> I64
```

### Comments

```r
#: fn(number: F64) -> I64
Num.ceiling <- function(number)
```

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

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

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

## `Num.floor`

### Inline

```r
Num.floor <- function(number: F64) -> I64
```

### Comments

```r
#: fn(number: F64) -> I64
Num.floor <- function(number)
```

Rounds down to a whole number, as an `I64`.

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

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

## `Num.round`

### Inline

```r
Num.round <- function(number: F64) -> I64
```

### Comments

```r
#: fn(number: F64) -> I64
Num.round <- function(number)
```

Rounds to the nearest whole number, halves away from zero, as an `I64`.

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

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

## `Num.truncate`

### Inline

```r
Num.truncate <- function(number: F64) -> I64
```

### Comments

```r
#: fn(number: F64) -> I64
Num.truncate <- function(number)
```

Drops the fraction, rounding toward zero, as an `I64`.

```r
Num.truncate(-1.7)
#> -1i64
```

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

## `Num.pow`

### Inline

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

### Comments

```r
#: <T: number> fn(base: T, exponent: T) -> T
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(2, 10)
#> 1024i64
```

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

## `Num.sin`

### Inline

```r
Num.sin <- function(number: F64) -> F64
```

### Comments

```r
#: fn(number: F64) -> F64
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#L1276)

## `Num.cos`

### Inline

```r
Num.cos <- function(number: F64) -> F64
```

### Comments

```r
#: fn(number: F64) -> F64
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#L1284)

## `Num.tan`

### Inline

```r
Num.tan <- function(number: F64) -> F64
```

### Comments

```r
#: fn(number: F64) -> F64
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#L1292)

## `Num.atan`

### Inline

```r
Num.atan <- function(number: F64) -> F64
```

### Comments

```r
#: fn(number: F64) -> F64
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#L1300)

## `Num.add_checked`

### Inline

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

### Comments

```r
#: <T: number> 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(9223372036854775807i64, 1i64)
#> :Err(:Overflow)
```

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

## `Num.sub_checked`

### Inline

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

### Comments

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

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

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

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

## `Num.mul_checked`

### Inline

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

### Comments

```r
#: <T: number> 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#L1324)

## `Num.add_saturated`

### Inline

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

### Comments

```r
#: <T: number> 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(9223372036854775807i64, 1i64)
#> 9223372036854775807i64
```

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

## `Num.sub_saturated`

### Inline

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

### Comments

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

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

```r
Num.sub_saturated(-9223372036854775807i64, 2i64)
#> -9223372036854775808i64
```

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

## `Num.mul_saturated`

### Inline

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

### Comments

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

Multiplies two numbers, clamping an integer result.

```r
Num.mul_saturated(4294967296i64, 4294967296i64)
#> 9223372036854775807i64
```

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

## `Num.add_wrap`

### Inline

```r
Num.add_wrap <- function(first: I64, second: I64) -> I64
```

### Comments

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

Adds two integers, wrapping around on overflow as two's complement arithmetic does.

```r
Num.add_wrap(9223372036854775807i64, 1i64)
#> -9223372036854775808i64
```

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

## `Num.sub_wrap`

### Inline

```r
Num.sub_wrap <- function(first: I64, second: I64) -> I64
```

### Comments

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

Subtracts `second` from `first`, wrapping around on overflow.

```r
Num.sub_wrap(-9223372036854775808i64, 1i64)
#> 9223372036854775807i64
```

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

## `Num.mul_wrap`

### Inline

```r
Num.mul_wrap <- function(first: I64, second: I64) -> I64
```

### Comments

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

Multiplies two integers, wrapping around on overflow.

```r
Num.mul_wrap(4294967296i64, 4294967296i64)
#> 0i64
```

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

## `Num.div_checked`

### Inline

```r
Num.div_checked <- function(first: F64, second: F64) -> Result<F64, :DivByZero | :Undefined>
```

### Comments

```r
#: fn(first: F64, second: F64) -> Result<F64, :DivByZero | :Undefined>
Num.div_checked <- function(first, second)
```

The quotient as a double, or `:Err(:DivByZero)`.

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

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

## `Num.div_trunc_checked`

### Inline

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

### Comments

```r
#: fn(first: I64, second: I64) -> Result<I64, :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(-7, 2)
#> :Ok(-3i64)
Num.div_trunc_checked(Inf, Inf)
#> :Err(:Undefined)
```

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

## `Num.div_ceil_checked`

### Inline

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

### Comments

```r
#: fn(first: I64, second: I64) -> Result<I64, :DivByZero | :Undefined>
Num.div_ceil_checked <- function(first, second)
```

Divides and rounds up, or `:Err(:DivByZero)`.

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

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

## `Num.rem_checked`

### Inline

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

### Comments

```r
#: fn(first: I64, second: I64) -> Result<I64, :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(-7, 2)
#> :Ok(-1i64)
```

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

## `Num.sqrt_checked`

### Inline

```r
Num.sqrt_checked <- function(number: F64) -> Result<F64, :SqrtOfNegative>
```

### Comments

```r
#: fn(number: F64) -> Result<F64, :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#L1415)

## `Num.log_checked`

### Inline

```r
Num.log_checked <- function(number: F64) -> Result<F64, :LogNeedsPositive>
```

### Comments

```r
#: fn(number: F64) -> Result<F64, :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#L1423)

## `Num.from_r`

### Inline

```r
Num.from_r <- function(value: integer) -> I64
Num.from_r <- function(value: double) -> F64
```

### Comments

```r
#: fn(value: integer) -> I64
Num.from_r <- function(value)

#: fn(value: double) -> F64
Num.from_r <- function(value)
```

Converts an R number into a ry number, refusing `NA` and a length other than one: a `double`
becomes an `F64` and an `integer` an `I64`.

```r
Num.from_r(2.5)
#> 2.5
```

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

## `Num.to_r`

### Inline

```r
Num.to_r <- function<T: number>(number: T) -> integer | double
```

### Comments

```r
#: <T: number> fn(number: T) -> integer | double
Num.to_r <- function(number)
```

Converts a ry number into an R number: an `F64` becomes a `double`, and an `I64` an `integer`
when it fits in 32 bits and a `double` otherwise. An `F64` already passes to R code
as a `double` without this call.

```r
Num.to_r(5i64)
#> 5L
```

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

## `Num.to_f64`

### Inline

```r
Num.to_f64 <- function<T: number>(number: T) -> F64
```

### Comments

```r
#: <T: number> fn(number: T) -> F64
Num.to_f64 <- function(number)
```

The number as an `F64`. An integer past 2^53 rounds to the nearest `F64`.

```r
Num.to_f64(3i64)
#> 3
```

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

## `Num.to_i64_checked`

### Inline

```r
Num.to_i64_checked <- function<T: number>(number: T) -> Result<I64, :OutOfBounds>
```

### Comments

```r
#: <T: number> fn(number: T) -> Result<I64, :OutOfBounds>
Num.to_i64_checked <- function(number)
```

The number as an `I64`, or `:Err(:OutOfBounds)` when an `I64` cannot hold it exactly, such as
a number with a fraction. `Num.truncate` drops a fraction first.

```r
Num.to_i64_checked(-3.7)
#> :Err(:OutOfBounds)
```

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

## `Num.to_i64`

### Inline

```r
Num.to_i64 <- function<T: number>(number: T) -> I64
```

### Comments

```r
#: <T: number> fn(number: T) -> I64
Num.to_i64 <- function(number)
```

The number as an `I64`. A number an `I64` cannot hold exactly is an
error; `Num.to_i64_checked` returns `:Err(:OutOfBounds)` instead.

```r
Num.to_i64(-3.0)
#> -3i64
```

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

## `Num.add`

### Inline

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

### Comments

```r
#: <T: number> 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([1, 2, 3], 0, Num.add)
#> 6i64
```

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

## `Num.sub`

### Inline

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

### Comments

```r
#: <T: number> 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(10, 4)
#> 6i64
```

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

## `Num.mul`

### Inline

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

### Comments

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

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

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

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

## `Num.div`

### Inline

```r
Num.div <- function(first: F64, second: F64) -> F64
```

### Comments

```r
#: fn(first: F64, second: F64) -> F64
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(7, 2)
#> 3.5
```

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

## `Num.div_trunc`

### Inline

```r
Num.div_trunc <- function(first: I64, second: I64) -> I64
```

### Comments

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

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

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

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

## `Num.div_ceil`

### Inline

```r
Num.div_ceil <- function(first: I64, second: I64) -> I64
```

### Comments

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

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

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

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

## `Num.rem`

### Inline

```r
Num.rem <- function(first: I64, second: I64) -> I64
```

### Comments

```r
#: fn(first: I64, second: I64) -> I64
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(-7, 2)
#> -1i64
```

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

## `Num.pow_int`

### Inline

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

### Comments

```r
#: fn(base: I64, exponent: I64) -> I64
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(3, 4)
#> 81i64
```

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

## `Num.sqrt`

### Inline

```r
Num.sqrt <- function(number: F64) -> F64
```

### Comments

```r
#: fn(number: F64) -> F64
Num.sqrt <- function(number)
```

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

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

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

## `Num.log`

### Inline

```r
Num.log <- function(number: F64) -> F64
```

### Comments

```r
#: fn(number: F64) -> F64
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#L1555)

## `Num.exp`

### Inline

```r
Num.exp <- function(number: F64) -> F64
```

### Comments

```r
#: fn(number: F64) -> F64
Num.exp <- function(number)
```

The number e raised to `number`: the exponential function, which is the inverse of `Num.log`.

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

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

## `Num.asin`

### Inline

```r
Num.asin <- function(number: F64) -> F64
```

### Comments

```r
#: fn(number: F64) -> F64
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#L1571)

## `Num.acos`

### Inline

```r
Num.acos <- function(number: F64) -> F64
```

### Comments

```r
#: fn(number: F64) -> F64
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#L1579)

## `Num.is_nan`

### Inline

```r
Num.is_nan <- function(number: F64) -> Bool
```

### Comments

```r
#: fn(number: F64) -> Bool
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#L1588)

## `Num.bitwise_and`

### Inline

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

### Comments

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

The bits set in both integers.

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

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

## `Num.bitwise_or`

### Inline

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

### Comments

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

The bits set in either integer.

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

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

## `Num.bitwise_xor`

### Inline

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

### Comments

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

The bits set in exactly one of the integers. On R numbers, 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(12, 10)
#> 6i64
```

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

## `Num.bitwise_not`

### Inline

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

### Comments

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

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

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

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

## `Num.shift_left_by`

### Inline

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

### Comments

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

Shifts the bits left by `bits`, from 0 to 63 for an `I64` and from 0 to 31 for an R number.
Bits shifted past the top are lost, as in Roc.

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

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

## `Num.shift_right_by`

### Inline

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

### Comments

```r
#: fn(number: I64, bits: I64) -> I64
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(-16, 2)
#> -4i64
```

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

## `Num.shift_right_zf_by`

### Inline

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

### Comments

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

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

```r
Num.shift_right_zf_by(-16, 28)
#> 68719476735i64
```

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

## `Num.count_one_bits`

### Inline

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

### Comments

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

The number of set bits.

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

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

## `Num.count_leading_zero_bits`

### Inline

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

### Comments

```r
#: fn(number: I64) -> I64
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(1)
#> 31L
```

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

## `Num.count_trailing_zero_bits`

### Inline

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

### Comments

```r
#: fn(number: I64) -> I64
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(8)
#> 3L
```

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

## `Num.pi`

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

## `Num.tau`

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

## `Num.e`

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

## `Num.max_i64`

```r
#: I64
Num.max_i64
```

The largest `I64`, `9223372036854775807i64`. It is a value, not a function.

```r
Num.max_i64
#> 9223372036854775807i64
```

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

## `Num.min_i64`

```r
#: I64
Num.min_i64
```

The smallest `I64`, `-9223372036854775808i64`. It is a value, not a function.

```r
Num.min_i64
#> -9223372036854775808i64
```

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

## `Num.max_f64`

```r
#: F64
Num.max_f64
```

The largest finite double.

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

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

## `Num.min_f64`

```r
#: F64
Num.min_f64
```

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

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

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

## `Num.infinity_f64`

```r
#: F64
Num.infinity_f64
```

Positive infinity, R's `Inf`.

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

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

## `Num.nan_f64`

```r
#: F64
Num.nan_f64
```

Not a number, the `F64` that arithmetic such as `0 / 0` produces. It is not R's `NA`.

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