Comment 5 for bug 308961

Revision history for this message
Nikodemus Siivola (nikodemus) wrote :

Thank you! Sorry about taking so long to merge this.

Committed as:

commit 58187b3f2ab87bce54657c9c94ac2b3090103ba1
Author: David Vázquez <xxx>
Date: Mon Jun 28 17:28:08 2010 +0200

    FLONUM-TO-DIGITS handles non-negative input properly

     lp#308961, part 1.

     SBCL has an extended version of the Burger & Dybwig fp printer, which
     supports rounding.

     It did not however support zero -- but in eg.

       (format nil "~,1F" 0.001)

     0.001 is rounded to zero, which leads FLONUM-TO-DIGITS giving us one zero too
     many. Ie. it should be

        => "0.0"

     but prior to this we got "0.00" instead.

     This patch removes the special casing for 0, and instead tests that the lower
     limit of the interval (- r m-) is positive in order not to generate extra
     zeros.

and

commit dafa18aa6bd65fe2129a32b0e827141684bb159a
Author: David Vázquez <xxx>
Date: Mon Jun 28 18:53:30 2010 +0200

    FORMAT-AUX-EXP: adjust scale if scale-exponent return 1.0

     lp#308961, part 2.

     FORMAT-EXP-AUX scales a number such that it will have K digits before of the
     decimal point. This relies on scale-exponent.

      (format nil "~E" 0.1) ; => "1.e-1"

      0: (FORMAT-EXP-AUX #<SB-IMPL::STRING-OUTPUT-STREAM {AFE5DE9}> 0.1 NIL NIL
                         NIL 1 NIL #\ NIL NIL)
        1: (SB-IMPL::SCALE-EXPONENT 0.1)
        1: SB-IMPL::SCALE-EXPONENT returned 0.1 0
      0: FORMAT-EXP-AUX returned "1"

     0.1 is 0.1 * 10^0 according to scale-exponent. Then, it is multiplied by 10^K
     before printing. Everything works out fine.

     However!

      (format nil "~E" 0.01) ; => "10.e-3" ... oops

      0: (FORMAT-EXP-AUX #<SB-IMPL::STRING-OUTPUT-STREAM {AA744C1}> 0.01 NIL NIL
                         NIL 1 NIL #\ NIL NIL)
        1: (SB-IMPL::SCALE-EXPONENT 0.01)
        1: SB-IMPL::SCALE-EXPONENT returned 1.0 -2
      0: FORMAT-EXP-AUX returned "2"

     In this example, scale-exponent returns 1.0 and -2, meaning 0.01 = 1.0 *
     10^-2. Again, format-aux-exp multiply it by 10^K. But as 1.0 has a digit
     before of the decimal point, the result will have K+1 digits.

     This is due to format-exp-aux assumed the returned value will be lesser to
     1.0. In order to fix this, we decrement K when scale-exponent return 1.0 as
     primary value.

with tests in

commit bea52212cb688209f31804bc6d4644968ac28246
Author: Nikodemus Siivola <email address hidden>
Date: Tue Jun 7 12:29:21 2011 +0300

    tests and NEWS for lp#308961

      Also add a random FP read/print consistency tester.

      For now it skips denormalized double-floats due to bug 793774.