Andy Haywood <···········@cwcom.net> writes:
> Why does
>
> (* 353.0 0.01) => 3.5300000000002
>
> but
>
> (/ 353.0 (/ 1 0.01)) => 3.53
>
> ?
You have just discovered the discipline of Numerical Analysis, the
area of computational mathematics in which you find that 1+1 is not
_exactly_ 2, at least not if you're working with imprecise values.
The critical thing that is happening here is that the conversion of
the fraction "1/100" into binary involves losing some precision, since
it cannot be exactly represented.
As a result of that loss of precision, you will find that expressions
you'd _think_ should be identities in fact aren't.
--
(concatenate 'string "cbbrowne" ·@hex.net") <http://www.ntlug.org/~cbbrowne/>
(THASSERT (PLANNER RG))
-- Example of HACKER statement.
········@hex.net wrote:
>
> Andy Haywood <···········@cwcom.net> writes:
> > Why does
> >
> > (* 353.0 0.01) => 3.5300000000002
> >
> > but
> >
> > (/ 353.0 (/ 1 0.01)) => 3.53
> >
> > ?
>
> You have just discovered the discipline of Numerical Analysis, the
> area of computational mathematics in which you find that 1+1 is not
> _exactly_ 2, at least not if you're working with imprecise values.
As my boss, Ken Smith, from 20 years ago said "One plus one is three
for large values of one" after finding this nasty bug in some microcode.