fpprintprec and leading zeros



On 2013-12-28, Tamas Papp <tkpapp at gmail.com> wrote:

> I find that printing of the leading 0 is not consistent: my
> guess is that it is only printed when trailing zeros can be chopped off:
>
> --8<---------------cut here---------------start------------->8---
> (%i190) fpprintprec:4;
> (%o190)                                4
> (%i191) 0.1868;
> (%o191)                              .1868
> (%i192) 0.1860;
> (%o192)                              0.186

On looking at this again (thanks for the reference), I have concluded
this is a bug in Maxima's use of the floating point formatter. CLHS
states [1] that exactly w characters are output where w is the width
of the field. Maxima supplies the same width (namely fpprintprec + 1)
for 0.1868 and 0.1860 and, according to CLHS, the formatter must prefer
a trailing significant digit to the leading zero (i.e., it is not an
idiosyncrasy of SBCL).

The logic for this stuff is found at lines 315--328 in src/commac.lisp
(function EXPLODEN). I looked at it for a few minutes but I don't have
an easy fix.

Probably it's a good idea to post a bug report [2] to help us keep
track of this problem.

best

Robert Dodier

[1] http://www.lispworks.com/documentation/HyperSpec/Body/22_cca.htm
[2] http://sourceforge.net/p/maxima/bugs