Menu

#4970 floor and ceiling return wrong integers, with ceiling less than floor

None
open
nobody
5
13 hours ago
13 hours ago
No

ceiling(x) returns a value 3 BELOW floor(x), and floor equals ceiling for an irrational argument

Maxima 5.49post, SBCL 2.6.7.

Three separate self-refuting outcomes from ordinary input at default settings.

(%i1) display2d:false$
(%i2) z: block([fpprec:40], bfloat(10^17*%pi))$
(%i3) r: rationalize(z)$
(%i4) fpprec:16$
(%i5) [floor(z), ceiling(z)];
(%o5) [314159265358979323,314159265358979320]
(%i6) [floor(r), ceiling(r)];
(%o6) [314159265358979323,314159265358979324]
(%i7) [floor(-10^17*%pi), ceiling(-10^17*%pi)];
(%o7) [-314159265358979320,-314159265358979323]
(%i8) round(10^17*%pi);
(%o8) 314159265358979320
(%i9) [floor(10^17*sqrt(2)), ceiling(10^17*sqrt(2))];
(%o9) [141421356237309504,141421356237309504]

Expected: ceiling(z) = 314159265358979324 as in (%o6); floor(-10^17*%pi) = -314159265358979324; round(10^17*%pi) = 314159265358979324; ceiling(10^17*sqrt(2)) = 141421356237309505.

(%o5) has ceiling < floor. (%o7) has floor > ceiling. (%o9) has floor = ceiling for an irrational argument. All three are impossible, so no reference value is needed to see something is wrong.

(%o6) is the oracle: rationalize gives the exact rational value of the identical bigfloat object, and exact-rational floor/ceiling take a different code path. It shows floor is right and ceiling is wrong.

round, truncate, entier and fix are affected too. Note floor(10^30*%e) declines to evaluate and stays symbolic while ceiling(10^30*%e) returns an answer that is correct to only 17 of its 31 digits, so the two disagree about whether the question is even answerable.

Discussion


Log in to post a comment.