# Numeric stuff

**URL:** <https://www.ruby-forum.com/t/numeric-stuff/126468>\
**Category:** IronRuby\
**Created:** [January 18, 2008, 3:25pm UTC](https://www.ruby-forum.com/t/numeric-stuff/126468 "2008-01-18T15:25:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![editkid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/977dab/32.png) [@editkid](https://www.ruby-forum.com/u/editkid)\
**Post date:** [January 18, 2008, 3:25pm UTC](https://www.ruby-forum.com/t/numeric-stuff/126468/1 "2008-01-18T15:25:19Z")

</div>

Here is a patch for the rest of the number stuff. The main patch  
(NumericBits.patch) modifies the following files:

Numeric.cs: minor fixes and documentation

FixnumOps.cs and BignumOps.cs: minor fixes and improvements

FloatOps.cs: complete implementation

Integer.cs: complete implementation (I know Jb Evain beat me to it on  
the  
upto/downto front but I hope that, without stealing his thunder, this is  
a  
complete implantation of the methods).

Precision.cs: complete implementation

LibrarySites.cs: Added a couple of extra sites and fixed a bug with abs  
site.

Of course you have to regenerate Initializer.Generated.cs to get it to  
compile.

I have also added a file (BignumLiteral.patch) which "turns on"the  
Bignum  
literal in IronRuby. It affects the following files:

BigInteger.cs: Adds a new Create method

Tokenizer.cs : Calls the BigInteger.Create method.

I appreciate that this is not going to get included in the build but I  
thought I would provide it for people who want to get into Bignums (or  
get  
most of the specs to actually run) before the official fix for this is  
released.

To keep things simple I have not added the many unit tests (specs) that  
I  
have written for these classes, even though these have probably taken  
75% of  
the time spent. This is because the old builtin specs are being  
deprecated  
and it seems more sensible to try and push these specs into the Rubinius  
test suite instead. Hopefully Charles Nutter will be pleased!

Finally if you do run the specs there will be a number of failures:

The match method has not yet been defined so any specs that check for  
runtime type or version number will fail.

I believe that these are primarily due to issues with the  
Ruby.Runtime.Converter class and Ruby.Runtime.StringFormatter. I will  
push  
through bug reports on RubyForge for these soon.

There are also some issues with IronRuby throwing FloatDomainError where  
CRuby throws RangeError. I have not convinced myself whether this is an  
issue inside Protocols or FloatOps so I have left them as they are for  
now.  
Ironically, FloatDomainError derives from RangeError so it would not  
make  
much difference in a real application anyway.

By the way, there is an interesting issue with Float#to\_s. It appears  
that  
on Windows you get an extra zero in the exponent in both CRuby and  
IronRuby,  
which given the Rubinius specs doesn’t appear on other platforms:  
1.4e046  
rather than 1.4e46.

Finally, all the Rubinius specs think that 0x40000000 is a Bignum but in  
IronRuby (and JRuby) this is Fixnum. Therefore most of the bignum  
specs  
are actually testing against Fixnum instead of Bignum. So the Bignum  
functionality is not being given a work-out and more annoyingly, where  
there  
are different semantics between Fixnum and Bignum, the specs fail (i.e.  
Fixnum#div vs Bignum#div).

Looking forward to the feedback.

Regards,

Pete

---

<div class="post-metadata">

**Author:** ![editkid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/977dab/32.png) [@editkid](https://www.ruby-forum.com/u/editkid)\
**Post date:** [January 18, 2008, 4:27pm UTC](https://www.ruby-forum.com/t/numeric-stuff/126468/2 "2008-01-18T16:27:22Z")

</div>

Peter Bacon D.:

> Here is a patch for the rest of the number stuff.

Thanks for sending this in, Peter! We’ll review and get comments back  
out soon.

> Finally, all the Rubinius specs think that 0x40000000 is a Bignum but  
> in IronRuby (and JRuby) this is Fixnum. Therefore most of the bignum  
> specs are actually testing against Fixnum instead of Bignum. So the  
> Bignum functionality is not being given a work-out and more  
> annoyingly, where there are different semantics between Fixnum and  
> Bignum, the specs fail (i.e. Fixnum#div vs Bignum#div).

This is a known problem in JRuby as well since they use 64 bit longs to  
represent Fixnums. Since the size of a Fixnum is a platform dependent  
thing (have no idea how 64 bit Ruby behaves) the specs are wrong and  
need to be fixed. I’ve cc’d Brian F., the spec owner on this.

Thanks,  
-John
