Thanks! I realized that and already changed my post to read "almost satisfying" instead of "not fully satisfying."jahboater wrote: ↑Mon Jul 15, 2019 7:11 pmThe results for this C code are correct and as expected.ejolson wrote: ↑Mon Jul 15, 2019 6:53 pmOne obtains a different but still not fully satisfying result with the C programwonder if Richard's BBC Basic does the same.Code: Select all
#include <stdio.h> #include <math.h> int main(){ for(double x=1e3;x<=1e32;x*=10){ double y=floor(x); printf("floor(%g)=%f %s\n", x,y,y==x?"equal":"not equal"); } return 0; }
floor(x) returns largest integral value not greater than x.
Therefore if x is an integer, floor(x) will return x. And in your example x is always an integer.
I think you need for the example: long n = lrint(x)
If the rounded value of x cannot be stored in a long, it will report a domain error (and raise the FE_INVALID exception).
I wonder what happens if one moves along exact powers of two.