Implement BigDecimal
Reported by Wilson Bilkovich | February 27th, 2008 @ 12:09 PM | in 1.0 preview
ActiveRecord uses BigDecimal to support decimal database columns. Implement enough of this to get AR running in pure ruby.
Comments and changes to this ticket
-
Wilson Bilkovich March 8th, 2008 @ 07:40 PM
- → State changed from new to open
-

Marnen Laibow-Koser April 17th, 2008 @ 05:14 PM
How far have you got with this? I'm starting to look at BigDecimal as well, and I don't want to duplicate your work. Drop me a line at marnen@marnen.org or put a note here.
-
Wilson Bilkovich April 18th, 2008 @ 10:41 AM
I was hoping to get enough Subtend support working to use an existing C extension unmodified (e.g. http://decimal.rubyforge.org ), but there are some important features missing, e.g. rb_ensure.
I've got a sketch of a pure Ruby BD that I started a while ago, but I'm going to start over on it now that we have some specs.
What is your plan?
-

Marnen Laibow-Koser April 18th, 2008 @ 11:02 AM
I was trying for a pure Ruby implementation too, but I only got a few lines of code done before I realized that you were already working on this. If you were planning to start over, should I push what I have first?
-
Wilson Bilkovich April 18th, 2008 @ 04:16 PM
Go for it. Might as well stick it in lib/bigdecimal.rb.
I can't think of a good reason not to, at least.
-

Marnen Laibow-Koser April 18th, 2008 @ 04:20 PM
That's where it was. Let me get it to a reasonable point, and I'll post the patch here since I don't have a bit yet.
-

Marnen Laibow-Koser April 18th, 2008 @ 05:37 PM
OK. Here's a patch of what I've got so far (0017-First-stab-at-BigDecimal.patch).
-
Wilson Bilkovich April 18th, 2008 @ 06:10 PM
Looks great. Just applied it.
If you give Evan your ssh public key, you can get commit access.
-

Marnen Laibow-Koser April 21st, 2008 @ 11:19 PM
Great! Got commit access now, back to work on BigDecimal.
-

Marnen Laibow-Koser April 22nd, 2008 @ 09:21 AM
Did some work on #sign, #zero?, #eql/==, and #inspect.
-

-

Marnen Laibow-Koser April 22nd, 2008 @ 12:32 PM
Changed BigDecimal to an IEEE-style significand-and-exponent implementation.
-

-

-

-

-

Marnen Laibow-Koser April 26th, 2008 @ 12:50 AM
Just did a quick implementation of #to_f, although it was so easy that I can't shake the feeling that there aren't enough specs for this function.
-

Marnen Laibow-Koser April 26th, 2008 @ 12:08 PM
Implement #exponent. Specs say that it should return 0 if it can't return a Fixnum, and I've implemented it this way, but is it really correct? MRI certainly works this way, but the docs don't mention this behavior, so are we just copying a bug in MRI?
-
Wilson Bilkovich April 26th, 2008 @ 12:19 PM
Arguably yes, but that's pretty common.
What we've done in the past is implement the 'bug' and then open a ticket on the MRI tracker for clarification/fix.
What do you think should happen when exponent can't return a Fixnum? Exception?
-

Marnen Laibow-Koser April 26th, 2008 @ 12:57 PM
Certainly not. I think if the exponent is too big for a Fixnum, it should be returned as a Bignum. In general, there's very little operational distinction between Fixnum and Bignum in Ruby. I think this is one of the great things about the language, and I see no reason at all to suddenly make that distinction in this case.
-
Wilson Bilkovich April 26th, 2008 @ 01:00 PM
Makes sense, particularly given that the maximum Fixnum is system-dependent.
-
Dirkjan Bussink April 26th, 2008 @ 01:55 PM
Currently this system dependency also causes a spec to fail on amd64. But I also agree that it shouldn't matter whether Bignums or Fixnums are used. My approach usually has been to file the bug with MRI and to write it up correctly in Rubinius.
-

Marnen Laibow-Koser April 27th, 2008 @ 12:08 AM
Implement #+ (although I'm not overly fond of the algorithm) and #coerce.
-

-

Marnen Laibow-Koser April 28th, 2008 @ 02:09 AM
After discussion with Wilson, changing BigDecimal#exponent so that it can return Bignums where necessary.
-

Marnen Laibow-Koser April 28th, 2008 @ 02:42 AM
Posting here for future reference: the major documentation for BigDecimal seems to be at http://multivac.fatburen.org/loc... , not in the RDoc.
Please Login or create a free account to add a new comment.
You can update this ticket by sending an email to from your email client. (help)
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
