~/bend-docscommunity

SQRT_LAWS.bend source

SQRT_LAWS.bend on the hub · documented module

# The square root's rounding law (float64.bend), at literal inputs, in a gate of its own: the checker's evaluation of# the square root's 62 steps is the costliest in the arithmetic, and with LAWS.bend's other laws it came too close to# the checker's 10-second limit.# Gate: ./bend-check SQRT_PROOF.bend --verdictimport Baseimport ./float64.bend as F# Guarantees: sqrt(2) and sqrt(0.5) round to nearest, sqrt(4) = 2 exactly, sqrt(-0) = -0, sqrt(-1) = default NaN,#   sqrt of the smallest subnormal is 2^-537 exactly, sqrt(max) rounds to nearest.# Why it matters: an odd exponent (2, 0.5) and a subnormal input take the core's two alignment paths.law sqrt_rounding:  {[F.sqrt(F.of_bits(1073741824, 0)), F.sqrt(F.of_bits(1074790400, 0)), F.sqrt(F.of_bits(2147483648, 0)), F.sqrt(F.of_bits(3220176896, 0)),    F.sqrt(F.of_bits(0, 1)), F.sqrt(F.of_bits(2146435071, 4294967295)), F.sqrt(F.of_bits(1071644672, 0))]    == [F.F64{1073127582, 1719614413}, F.F64{1073741824, 0}, F.F64{2147483648, 0}, F.F64{4294443008, 0}, F.F64{509607936, 0},        F.F64{1609564159, 4294967295}, F.F64{1072079006, 1719614413}] : List<&2, F.F64>}