From: Shri Borde Date: 2009-02-26T06:09:00+09:00 Subject: [ruby-core:22504] ArgumentError when comparing a Fixnum with BigDecimal("NaN") --_000_710DF26F214D2B4BB94287123FFE980A2E0CF47ADBNAEXMSGC104re_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Ruby 1.8.6 and 1.9 both raise an ArgumentError when comparing a Fixnum with= BigDecimal("NaN"), whereas they do not when comparing a Fixnum with a Floa= t NaN. Is there a design reason why this is so? Or is it just what it is. Y= ou would want Float and BigDecimal to be as similar to each other as possib= le, and this behavior seems arbitrary, requiring the user to think of both = behaviors when doing comparison of floating point values (which could be ei= ther Float of BigDecimal). irb(main):001:0> require "bigdecimal" =3D> true irb(main):002:0> 4 < BigDecimal("5").to_f =3D> true irb(main):003:0> 4 < BigDecimal("5") =3D> true irb(main):005:0> 4 < BigDecimal("NaN").to_f =3D> false irb(main):006:0> 4 < BigDecimal("NaN") ArgumentError: comparison of Fixnum with BigDecimal failed from (irb):6:in `<' from (irb):6 from :0 Thanks, Shri --_000_710DF26F214D2B4BB94287123FFE980A2E0CF47ADBNAEXMSGC104re_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable

Ruby 1.8.6 and 1.9 both raise an ArgumentError when comparing a Fixnum with BigDecimal("NaN"), whereas they do not wh= en comparing a Fixnum with a Float NaN. Is there a design reason why this is s= o? Or is it just what it is. You would want Float and BigDecimal to be as simi= lar to each other as possible, and this behavior seems arbitrary, requiring the user to think of both behaviors when doing comparison of floating point val= ues (which could be either Float of BigDecimal).

 

irb(main):001:0> require "bigdecimal"

=3D> true

irb(main):002:0> 4 < BigDecimal("5").t= o_f

=3D> true

irb(main):003:0> 4 < BigDecimal("5")

=3D> true

 

irb(main):005:0> 4 < BigDecimal("NaN")= .to_f

=3D> false

irb(main):006:0> 4 < BigDecimal("NaN")=

ArgumentError: comparison of Fixnum with BigDecimal failed

        from (irb):= 6:in `<'

        from (irb):= 6

        from :0

 

Thanks,

Shri

 

--_000_710DF26F214D2B4BB94287123FFE980A2E0CF47ADBNAEXMSGC104re_--