# > x = 1.0.to_dec / 3.0.to_dec
# > y = x + x + x
# > y == 1.0.to_dec # => false
hmm, i thought this was already answered by others.. gotta check..
irb(main):023:0* x=1.0.to_dec/3.0.to_dec
=> #<BigDecimal:b7e45e14,'0.3333333333 333333E0',16(24)>
irb(main):024:0> x+x+x == 1.0.to_dec
=> true
kind regards -botp
···
From: Michael Ulm [mailto:michael.ulm@isis-papyrus.com]
Stefan Rusterholz wrote:
Marshal.dump on the other hand is serializing, of course you don't want
your floats truncated just because you're serializing.
Excuse me -- does Marshal.dump serialize floats in text or in binary?
I'd hope it was binary. A *YAML* serializer would have to do it in text,
although they could obviously encode binary in base 64 or hex.
Peña wrote:
From: Michael Ulm [mailto:michael.ulm@isis-papyrus.com] # > x = 1.0.to_dec / 3.0.to_dec
# > y = x + x + x
# > y == 1.0.to_dec # => false
hmm, i thought this was already answered by others.. gotta check..
irb(main):023:0* x=1.0.to_dec/3.0.to_dec
=> #<BigDecimal:b7e45e14,'0.3333333333 333333E0',16(24)>
irb(main):024:0> x+x+x == 1.0.to_dec
=> true
Strange, I tested this on two different machines and both gave false
to your last expression. Did you modify BigDecimal#== ?
Regards,
Michael
M. Edward (Ed) Borasky wrote:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Stefan Rusterholz wrote:
Marshal.dump on the other hand is serializing, of course you don't want your floats truncated just because you're serializing.
Excuse me -- does Marshal.dump serialize floats in text or in binary?
I'd hope it was binary. A *YAML* serializer would have to do it in text,
although they could obviously encode binary in base 64 or hex.
The number itself is in acsii:
irb(main):006:0> x = 1.234e120
=> 1.234e+120
irb(main):007:0> Marshal.dump(x)
=> "\004\bf\0371.2340000000000001e+120\000@`"
Maybe this is for compatibility, in case ruby is running on some oddball system without the standard float formats?
···
--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
# > From: Michael Ulm [mailto:michael.ulm@isis-papyrus.com]
# > irb(main):023:0* x=1.0.to_dec/3.0.to_dec
# > => #<BigDecimal:b7e45e14,'0.3333333333 333333E0',16(24)>
# > irb(main):024:0> x+x+x == 1.0.to_dec
# > => true
···
From: Michael Ulm [mailto:michael.ulm@isis-papyrus.com]
#
# Strange, I tested this on two different machines and both gave false
# to your last expression. Did you modify BigDecimal#== ?
yes. i just used one of the codes posted here.. not sure if it was even your suggested code though. nonetheless, what were you expecting? that 1/3 can be represented exactly in decimal? 
but i really want a way to override float literals, so i do not litter all those to_decs :)) Of course, floats has a lot of merits, but it gives too many surprises fr just a few dec samples. businesswise, it has little use.
kind regards -botp