A bug in BigDecimal?

Hi,

I was doing some computations JFF when I found
this :

···

========================
require 'bigdecimal'
BigDecimal.limit(1000)

# ok => 2.718...
n = 1_000_000_000;
((BigDecimal.new(n) + BigDecimal.new(1)) / BigDecimal.new(n))**BigDecimal.new(n)

# gives infinity, not good, it should converge to value E or rise
# an exception if it can't compute it.
n = 1_000_000_000_0;
((BigDecimal.new(n) + BigDecimal.new(1)) / BigDecimal.new(n))**BigDecimal.new(n)

I am running Ruby 2.4.2, do you observe the same behaviour
in your release?

Bye
Nicola

Good morning,

seems to be working perfectly here.

=> 0.271828182709990432237664402386033286282501...

→ irb -v
irb 0.9.6(09/06/30)
→ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]

···

On Tue, Nov 21, 2017 at 8:36 AM, Nicola Mingotti <nmingotti@gmail.com> wrote:

Hi,

I was doing some computations JFF when I found
this :

========================
require 'bigdecimal'
BigDecimal.limit(1000)

# ok => 2.718...
n = 1_000_000_000;
((BigDecimal.new(n) + BigDecimal.new(1)) / BigDecimal.new(n))**BigDecimal
.new(n)

# gives infinity, not good, it should converge to value E or rise
# an exception if it can't compute it.
n = 1_000_000_000_0;
((BigDecimal.new(n) + BigDecimal.new(1)) / BigDecimal.new(n))**BigDecimal
.new(n)

I am running Ruby 2.4.2, do you observe the same behaviour
in your release?

Bye
Nicola

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

--
joe gain

jacob-burckhardt-str. 16
78464 konstanz
germany

+49 (0)7531 60389

(...otherwise in ???)

Umm, very suspicious, my configuration is similar.
But I restarted the irb, redone the computation, and still it fails.
It could be because I am in a 32 bit system. I report my config in details.

$> irb -v
irb 0.9.6(09/06/30)

$> ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [i686-linux]

$> file `which ruby`
/usr/local/bin/ruby: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=4155341292883d00fd56de2c46abb3f23151c640, not stripped

$> uname -a
Linux foo 3.16.0-4-686-pae #1 SMP Debian 3.16.43-2+deb8u5 (2017-09-19) i686 GNU/Linux

$> cat /etc/debian_version
8.9

I am running Debian as a guest a VMWare virtual machine with OSX host.

bye
Nicola

···

On 21/11/2017 08:45, Joe Gain wrote:

Good morning,

seems to be working perfectly here.

=> 0.271828182709990432237664402386033286282501...

→ irb -v
irb 0.9.6(09/06/30)
→ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]

On Tue, Nov 21, 2017 at 8:36 AM, Nicola Mingotti <nmingotti@gmail.com > <mailto:nmingotti@gmail.com>> wrote:

    Hi,

    I was doing some computations JFF when I found
    this :

    ========================
    require 'bigdecimal'
    BigDecimal.limit(1000)

    # ok => 2.718...
    n = 1_000_000_000;
    ((BigDecimal.new(n) + BigDecimal.new(1)) /
    BigDecimal.new(n))**BigDecimal.new(n)

    # gives infinity, not good, it should converge to value E or rise
    # an exception if it can't compute it.
    n = 1_000_000_000_0;
    ((BigDecimal.new(n) + BigDecimal.new(1)) /
    BigDecimal.new(n))**BigDecimal.new(n)
    ========================

    I am running Ruby 2.4.2, do you observe the same behaviour
    in your release?

    Bye
    Nicola

    Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
    <mailto:ruby-talk-request@ruby-lang.org>?subject=unsubscribe>
    <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk
    <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>>

--
joe gain

jacob-burckhardt-str. 16
78464 konstanz
germany

+49 (0)7531 60389

(...otherwise in ???)

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>

I made a second experiment in a BeagleBone Black
which is an ARM. Still, the system is 32 bit and I get the same wrong result.

This time the Ruby I am using comes from the Debian dist. package.

So, I think there is a problem in BigDecimal (or some underlying library)

-------- specs of this machine

···

-----------------------------------------------
#> uname -a
Linux bbtest 4.4.91-ti-r133 #1 SMP Tue Oct 10 05:18:08 UTC 2017 armv7l GNU/Linux

#> cat /etc/debian_version
9.2

#> cat /etc/dogtag
BeagleBoard.org Debian Image 2017-10-10

#> ruby -v
ruby 2.3.3p222 (2016-11-21) [arm-linux-gnueabihf]

#> irb -v
irb 0.9.6(09/06/30)

#> file /usr/bin/ruby2.3
/usr/bin/ruby2.3: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=755336ae6067230d52c894c8d91ec82f6402d3ab, stripped
-------------------------------------------------------------------------------------

bye
Nico

On 21/11/2017 08:45, Joe Gain wrote:

Good morning,

seems to be working perfectly here.

=> 0.271828182709990432237664402386033286282501...

→ irb -v
irb 0.9.6(09/06/30)
→ ruby -v
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]

On Tue, Nov 21, 2017 at 8:36 AM, Nicola Mingotti <nmingotti@gmail.com > <mailto:nmingotti@gmail.com>> wrote:

    Hi,

    I was doing some computations JFF when I found
    this :

    ========================
    require 'bigdecimal'
    BigDecimal.limit(1000)

    # ok => 2.718...
    n = 1_000_000_000;
    ((BigDecimal.new(n) + BigDecimal.new(1)) /
    BigDecimal.new(n))**BigDecimal.new(n)

    # gives infinity, not good, it should converge to value E or rise
    # an exception if it can't compute it.
    n = 1_000_000_000_0;
    ((BigDecimal.new(n) + BigDecimal.new(1)) /
    BigDecimal.new(n))**BigDecimal.new(n)
    ========================

    I am running Ruby 2.4.2, do you observe the same behaviour
    in your release?

    Bye
    Nicola

    Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org
    <mailto:ruby-talk-request@ruby-lang.org>?subject=unsubscribe>
    <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk
    <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>>

--
joe gain

jacob-burckhardt-str. 16
78464 konstanz
germany

+49 (0)7531 60389

(...otherwise in ???)

Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>