3 ms·
Beware; the calculator code isn't standard Scheme; it is written in Gambit Scheme, which underlies the LambdaNative project. The ##flonum? is a "Primitive Proc
by kazinator 4y ago
Beware; the calculator code isn't standard Scheme; it is written in Gambit Scheme, which underlies the LambdaNative project.
The ##flonum? is a "Primitive Procedure", see here:
https://gambitscheme.org/latest/manual/#Primitive-Procedures
which has no place in an application program like this; it's hard to imagine why the author of the calculator didn't just use Gambit's flonum? function. (In standard Scheme, the inexact? function would be used.)
The code is using Gambit-specific functions with a fl prefix like fl+, fl/ and fl, which provide floating-point-specific arithmetic functions. Standard Scheme doesn't do that; it just has +, / and for all numbers and mixtures of numbers.
It looks like the author of the code has a naive view of floating-point; he or she seems to be under the impression that if you multiply a number by 1E10, then add 0.5, take the floor and divide by 1E10, that it will thereby truncated to 10 digits after the decimal after which there are reliably zeros, such that number->string will never produce more than 10 digits after the decimal. That would be true in a decimal-based floating-point representation, not in a binary one.
So that whole expression (number->string (fl/ (flfloor (fl+ (fl* (flo n) 1.0e10) 0.5)) 1.0e10)) is doing something dodgy that should be done in an entirely different way.