The answer to 10.0/3 or float(10/3) is 3.3333333333333335 instead of 3.333333333333333
(%i1) 10.0/3;
(%o1) 3.3333333333333335
(%i2) float(10/3);
(%o2) 3.3333333333333335
(%i3) float(100/3);
(%o3) 33.333333333333336
(%i4) float(1000/3);
(%o4) 333.3333333333333
(%i5) float(10000/3);
(%o5) 3333.3333333333335
Please note in all cases but 1000/3 there are 17 printed digits instead of 16. However setting fpprintprec to 16 does not completely solve the problem, as float(100/3) is still wrong
(%i6) fpprintprec:16;
(%o6) 16
(%i7) 10.0/3;
(%o7) 3.333333333333333
(%i8) float(10/3);
(%o8) 3.333333333333333
(%i9) float(100/3);
(%o9) 33.33333333333334
(%i10) float(1000/3);
(%o10) 333.3333333333333
(%i11) float(10000/3);
(%o11) 3333.333333333333
I use maxima 5.48.1 in Archlinux
This is not a bug. It is the expected behavior of floating point arithmetic on any computer.
maxima has a number of ways to address the issue you have reported. I suggest you ask specific questions on the Maxima discussion list
You can refer to What every computer scientist should know about floating-point arithmetic for some background.
In addition to what David said, there is a subtle difference between
10.0/3andfloat(10/3). The former is a floating-point division between10.0and3.0. Both of thsee can be represented exactly in floating point. However,float(10/3)is the nearest floating-point value to the rational10/3. These two values aren't always the same due to how rounding is done.You can check the value by doing something like
:lisp (print (/ 10.0 3)). For me with cmucl, I get 3.3333333333333335. I know cmucl uses an algorithm that prints a value that when read in produces the same value as produced by(/ 10.0 3). I'm pretty sure sbcl uses the same algorithm. I believe all other lisps use the similar algorithms that produce the same output such that when read in, the exact same floating-point value is produced.We need to write a FAQ about floating point. Of course it is the same in
every other system, but Maxima also has bigfloats and rationals, which are
helpful for discussing floats. For example:
rationalize -- converts a floating point number to the exact rational
number it is equal to -- the denominator is always a power of 2
rationalize(10.0/3.0) - 1/3 => 1/6755399441055744 ... float(%)
=> 1.4802973661668753e-16
rat -- finds the "nicest" rational within ratepsilon (default 2.0e-15) of a
float
10.0/3.0 => 3.3333333333333335 ... rat(%)
rat: replaced 3.3333333333333335 by 10/3 = 3.3333333333333335
=> 1/3
cf -- finds the continued fraction representation -- shows the "nicest"
nearby rationals
cfdisrep -- converts to standard arithmetic form
cfdisrep(cf(10.0./3.0)) => 3+1/(2+1/(1+1/750599937895082))
On Mon, Sep 1, 2025 at 1:44 PM Raymond Toy rtoy@users.sourceforge.net
wrote:
Related
Bugs:
#4604Thank you for your quick and detailed answers, and for the article as well. Apologies for opening this ticket as a bug.
No problem. Please follow up on the maxima-discuss list.