printing floats (3/3), was: minor strangeness in cvs head maxima
Subject: printing floats (3/3), was: minor strangeness in cvs head maxima
From: Raymond Toy
Date: Wed, 12 Oct 2005 11:48:52 -0400
>>>>> "Robert" == Robert Dodier writes:
Robert> ((floatp symb)
Robert> (let ((a (abs symb)))
Robert> ;; When printing out something for Fortran, we want to be
Robert> ;; sure to print the exponent marker so that Fortran
Robert> ;; knows what kind of number it is. It turns out that
Robert> ;; Fortran's exponent markers are the same as Lisp's so
Robert> ;; we just need to make sure the exponent marker is
Robert> ;; printed.
Robert> ;;
Robert> ;; Also, for normal output, we basically want to use
Robert> ;; prin1, but we can't because we want fpprec to control
Robert> ;; how many digits are printed. So we have to check for
Robert> ;; the size of the number and use ~e or ~f appropriately.
Robert> (multiple-value-bind (form width)
Robert> (if (or *fortran-print*
Robert> (zerop a)
Robert> (<= .001d0 a 10000000d0))
Robert> (values "~vf" (+ 1 $fpprec))
Robert> (values "~ve" (+ 5 $fpprec)))
Robert> (setq string (format nil form width symb)))
Robert> (setq string (string-trim " " string))))
Robert> This fixes the issue with 1.0 and 1.0d295. However, we now have a
Robert> problem if we want to use $fpprec to control the number of digits if
Robert> the number is between 0.001 and 1.
Robert> I need some guidance here. Perhaps this should be on the list? If
Robert> so, you can forward to this message (and all previous ones) to the
Robert> list too.
I guess the questions here are:
o How should fortran(foo) interact with fpprec? The old code used to
print out just the number of digits specified by fpprec. But
perhaps we don't want to do that when we're converting to Fortran?
Should we print the numbers with full precision?
o Should fpprec really control how many digits are printed? Because
it does for bfloats, it seems reasonable for other floats. (But
bfloats are always printed in exponential form to get the B exponent
marker.) If so, the code needs to be made a little smarter so that
numbers between 0.001 and 1 get printed with enough significant
digits. What about numbers between 1 and 10^7? Should they be
printed with only fpprec significant digits. So if fpprec is 5, how
is 12345678.9 printed?
12345678.90000 or 12346000.0?
Ray