[MacRuby] #1042: BigMath::log and BigMath:exp are broken
#1042: BigMath::log and BigMath:exp are broken -------------------------------------+-------------------------------------- Reporter: hghoehne@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: MacRuby 0.9 Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- {{{ macruby -ve 'require "bigdecimal/math"; include BigMath; p exp(log(BigDecimal("20.0"), 200), 200).to_f' MacRuby 0.9 (ruby 1.9.2) [universal-darwin10.0, x86_64] 16.6822127651354 }}} {{{ ruby -ve 'require "bigdecimal/math"; include BigMath; p exp(log(BigDecimal("20.0"), 200), 200).to_f' ruby 1.9.3dev (2010-12-15 trunk 30211) [x86_64-darwin10.3.0] 20.0 }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/1042> MacRuby <http://macruby.org/>
#1042: BigMath::log and BigMath:exp are broken -------------------------------------+-------------------------------------- Reporter: hghoehne@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- Changes (by lsansonetti@…): * milestone: MacRuby 0.9 => Old description:
{{{ macruby -ve 'require "bigdecimal/math"; include BigMath; p exp(log(BigDecimal("20.0"), 200), 200).to_f' MacRuby 0.9 (ruby 1.9.2) [universal-darwin10.0, x86_64] 16.6822127651354 }}}
{{{ ruby -ve 'require "bigdecimal/math"; include BigMath; p exp(log(BigDecimal("20.0"), 200), 200).to_f' ruby 1.9.3dev (2010-12-15 trunk 30211) [x86_64-darwin10.3.0] 20.0 }}}
New description: {{{ macruby -ve 'require "bigdecimal/math"; include BigMath; p exp(log(BigDecimal("20.0"), 200), 200).to_f' MacRuby 0.9 (ruby 1.9.2) [universal-darwin10.0, x86_64] 16.6822127651354 }}} {{{ ruby -ve 'require "bigdecimal/math"; include BigMath; p exp(log(BigDecimal("20.0"), 200), 200).to_f' ruby 1.9.3dev (2010-12-15 trunk 30211) [x86_64-darwin10.3.0] 20.0 }}} -- Comment: We need to investigate if it's a float precision issue or another bug. -- Ticket URL: <http://www.macruby.org/trac/ticket/1042#comment:1> MacRuby <http://macruby.org/>
#1042: BigMath::log and BigMath:exp are broken -------------------------------------+-------------------------------------- Reporter: hghoehne@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- Comment(by watson1978@…): as follow changing, It seems that MacRuby returns same result when change a SIZEOF_BDIGITS. Will it be a problem of the calculation precision? I cannot yet understand a problem definitely. {{{ #!diff diff --git a/include/ruby/defines.h b/include/ruby/defines.h index c5b144b..b88820e 100644 --- a/include/ruby/defines.h +++ b/include/ruby/defines.h @@ -83,7 +83,7 @@ void xfree(void*); #if defined(__LP64__) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060) # define BDIGIT uint64_t -# define SIZEOF_BDIGITS 8 +# define SIZEOF_BDIGITS 4 # define BDIGIT_DBL __uint128_t # define BDIGIT_DBL_SIGNED __int128_t #elif SIZEOF_INT*2 <= SIZEOF_LONG_LONG }}} {{{ $ macruby -ve 'require "bigdecimal/math"; include BigMath; p exp(log(BigDecimal("20.0"), 200), 200).to_f' MacRuby 0.9 (ruby 1.9.2) [universal-darwin10.0, x86_64] 20.0 }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/1042#comment:2> MacRuby <http://macruby.org/>
#1042: BigMath::log and BigMath:exp are broken -------------------------------------+-------------------------------------- Reporter: hghoehne@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- Comment(by hghoehne@…): Replying to [comment:1 lsansonetti@…]:
We need to investigate if it's a float precision issue or another bug. it is not a floating point issue: {{{ macruby -ve 'require "bigdecimal/math"; include BigMath; p exp(log(BigDecimal("20.0"), 200), 200).to_s("F")' MacRuby 0.9 (ruby 1.9.2) [universal-darwin10.0, x86_64] "16.682212765135445728579726056096452833034533515555079556957244320033165845148008887123174915662059112635413821896051944861145900807306986139192694748145595129342899638163206001857956245662413278649635" }}}
-- Ticket URL: <http://www.macruby.org/trac/ticket/1042#comment:3> MacRuby <http://macruby.org/>
#1042: BigMath::log and BigMath:exp are broken -------------------------------------+-------------------------------------- Reporter: hghoehne@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- Comment(by lsansonetti@…): I believe the SIZEOF_BDIGITS change to 8 was done for performance reasons, a couple years ago. However, I do not remember the exact context of this change, anymore. -- Ticket URL: <http://www.macruby.org/trac/ticket/1042#comment:4> MacRuby <http://macruby.org/>
#1042: BigMath::log and BigMath:exp are broken -------------------------------------+-------------------------------------- Reporter: hghoehne@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- Comment(by hghoehne@…): This regression was introduced with the latest import from the ruby 1.9 trunk several weeks ago. {{{ macruby_select 0.6 -ve 'require "bigdecimal"; require "bigdecimal/math"; include BigMath; p exp(log(BigDecimal("20.0"), 200), 200).to_s("E")' MacRuby version 0.6 (ruby 1.9.0) [universal-darwin10.0, x86_64] "0.19999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999995794303783081384926E2" }}} it took me some time to figure out why my numerical calculations stopped working. Unfortunately printf is broken for numeric types since version 0.4, which makes console output really hard to check. This bug makes also the results from the benchmark module unreadable. -- Ticket URL: <http://www.macruby.org/trac/ticket/1042#comment:5> MacRuby <http://macruby.org/>
#1042: BigMath::log and BigMath:exp are broken -------------------------------------+-------------------------------------- Reporter: hghoehne@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- Comment(by pthomson@…): Replying to [comment:4 lsansonetti@…]:
I believe the SIZEOF_BDIGITS change to 8 was done for performance reasons, a couple years ago. However, I do not remember the exact context of this change, anymore.
The change was to use 64-bit integers for bignum basic storage and 128-bit integers (with uint128_t), which gained around a 10-15% speed boost (and halved space usage) for bignum calculations. However, it seems to have screwed something up in BigDecimal. I'm looking into the issue, but this code is old and very weird. If nobody can figure this out, the safest way to make this work is to revert the change that made BDIGIT a uint64_t and BDIGIT_DBL a __uint128_t. -- Ticket URL: <http://www.macruby.org/trac/ticket/1042#comment:6> MacRuby <http://macruby.org/>
#1042: BigMath::log and BigMath:exp are broken -------------------------------------+-------------------------------------- Reporter: hghoehne@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- Comment(by pthomson@…): Here's a patch that removes that dubious optimization: diff --git a/include/ruby/defines.h b/include/ruby/defines.h index c5b144b..dbbec8f 100644 --- a/include/ruby/defines.h +++ b/include/ruby/defines.h @@ -81,12 +81,7 @@ void xfree(void*); #include <AvailabilityMacros.h> -#if defined(__LP64__) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060) -# define BDIGIT uint64_t -# define SIZEOF_BDIGITS 8 -# define BDIGIT_DBL __uint128_t -# define BDIGIT_DBL_SIGNED __int128_t -#elif SIZEOF_INT*2 <= SIZEOF_LONG_LONG +#if SIZEOF_INT*2 <= SIZEOF_LONG_LONG # define BDIGIT unsigned int # define SIZEOF_BDIGITS SIZEOF_INT # define BDIGIT_DBL unsigned LONG_LONG -- Ticket URL: <http://www.macruby.org/trac/ticket/1042#comment:7> MacRuby <http://macruby.org/>
#1042: BigMath::log and BigMath:exp are broken -------------------------------------+-------------------------------------- Reporter: hghoehne@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: -------------------------------------+-------------------------------------- Comment(by pthomson@…): Whoops, forgot the code tags: {{{ diff --git a/include/ruby/defines.h b/include/ruby/defines.h index c5b144b..dbbec8f 100644 --- a/include/ruby/defines.h +++ b/include/ruby/defines.h @@ -81,12 +81,7 @@ void xfree(void*); #include <AvailabilityMacros.h> -#if defined(__LP64__) && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060) -# define BDIGIT uint64_t -# define SIZEOF_BDIGITS 8 -# define BDIGIT_DBL __uint128_t -# define BDIGIT_DBL_SIGNED __int128_t -#elif SIZEOF_INT*2 <= SIZEOF_LONG_LONG +#if SIZEOF_INT*2 <= SIZEOF_LONG_LONG # define BDIGIT unsigned int # define SIZEOF_BDIGITS SIZEOF_INT # define BDIGIT_DBL unsigned LONG_LONG }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/1042#comment:8> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby