9.3 - (2 * 4.5) = 0.3007
I expected 0.3
?
--
Иван Драголов
dragolov.net
GSM: 0888 63 19 46
GSM за SMS: 0878 82 83 93
facebook.com/ivan.dragolov
twitter.com/dragolov
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
Fun with floating point!
# ghci
GHCi, version 7.4.2: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude 9223372036854775807.0 == 9223372036854775808
True
This is a rounding error. It will happen in any language due to the
imprecision of floats; for example, using Ruby:
$ irb
1.9.3-p286 :001 9.3 - (2 * 4.5)
= 0.3007
1.9.3-p286 :001 ^D
$
Read this:
http://floating-point-gui.de/
On Wed, Jan 16, 2013 at 7:25 AM, ivan dragolov
This may be of interest if you want full-precision decimals:
http://www.haskell.org/haskellwiki/Libraries_and_tools/Mathematics#Decimal_numbers
On Wed, Jan 16, 2013 at 7:30 AM, Patrick Mylund Nielsen
hask...@patrickmylund.com wrote:
Fun with floating point!
# ghci
GHCi, version 7.4.2:
Prelude import Data.Ratio
Prelude Data.Ratio 93 % 10 - (2 * 9 % 2)
3 % 10
Floating point sucks, avoid it if you can.
Thanks
Tom Davie
On 16 Jan 2013, at 13:25, ivan dragolov i...@dragolov.net wrote:
9.3 - (2 * 4.5) = 0.3007
I expected 0.3
?
--
Иван Драголов
You should read
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.22.6768
If you want to be efficient with floats. Language independent.
Luis
On Wed, Jan 16, 2013 at 2:25 PM, ivan dragolov i...@dragolov.net wrote:
9.3 - (2 * 4.5) = 0.3007
I expected 0.3
?
--
Иван
On Wednesday 16 January 2013, 15:25:15, ivan dragolov wrote:
9.3 - (2 * 4.5) = 0.3007
I expected 0.3
?
Prelude Text.FShow.RealFloat FD 9.3
9.300710542735760100185871124267578125
The closest Double to 9.3 is somewhat larger than 9.3. Since the first two
significant
On 16/01/2013 13:55, Tom Davie wrote:
Prelude import Data.Ratio
Prelude Data.Ratio 93 % 10 - (2 * 9 % 2)
3 % 10
Or even just a type annotation:
Prelude (9.3 - (2 * 4.5)) :: Rational
3 % 10
On 16 Jan 2013, at 13:25, ivan dragolov i...@dragolov.net
mailto:i...@dragolov.net wrote:
9.3 - (2
On 13-01-16 10:04 AM, Luis Cabellos wrote:
You should read
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.22.6768
If you want to be efficient with floats. Language independent.
And also http://floating-point-gui.de/
___
Haskell-Cafe
Welcome to IEEE floating point math!
Wikipedia has a good article on the specification. If you want exact
fractional numbers for your own purposes, there are a number of ways around
the limits of floats.
Rational will represent numbers internally as fractions, and still allow
you to use the same
10 matches
Mail list logo