API reference Dodo 0.1.4

std/math

Public declarations, types, methods, and source contracts for std/math.

On this page

Library guide · API index and notation

This page is generated from the bundled library in this checkout. Signatures and adjacent source comments are reproduced below; the linked guide explains usage, storage, failures, and platform support.

import "std/math"

Names used in signatures

Unqualified names denote this package’s types (including other source files in the same package), language built-ins, or generic parameters such as T. Qualified names use the import aliases below. These aliases belong to the library source; import a dependency yourself to use its alias in your program.

Alias Package Source file
ptr core/ptr math.dodo

PI

Constant · Source

Portable binary64 values and arithmetic. Trigonometry and its reduction table are independently imported from std/math/trig. No allocation or OS imports.

pub const PI: f64 = 3.14159265358979323846264338327950288

TAU

Constant · Source

pub const TAU: f64 = 6.28318530717958647692528676655900576

E

Constant · Source

pub const E: f64 = 2.71828182845904523536028747135266250

LN_2

Constant · Source

pub const LN_2: f64 = 0.693147180559945309417232121458176568

LN_10

Constant · Source

pub const LN_10: f64 = 2.30258509299404568401799145468436421

EPSILON

Constant · Source

pub const EPSILON: f64 = 2.220446049250313080847263336181640625e-16

MIN_NORMAL

Constant · Source

pub const MIN_NORMAL: f64 = 2.2250738585072014e-308

MAX_FINITE

Constant · Source

pub const MAX_FINITE: f64 = 1.7976931348623157e308

I64_MAX

Constant · Source

pub const I64_MAX: i64 = 9223372036854775807

I64_MIN

Constant · Source

pub const I64_MIN: i64 = -9223372036854775807 - 1

U64_MAX

Constant · Source

pub const U64_MAX: u64 = 0xffffffffffffffff

MathError

Enum · Source

pub enum MathError {
    Overflow, DivisionByZero, Domain
}

Classification

Enum · Source

pub enum Classification {
    Zero, Subnormal, Normal, Infinite, Nan
}

to_bits

Function · Source

The target binary64 representation is IEEE 754. Unaligned accesses avoid an assumption that u64 and f64 have identical ABI alignment; byte order cancels.

pub fn to_bits(value: f64) -> u64

from_bits

Function · Source

pub fn from_bits(value: u64) -> f64

infinity

Function · Source

pub fn infinity() -> f64

nan

Function · Source

pub fn nan() -> f64

sign_bit

Function · Source

pub fn sign_bit(value: f64) -> bool

abs

Function · Source

pub fn abs(value: f64) -> f64

copy_sign

Function · Source

pub fn copy_sign(value: f64, sign: f64) -> f64

classify

Function · Source

pub fn classify(value: f64) -> Classification

is_nan

Function · Source

pub fn is_nan(value: f64) -> bool

is_infinite

Function · Source

pub fn is_infinite(value: f64) -> bool

is_finite

Function · Source

pub fn is_finite(value: f64) -> bool

is_normal

Function · Source

pub fn is_normal(value: f64) -> bool

is_subnormal

Function · Source

pub fn is_subnormal(value: f64) -> bool

checked_abs

Function · Source

pub fn checked_abs(value: i64) -> Result<i64, MathError>

unsigned_abs

Function · Source

Unlike checked_abs, the magnitude of the signed minimum fits in u64.

pub fn unsigned_abs(value: i64) -> u64

checked_add

Function · Source

pub fn checked_add(a: i64, b: i64) -> Result<i64, MathError>

checked_sub

Function · Source

pub fn checked_sub(a: i64, b: i64) -> Result<i64, MathError>

checked_mul

Function · Source

pub fn checked_mul(a: i64, b: i64) -> Result<i64, MathError>

checked_div

Function · Source

pub fn checked_div(a: i64, b: i64) -> Result<i64, MathError>

checked_rem

Function · Source

pub fn checked_rem(a: i64, b: i64) -> Result<i64, MathError>

checked_pow

Function · Source

pub fn checked_pow(base: i64, exponent: u32) -> Result<i64, MathError>

checked_pow_u64

Function · Source

pub fn checked_pow_u64(base: u64, exponent: u32) -> Result<u64, MathError>

gcd

Function · Source

Euclid’s algorithm; gcd(0,0)=0. lcm with a zero argument is zero.

pub fn gcd(a: u64, b: u64) -> u64

checked_lcm

Function · Source

pub fn checked_lcm(a: u64, b: u64) -> Result<u64, MathError>

isqrt

Function · Source

Restoring binary square root; exact floor(sqrt(n)), including U64_MAX.

pub fn isqrt(value: u64) -> u64

checked_next_power_of_two

Function · Source

pub fn checked_next_power_of_two(value: u64) -> Result<u64, MathError>

trunc

Function · Source

Exact integral rounding, independent of float-to-integer conversion ranges.

pub fn trunc(value: f64) -> f64

floor

Function · Source

pub fn floor(value: f64) -> f64

ceil

Function · Source

pub fn ceil(value: f64) -> f64

round

Function · Source

Nearest integer, ties away from zero. round_even uses ties to even.

pub fn round(value: f64) -> f64

round_even

Function · Source

pub fn round_even(value: f64) -> f64

scalbn

Function · Source

Power-of-two scaling keeps the final subnormal rounding in a single multiply.

pub fn scalbn(value: f64, exponent: i32) -> f64

sqrt

Function · Source

Newton iteration after exact exponent normalization; no hardware sqrt needed.

pub fn sqrt(value: f64) -> Result<f64, MathError>

cbrt

Function · Source

pub fn cbrt(value: f64) -> f64

hypot

Function · Source

pub fn hypot(a: f64, b: f64) -> f64

log

Function · Source

Log reduction to [sqrt(1/2),sqrt(2)]. The convergent atanh series uses 12 terms: its exact-arithmetic truncation error is below 2e-21 on that interval. The split ln(2) constants are generated above; see std/math/CONSTANTS.md.

pub fn log(value: f64) -> Result<f64, MathError>

log2

Function · Source

pub fn log2(value: f64) -> Result<f64, MathError>

log10

Function · Source

pub fn log10(value: f64) -> Result<f64, MathError>

log1p

Function · Source

pub fn log1p(value: f64) -> Result<f64, MathError>

exp

Function · Source

Exp range reduction uses a split ln(2), then the Taylor polynomial on [-ln(2)/2,ln(2)/2]. Finite overflow is an error; gradual underflow is allowed.

pub fn exp(value: f64) -> Result<f64, MathError>

exp2

Function · Source

pub fn exp2(value: f64) -> Result<f64, MathError>

expm1

Function · Source

pub fn expm1(value: f64) -> Result<f64, MathError>

powi

Function · Source

Integer exponentiation: negative exponents invert the base first. 0^0=1; zero to a negative power is DivisionByZero; finite overflow is checked.

pub fn powi(base: f64, exponent: i32) -> Result<f64, MathError>

pow

Function · Source

General real power. Negative finite bases require an exactly integral power.

pub fn pow(base: f64, exponent: f64) -> Result<f64, MathError>

Type to search all documentation.

Keyboard shortcuts

Search documentation
Ctrl K or /
Move through results
↑ ↓
Open selected result
Enter
Close a dialog
Esc
Show these shortcuts
?