[Haskell-cafe] Re: Is logBase right?

Lennart Augustsson lennart at augustsson.net
Thu Aug 27 20:45:04 EDT 2009


Prelude> toRational 697.04157958259998
3065621287177675 % 4398046511104
Prelude> toRational 697.0415795826
3065621287177675 % 4398046511104

As you can see, both numbers are represented by the same Double.
Haskell prints a Double with the simplest number that converts back to
the same bit pattern.
So there's no "keep more decimals", just a matter of string conversion.

  -- Lennart

On Tue, Aug 25, 2009 at 7:11 PM, Ketil Malde<ketil at malde.org> wrote:
> Steve <stevech1097 at yahoo.com.au> writes:
>
>> Also, I had a problem using floating point in Python where
>>>>> round(697.04157958254996, 10)
>> gave
>> 697.04157958259998
>
>> Its been fixed in the latest versions of Python:
>>>>> round(697.04157958254996, 10)
>> 697.0415795825
>
>> ghci> roundN 697.04157958254996 10
>> 697.0415795826
>
> Is there something special with this number?
>
>  Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
>  [GCC 4.3.3] on linux2
>  Type "help", "copyright", "credits" or "license" for more information.
>  >>> 697.04157958259998
>  697.04157958259998
>  >>> 12345.678901234567890
>  12345.678901234567
>
>  GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
>  Loading package base ... linking ... done.
>  Prelude> 697.04157958259998
>  697.0415795826
>  Prelude> 12345.678901234567890
>  12345.678901234567
>
> So, Python manages to keep more decimals than GHC for your number, but
> for other numbers, the precision appears to be the same.
>
> -k
> --
> If I haven't seen further, it is by standing in the footprints of giants
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>


More information about the Haskell-Cafe mailing list