gcl-devel
[Top][All Lists]

## Re: [Gcl-devel] RE: GCL bugs (decode-float, rationalize, expt)

 From: Camm Maguire Subject: Re: [Gcl-devel] RE: GCL bugs (decode-float, rationalize, expt) Date: 07 Jan 2003 01:19:16 -0500

```Greetings, and thanks again for your report!

> Camm--
>
>
> > if you could detail what results you would expect to the
> > commands below that differ from the present behavior.
>
> OK, see below.  I hope this is helpful.
>
>        -s
>
> -----------------------------
>
> > >(rationalize 1.0e-300)
> >
> > 6032057205060441/603205720506044084884212454315773567705025225
> > 17485057817966150649616223444937272933709735781382657437082254
> > 25014400837164813540499979063179105919597766951022193355091707
> > 89603485068403905907918039678834910609558429008744607641377146
> > 89404772415506707531455176029312243924240295474299938241298892
> > 35158145614364972941312
>
> This is the correct value for (rational 1.0e-300).  However,
> rationalize is supposed to take into account the precision of
> floating-point representation to minimize the denominator, so
> the correct value here would be 1/x, where x is some integer
> near 10^300 (or possibly x/y, x>1, y<10^300).
>

I agree that it would be a good idea for rationalize to behave as you
describe, but I don't believe it is required by the spec:

=============================================================================
If number is a float, rational returns a rational that is
mathematically equal in value to the float.  rationalize returns a
rational that approximates the float to the accuracy of the underlying
floating-point representation.

rational assumes that the float is completely accurate.

rationalize assumes that the float is accurate only to the precision
of the floating-point representation.
=============================================================================

I've left this alone for now due to the following comment I've
discovered in numlib.lsp:

=============================================================================
;; although the following is correct code in that it approximates the
;; x to within eps, it does not preserve (eql (float (rationalize x) x) x)
;; since the test for eql is more strict than the float-epsilon

;;; Rationalize originally by Skef Wholey.
;;; Obtained from Daniel L. Weinreb.
;(defun rationalize (x)
...
=============================================================================

I'm checking in fixes for all the others.  Please understand that I've
only addressed the problems you've raised -- there may be other
assumptions of normality elsewhere in the code.  I would, of course,
appreciate being informed of such if you find them.

My session now:

=============================================================================
>(scale-float 1.0e-320 -3)

1.2499860839783538E-321

>(scale-float 1.0e-320 3)

7.999910937461464E-320

>(float (rationalize 1.0e-320))

9.9998886718268301E-321

>(expt 10.0 -310)

9.9999999999989813E-311

>(decode-float 1.0e-320)

0.98828125
-1063
1.0

>=============================================================================

Take care,

> > >(float (rationalize 1.0e-320))
> > 0.0
>
> Incorrect.  (rationalize 1.0e-320) should be 1/x, where x is
> somewhere near 10^320, and (float (rationalize 1.0e-320) should be
> 1.0e-320.
>
> > >(expt 10.0 -310)
> > 0.0
>
> Incorrect.  Should be 1.0e-310.
>
> > >(expt 10 -300)
> >
> > 1/100000000000000000000000000000000000000000000000000000000000
> > 00000000000000000000000000000000000000000000000000000000000000
> > 00000000000000000000000000000000000000000000000000000000000000
> > 00000000000000000000000000000000000000000000000000000000000000
> > 0000000000000000000000000000000000000000000000000000000
>
> Correct.
>
> > >(decode-float 1.0e-300)
> > 0.66969287949141709
> > -996
> > 1.0
>
> Correct.
>
> > >(decode-float 1.0e-320)
> > 0.50000000000022471
> > -1022
> > 1.0
>
> Incorrect.  0.5 * 2^-1022 = 1.1e-308, not 1.0e-320.
> Correct answer is roughly .49, -1062, 1.0
>
> > >(integer-decode-float 1.0)
> > 4503599627370496
> > -52
> > 1
>
> Correct. 450xxxx = 2^52, so 450xxxx * 2^-52=1
>
>
>
> _______________________________________________
> Gcl-devel mailing list
> http://mail.gnu.org/mailman/listinfo/gcl-devel
>
>

--