Which one is right?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Which one is right?

Linker Lin-2
Hi,All,
Construct a list:
[0,0.1..1]

====================================
||   || ||  || ||  || ||__      Hugs 98: Based on the Haskell 98 standard
||___|| ||__|| ||__||  __||     Copyright (c) 1994-2005
||---||         ___||           World Wide Web: http://haskell.org/hugs
||   ||                         Bugs: http://hackage.haskell.org/trac/hugs
||   || Version: September 2006 _________________________________________

Haskell 98 mode: Restart with command line option -98 to enable extensions

Type :? for help
Hugs> [0,0.1..1]
[0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]
Hugs>

====================================
GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
Prelude> [0,0.1..1]
[0.0,0.1,0.2,0.30000000000000004,0.4,0.5,0.6,0.7,0.7999999999999999,0.8999999999999999,0.9999999999999999]
Prelude>

====================================
Thanks.


--
Regards,
Linker Lin
[hidden email]

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Which one is right?

Thomas Davie
This looks like Hugs defaulting to a different type to ghci,  
specifically, Hugs is defaulting to one of the high precission types  
like CReal or Rational, while ghci is defaulting to Float or Double.

Bob

On 24 Jun 2009, at 21:03, Linker wrote:

> Hi,All,
> Construct a list:
> [0,0.1..1]
>
> ====================================
> ||   || ||  || ||  || ||__      Hugs 98: Based on the Haskell 98  
> standard
> ||___|| ||__|| ||__||  __||     Copyright (c) 1994-2005
> ||---||         ___||           World Wide Web: http://haskell.org/ 
> hugs
> ||   ||                         Bugs: http://hackage.haskell.org/trac/hugs
> ||   || Version: September 2006  
> _________________________________________
>
> Haskell 98 mode: Restart with command line option -98 to enable  
> extensions
>
> Type :? for help
> Hugs> [0,0.1..1]
> [0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]
> Hugs>
>
> ====================================
> GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
> Loading package base ... linking ... done.
> Prelude> [0,0.1..1]
> [0.0,0.1,0.2,0.30000000000000004,0.4,0.5,0.6,0.7,0.7999999999999999,0.8999999999999999,0.9999999999999999
> ]
> Prelude>
>
> ====================================
> Thanks.
>
>
> --
> Regards,
> Linker Lin
> [hidden email]
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Which one is right?

Bulat Ziganshin-2
In reply to this post by Linker Lin-2
Hello Linker,

Wednesday, June 24, 2009, 11:03:19 PM, you wrote:

> Construct a list:
> [0,0.1..1]

floats are newspeak: 2*2 may be more than 4 or less than 4 :)

--
Best regards,
 Bulat                            mailto:[hidden email]

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Which one is right?

Daniel Fischer-4
In reply to this post by Thomas Davie
Am Mittwoch 24 Juni 2009 21:05:50 schrieb Thomas Davie:
> This looks like Hugs defaulting to a different type to ghci,
> specifically, Hugs is defaulting to one of the high precission types
> like CReal or Rational, while ghci is defaulting to Float or Double.
>
> Bob

No, hugs is displaying with fewer digits of precision, so the round for display gives
0.x000000 which is abbreviated to 0.x, ghci displays with more digits, so the floating
point inexactness shows in the last digit.

Prelude> sin 2
0.9092974268256817
Hugs> sin 2
0.909297426825682
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: Which one is right?

Jake McArthur
In reply to this post by Linker Lin-2
Linker wrote:
> Hugs> [0,0.1..1]
> [0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]
 >
> Prelude> [0,0.1..1]
> [0.0,0.1,0.2,0.30000000000000004,0.4,0.5,0.6,0.7,0.7999999999999999,0.8999999999999999,0.9999999999999999]

Just floating point errors. In this case, you may be able to get away
with something like this:

     Prelude> map ((/10) . fromIntegral) [0..10]
     [0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0]

- Jake
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe