[Haskell-cafe] Re: Is logBase right?

Magnus Therning magnus at therning.org
Sun Aug 23 04:35:19 EDT 2009


2009/8/22 Roberto López <plastermoso at hotmail.com>:
> If 4.0 / 2.0 was 1.9999999999999999999998, it would be ok?
>
> The real value of log10 1000 is 3 (3.0). It can be represented with accuracy
> and it should be.

Well, it already can be, you just need to choose your representation properly:

> logBase 10 1000 :: Double
2.9999999999999996
> logBase 10 1000 :: Float
3.0

Welcome the wonderful land of floating point numbers.

(The examples above are from an Intel 32-bit machine, I suspect it'd
change on any other type of architecture.)

/M

-- 
Magnus Therning                        (OpenPGP: 0xAB4DFBA4)
magnus@therning.org          Jabber: magnus@therning.org
http://therning.org/magnus         identi.ca|twitter: magthe


More information about the Haskell-Cafe mailing list