for fpprec:1 thru 20 do if equal(float(1/3),bfloat(1/3)) then print(fpprec);
2, 5, 8, 11, 14
for fpprec:1 thru 20 do if equal(bfloat(1/3),float(1/3)) then print(fpprec);
1, 3, 4, 6, 7, 9, 10, 12, 13, 15
This is because equal(a,b) works by calculating a-b, which is not the same as b-a.
There are a several cleaner definitions which would make equal reflexive:
I would advocate for the most "intuitive" definition, namely the first: they are equal if they represent exactly the same number.
OK by me to implement rationalize(y) = rationalize(x).
To be clear, I mean that as a specification. To implement, we can use
integer-decode-floatandashto align the binary representations, like this (thank you, Claude):