# Bug in Bignum.to\_s (1.8.6 only)

**URL:** <https://www.ruby-forum.com/t/bug-in-bignum-to-s-1-8-6-only/90742>\
**Category:** Ruby\
**Created:** [March 31, 2007, 7:27pm UTC](https://www.ruby-forum.com/t/bug-in-bignum-to-s-1-8-6-only/90742 "2007-03-31T19:27:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dazuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d6d6ee/32.png) [@dazuma](https://www.ruby-forum.com/u/dazuma)\
**Post date:** [March 31, 2007, 7:27pm UTC](https://www.ruby-forum.com/t/bug-in-bignum-to-s-1-8-6-only/90742/1 "2007-03-31T19:27:42Z")

</div>

Hello all,

Just making a quick note of a bug we found in Bignum.to\_s in Ruby 1.8.6,  
in case it burns anyone else.

Examples:

irb(main):001:0\> 18446744073709551615.to\_s(36) # should be  
“3w5e11264sgsf”  
=\> “w5e11264sgsf”  
irb(main):002:0\> -18446744073709551615.to\_s(8) # should be  
“-1777777777777777777777”  
=\> “11777777777777777777777”

The bug affects bases 8, 9, and 32-36 inclusive, over certain ranges of  
values depending on the base. Values immediately less than 2**64 seem to  
be particularly affected. For example, in base 36, all values from  
4738381338321616896 through 18446744073709551615 (which is 2**64-1) will  
fail.

It manifests only in Ruby 1.8.6. Ruby 1.8.5 works correctly. (It appears  
that some optimization work went a little too far.)

For anyone affected by this, I filed the bug on RubyForge, and posted a  
possible “works for me, but use at your own risk” fix to bignum.c:

[http://rubyforge.org/tracker/?func=detail&aid=9410&group\_id=426&atid=1698](http://rubyforge.org/tracker/?func=detail&aid=9410&group_id=426&atid=1698)

Cheers,  
Daniel A.  
Chief Architect, [Zoodango.com](http://Zoodango.com)

---

<div class="post-metadata">

**Author:** ![dazuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d6d6ee/32.png) [@dazuma](https://www.ruby-forum.com/u/dazuma)\
**Post date:** [March 31, 2007, 11:46pm UTC](https://www.ruby-forum.com/t/bug-in-bignum-to-s-1-8-6-only/90742/2 "2007-03-31T23:46:50Z")

</div>

On Mar 31, 1:27 pm, Daniel A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ## irb(main):002:0\> -18446744073709551615.to\_s(8) # should be that some optimization work went a little too far.)
> 
> Posted viahttp://www.ruby-forum.com/.

I have verified that the bignum bug you described also occurs in ruby  
1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]

C:\Documents and Settings\Owner\>irb  
irb(main):001:0\> 18446744073709551615.to\_s  
=\> “18446744073709551615”  
irb(main):002:0\> 18446744073709551615.to\_s(32)  
=\> “vvvvvvvvvvvv”  
irb(main):003:0\> 18446744073709551616.to\_s(32)  
=\> “g000000000000”  
irb(main):004:0\> 18446744073709551615.to\_s(36)  
=\> “w5e11264sgsf”  
irb(main):005:0\> 18446744073709551616.to\_s(36)  
=\> “3w5e11264sgsg”  
irb(main):006:0\> 18446744073709551615.to\_s(31)  
=\> “nd075ib45k86f”  
irb(main):007:0\> 18446744073709551616.to\_s(31)  
=\> “nd075ib45k86g”

---

<div class="post-metadata">

**Author:** ![dazuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d6d6ee/32.png) [@dazuma](https://www.ruby-forum.com/u/dazuma)\
**Post date:** [April 1, 2007, 3:45am UTC](https://www.ruby-forum.com/t/bug-in-bignum-to-s-1-8-6-only/90742/3 "2007-04-01T03:45:51Z")

</div>

bbiker wrote:

> I have verified that the bignum bug you described also occurs in ruby  
> 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]

Actually, to clarify, the 1.8.6 releases are the ONLY released version  
I’m aware of that exhibits the bug. (1.8.5 and earlier do not appear to  
be affected, so far as I know.) But thanks for verifying. 🙂

Daniel

---

<div class="post-metadata">

**Author:** ![dazuma](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d6d6ee/32.png) [@dazuma](https://www.ruby-forum.com/u/dazuma)\
**Post date:** [April 2, 2007, 10:59pm UTC](https://www.ruby-forum.com/t/bug-in-bignum-to-s-1-8-6-only/90742/4 "2007-04-02T22:59:45Z")

</div>

Begin forwarded message:
