def to_nat

bend-collections-laws-math@1.0.0.0 · spec/math/f64.bend:364

import bend-collections-laws-math@1.0.0.0/spec/math/f64.bend as F64
import Base
import bend-collections-laws-math@1.0.0.0/spec/lib/common.bend as C
import bend-collections-laws-math@1.0.0.0/src/math/f64.bend as F
import bend-collections-laws-math@1.0.0.0/src/math/num.bend as N

364# x truncated toward zero as a w-bit unsigned integer: NaN is a domain error;
365# an infinity, a truncation below zero or one of 2^w or more an overflow
366# (3.1: int(x) truncates; 2.6: fixed widths raise instead of wrapping)
367def to_nat(+x: F.F64, +w: Nat) -> Result<&2, &2, N.NumError, Nat>:
368  pick(Result<&2, &2, N.NumError, Nat>, is_nan(x), Fail{N.BadDomain{}}, pick(Result<&2, &2, N.NumError, Nat>, Bool.or(is_inf(x), Bool.or(Bool.and(sign(x), Bool.not(Nat.is_eq(int_part(x), 0n))), Bool.not(C.fits(w, int_part(x))))), Fail{N.Overflow{}}, Done{int_part(x)}))

Uses (14)

Used by (10)