Robert Klemme
7/2/2008 2:02:00 PM
2008/7/2 Minh Tran <mtgred@gmail.com>:
> I tried with
>
> s = l.map {|e| (e**2).to_s.to_f}
>
> instead of
>
> s = l.map {|e| e**2}
>
> and it now works.
But it works only accidentally! This is likely to break soon again.
> It doesn't look very elegant though to need such kind of hacking to make
> it base operator to work as expected.
No, no, no! The operator works as expected. There is even an IEEE
standard defining how floating point math has to behave. You must
*never* rely on == when doing float math. In this case you rather
need to do either of these
- resort to decimal math with BigDecimal
- define equality as a max difference ("epsilon") between two float
values and test that
Kind regards
robert
--
use.inject do |as, often| as.you_can - without end