From ...
From: Erik Naggum
Subject: Re: Gnu Common Lisp HELP!
Date: 1996/01/11
Message-ID: <19960111T202920Z@arcana.naggum.no>#1/1
X-Deja-AN: 135255175
references: <30F51D2D.C84@ling.umu.se>
organization: Naggum Software; +47 2295 0313
newsgroups: comp.lang.lisp
[Ola Andersson]
| I am a new Lisp user and I would like to know why I get this result:
| (SETQ INTEREST-RATE 0.1)
| 0.10000000001
because it's correct. 0.1 cannot be expressed accurately with floating
point. instead of floating point, use rational numbers, such as 1/10.
representing and computing monetary values with floating-point is a
well-known "sin".
note that the Common Lisp `round' function rounds to even integers. this
is the numerically correct solution, and works out best with money, as
well. most people don't understand this, and insist on small errors. some
national regulations even force people to be screwed by rounding errors.
you may need to take this into account (pun intended).
| I am using gcl v2.1. (What is the latest version?)
version 2.2 has been released. look in math.utexas.edu:/pub/gcl.
#
--
the problem with this "information superhighway" is mainly that if you ask
people to go play in it, they don't even understand when they get run over.