[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Clisp940204 add problem
- To: "Stewart G. Tattersall" <firstname.lastname@example.org>
- Subject: Clisp940204 add problem
- From: email@example.com (Joerg-Cyril Hoehle)
- Date: Mon, 20 Feb 95 19:24:13 +0100
- Cc: firstname.lastname@example.org
- In-reply-to: <Pine.ULT.3.91.950218122121.2661A-100000@hunter>
- References: <Pine.ULT.3.91.950218122121.2661A-100000@hunter>
Stewart G. Tattersall writes:
> > (+ 8.625 5.44)
> > (+ 8.625 13.44)
> > (+ 8.625 113.44)
> > (+ .625 .44)
> What is causing this error is a mystery to me.
Maybe it's not an error but a symptom of the limited mantissa of the
floating point format. Most decimal numbers have no exact log2
representation and converting between the two representations causes
the output you see.
0.999999999999999999999.... and 1.0 are the same numbers. With a
limited mantissa you only get an approximation of the first.
5.44 is represented internally as
where it would really be
> I would like to see a bug fix.
CLISP gives you a choice of four floating point formats. Try
(setq *READ-DEFAULT-FLOAT-FORMAT* 'short-float)
with one of SHORT-FLOAT, SINGLE-FLOAT (the default), DOUBLE-FLOAT and
LONG-FLOAT. It might give you want you are looking for. It must not.
You can choose the minimal number of digits to compute with in the
long-float format. The default is 64.
Otherwise you might give a try to rational arithmetic:
> (+ 8625/1000 544/100)
> (float *)
(Have a look at *DEFAULT-FLOAT-FORMAT* for this last conversion).
> This problem is making me look bad using lisp as my environment of
You could get the same with any language, with a pocket calculator or a Cray.
> > (LISP-IMPLEMENTATION-VERSION)
> "January 1994"
> My system is an A3000.
You'll get exactly the same results with the January 1995 Sun4m CLISP version.