~/bend-docscommunity

INT64_LAWS.bend source

INT64_LAWS.bend on the hub · documented module

# The laws of bend-float64's 64-bit integer conversions (float64.bend), at literal inputs: NumPy's answers on x86-64.# A gate of its own so that each proof file stays within the checker's limit.# Gate: ./bend-check INT64_PROOF.bend --verdictimport Baseimport ./wide.bend as Wimport ./float64.bend as F# Guarantees: to_i64 truncates (-2.5 -> -2) and gives -2^63 for 2^63, 1.5 * 2^63 and NaN; to_u64 gives -1.0 -> 2^64 - 1,#   2^63 -> 2^63, the largest float64 below 2^64 -> 0xFFFFFFFFFFFFF800, 2^64 -> 0 (NumPy's astype on x86-64);#   from_i64 is exact for -2^63 and ties to even for 2^53 + 1 and -(2^53 + 1); from_u64 rounds 2^64 - 1 up to 2^64#   and ties 2^63 + 2^10 down and 2^63 + 3 * 2^10 up to even.# Why it matters: 64-bit integers are where conversions overflow or round; these pin both to the hardware's answers.law conversions_64:  {[F.to_i64(F.of_bits(3221487616, 0)), F.to_i64(F.of_bits(1138753536, 0)), F.to_i64(F.of_bits(2146959360, 0)), F.to_i64(F.of_bits(1139277824, 0)),    F.to_u64(F.of_bits(3220176896, 0)), F.to_u64(F.of_bits(1138753536, 0)), F.to_u64(F.of_bits(1139802111, 4294967295)),    F.to_u64(F.of_bits(1139802112, 0))]    == [W.W64{4294967295, 4294967294}, W.W64{2147483648, 0}, W.W64{2147483648, 0}, W.W64{2147483648, 0},        W.W64{4294967295, 4294967295}, W.W64{2147483648, 0}, W.W64{4294967295, 4294965248},        W.W64{0, 0}] : List<&2, W.W64>}  & {[F.from_i64(W.W64{2147483648, 0}), F.from_i64(W.W64{2097152, 1}), F.from_i64(W.W64{4292870143, 4294967295}),      F.from_u64(W.W64{4294967295, 4294967295}), F.from_u64(W.W64{2147483648, 1024}), F.from_u64(W.W64{2147483648, 3072})]    == [F.F64{3286237184, 0}, F.F64{1128267776, 0}, F.F64{3275751424, 0},        F.F64{1139802112, 0}, F.F64{1138753536, 0}, F.F64{1138753536, 2}] : List<&2, F.F64>}