[comp.lang.ada] Ko_Haw Nieh's floating-point formatting problem

NCOHEN@IBM.COM (Norman COHEN) (11/15/87)

There is no way to achieve the effect Ko-Haw Nieh desires using the
versions of Put provided by instances of Text_IO.Float_IO.  Those
versions allow two different styles of real output, ordinary notation
and scientific notation.  Ordinary notation results from an EXP value of
zero.  Thus

   Put (23.35, Fore => f, Aft => a, Exp => 0);

produces output of the form

   b...b23.350...0
   \     / \     /
   min(f,2)   a

where the value for FORE affects the number of leading blanks and the
value for AFT affects the number of digits printed after the decimal
point.

A nonzero value of EXP results in scientific notation.  Some people
define scientific notation to include one significant digit before the
decimal point and others define it with the most signficant digit
immediately to the right of the decimal point.  The designers of Ada
subscribe to the first definition; the designers of Ko-Haw Nieh's
FORTRAN compiler apparently subscribe to the second.  In Ada, the call

   Put (23.35, Fore => f, Aft => a, Exp => e);  -- e>0

produces output of the following form:

   b...b2.3350...0E+0...01
   \    / \      / \     /
  min(f,1)    a    min(e,2)


FORE controls only the number of leading blanks, AFT controls only the
number of digits following the decimal point and preceding the E, and
EXP controls only the number of characters (including the sign)
following the E.  There is no way to control the number of significant
digits that appear before the decimal point.

It is, of course, possible--with some work--to write one's own
version of Put based on the other definition of scientific notation, or
to write a version with an additional parameter to control the number of
significant digits that will appear before the decimal point when
exponential notation is used.