def nextafter

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

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/src/math/f64.bend as F

444# the ordered-set neighbour (IEEE nextAfter, C99 annex F): NaN in, NaN out;
445# y when x == y; from a zero the smallest subnormal with y's sign; otherwise
446# one step of the magnitude bits, up when moving away from zero (the step past
447# the largest finite double is infinity, the step below the smallest
448# subnormal a zero of x's sign)
449def nextafter(+x: F.F64, +y: F.F64) -> F.F64:
450  pick(F.F64, Bool.not(ordered(x, y)), qnan(), pick(F.F64, Cmp.is_eq(ord(x, y)), y, pick(F.F64, is_zero(x), encode(sign(y), 0n, 1n), of_pat(sign(x), pick(Nat, Bool.xor(Cmp.is_lt(ord(x, y)), sign(x)), Nat.add(pat(x), 1n), Nat.sub(pat(x), 1n))))))

Uses (17)

Used by (2)