[MacRuby] #584: BigMath.sqrt always returns NaN
#584: BigMath.sqrt always returns NaN -------------------------------------+-------------------------------------- Reporter: hghoehne@… | Owner: lsansonetti@… Type: defect | Status: new Priority: major | Milestone: MacRuby 0.5 Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- require "bigdecimal" require "bigdecimal/math" four = BigDecimal("4") puts BigMath.sqrt(four, 10) NaN -- Ticket URL: <http://www.macruby.org/trac/ticket/584> MacRuby <http://macruby.org/>
#584: BigMath.sqrt always returns NaN -------------------------------------+-------------------------------------- Reporter: hghoehne@… | Owner: lsansonetti@… Type: defect | Status: new Priority: major | Milestone: MacRuby 0.5 Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- Comment(by maxime.curioni@…): The problem seems to be more of a general difference between ruby 1.8 and ruby 1.9, than a MacRuby-specific problem: # ruby -v => ruby 1.8.7 (2008-08-11 patchlevel 72) [universal-darwin10.0] {{{
require 'bigdecimal/math' => true BigMath.methods.include? :sqrt => false }}}
# ruby -v => ruby 1.9.2dev (2010-01-26 trunk 26419) [i386-darwin10.2.0] {{{
require 'bigdecimal/math' => true BigMath.methods.include? :sqrt => false }}}
#macruby -v => MacRuby version 0.6 (ruby 1.9.0) [universal-darwin10.0, i386] {{{
require 'bigdecimal/math' => true BigMath.methods.include? :sqrt => false }}}
Since we are aiming to match Ruby 1.9's behavior, this is definitely something that should be fixed. In the mean time, users can go around the problem by:[[BR]] - either adding 'include BigMath' after "require 'bigdecimal/math'"[[BR]] - or using the instance method #sqrt on the object (i.e. "four.sqrt(10)")[[BR]] -- Ticket URL: <http://www.macruby.org/trac/ticket/584#comment:1> MacRuby <http://macruby.org/>
#584: BigMath.sqrt always returns NaN -------------------------------------+-------------------------------------- Reporter: hghoehne@… | Owner: lsansonetti@… Type: defect | Status: new Priority: major | Milestone: MacRuby 0.5 Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- Comment(by maxime.curioni@…): Sorry about the misprint for ruby 1.9: # ruby -v => ruby 1.9.2dev (2010-01-26 trunk 26419) [i386-darwin10.2.0] {{{
require 'bigdecimal/math' => true BigMath.methods.include? :sqrt => true }}}
-- Ticket URL: <http://www.macruby.org/trac/ticket/584#comment:2> MacRuby <http://macruby.org/>
#584: BigMath.sqrt always returns NaN -------------------------------------+-------------------------------------- Reporter: hghoehne@… | Owner: lsansonetti@… Type: defect | Status: new Priority: major | Milestone: MacRuby 0.5 Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- Comment(by hghoehne@…): Replying to [comment:2 maxime.curioni@…]: The "correct" way to check for sqrt in 1.87, 1.92 and macruby is {{{ BigDecimal.method_defined? :sqrt }}} which returns true in ruby 1.87, ruby 1.92 and macruby. In 1.87 and macruby you can call {{{ result = BigDecimal.sqrt(..,..) }}} That doesn't work in 1.92. Here you call {{{ result = BigMath.sqrt(..,..) }}} which also works in 1.87 and macruby. But {{{ BigMath.method_defined? :sqrt }}} will return false in ruby 1.92, but true in 1.87 and macruby. {{{ include BigMath result = sqrt(..,..) }}} is working in all versions. This small changes are definitely confusing and probably a bug in ruby 1.92. But BigMath.sqrt is defined in macruby: calling sqrt doesn't raise a NoMethodError, but returns NaN for any BigDecimal object. -- Ticket URL: <http://www.macruby.org/trac/ticket/584#comment:3> MacRuby <http://macruby.org/>
#584: BigMath.sqrt always returns NaN -------------------------------------+-------------------------------------- Reporter: hghoehne@… | Owner: lsansonetti@… Type: defect | Status: new Priority: major | Milestone: Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- Changes (by martinlagardette@…): * milestone: MacRuby 0.5 => Old description:
require "bigdecimal" require "bigdecimal/math" four = BigDecimal("4") puts BigMath.sqrt(four, 10) NaN
New description: {{{ #!ruby require "bigdecimal" require "bigdecimal/math" four = BigDecimal("4") puts BigMath.sqrt(four, 10) #=> NaN }}} -- Comment: I commited an updated version of bigdecimal/math with r4202, but for some reason, get NaN when I include both `bigdecimal` and `bigdecimal/math`, but not if I include any of them: {{{ $> macruby -r bigdecimal/math -e 'p BigDecimal.new("2").sqrt(10)' #<BigDecimal:2000f15a0,'0.1414213562 3730950488 016887185E1',32(32)> $> macruby -r bigdecimal -e 'p BigDecimal.new("2").sqrt(10)' #<BigDecimal:2000e0aa0,'0.1414213562 3730950488 016887185E1',32(32)> $> macruby -r bigdecimal -r bigdecimal/math -e 'p BigDecimal.new("2").sqrt(10)' #<BigDecimal:2000d0660,'NaN',4(32)> }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/584#comment:4> MacRuby <http://macruby.org/>
#584: BigMath.sqrt always returns NaN -------------------------------------+-------------------------------------- Reporter: hghoehne@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: major | Milestone: MacRuby 0.7 Component: MacRuby | Resolution: fixed Keywords: | -------------------------------------+-------------------------------------- Changes (by lsansonetti@…): * status: new => closed * resolution: => fixed * milestone: => MacRuby 0.7 Comment: This seems to work for me (as of r4401): {{{ $ /usr/local/bin/macruby -r bigdecimal/math -e 'p BigDecimal.new("2").sqrt(10)' #<BigDecimal:4004cb500,'0.1414213562 3730950488 016887185E1',32(32)> $ /usr/local/bin/macruby -r bigdecimal -e 'p BigDecimal.new("2").sqrt(10)' #<BigDecimal:4004c7480,'0.1414213562 3730950488 016887185E1',32(32)> $ /usr/local/bin/macruby -r bigdecimal -r bigdecimal/math -e 'p BigDecimal.new("2").sqrt(10)' #<BigDecimal:4004cb820,'0.1414213562 3730950488 016887185E1',32(32)> }}} Please re-open if you still see the problem with trunk. -- Ticket URL: <http://www.macruby.org/trac/ticket/584#comment:5> MacRuby <http://macruby.org/>
#584: BigMath.sqrt always returns NaN -------------------------------------+-------------------------------------- Reporter: hghoehne@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: major | Milestone: MacRuby 0.7 Component: MacRuby | Resolution: fixed Keywords: | -------------------------------------+-------------------------------------- Comment(by martinlagardette@…): This looks fixed indeed :-) -- Ticket URL: <http://www.macruby.org/trac/ticket/584#comment:6> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby