fx4.bend fails
raw source on the hub · import 0x4e6a6615b0feb5ac27adea952228511e/fx4.bend as Fx4
lib/fx4.bend -- Q8.120 signed fixed point on four flat U32 limbs.
GENERATED by lib/gen_fx4.py -- edit the generator, not this file.
An Fx4 is a 128-bit two's-complement integer (a:b:c:d, a most significant) read as value / 2^120: range about +-128, resolution 2^-120 (7.5e-37), against lib/fixed64.bend's 2^-56. That is a factor of 2^64 more precision, and it moves the Mandelbrot zoom wall from about 1e14 to about 1e33.
The point of the FLAT record is the GPU. lib/bigfix.bend does the same arithmetic on a list of limbs, and is correct, but it allocates a cons cell per limb per operation, so it runs on one core and the Metal watchdog kills it. Fx4 has no allocation and no recursion in its arithmetic: every operation is straight-line U32, and the 16 partial products of the multiply are unrolled.
Fx4.mul truncates toward zero. Fx4.div10 and Fx4.shr are for non-negative values (the decimal parser and pixel geometry). Tested against Python big integers by lib/test_fx4.py.
1 import
import Base
The reader could not load this file (at 0x4e6a6615b0feb5ac27adea952228511e/fx4.bend:70). What bend.ts says:
Error: - message : a type for this operator (write (a < b : Nat)) Location: 69 | +rd = (xd + yd : U32) 70>| +k0 = (Fx4.b2u(rd < xd) : U32) | ^ 71 | +t1 = (xc + yc : U32) Note: we broke this after launch, sorry. Until 2.0.16 a bare operator meant Nat. That was a bug: operators demand annotation. Wrap the expression and it'll work again.