Skip to content

[Truffle] Add special values of BigDecimal#2985

Merged
pitr-ch merged 6 commits intojruby:masterfrom
pitr-ch:bigdecimal
Jun 1, 2015
Merged

[Truffle] Add special values of BigDecimal#2985
pitr-ch merged 6 commits intojruby:masterfrom
pitr-ch:bigdecimal

Conversation

@pitr-ch
Copy link
Copy Markdown
Member

@pitr-ch pitr-ch commented May 25, 2015

not ready for merge

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put @TruffleBoundary on this. The v.toString() is not going to compile well.

@chrisseaton
Copy link
Copy Markdown
Contributor

Looks great!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this work? Is toString() redefined somehow for BigDecimal?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you want is really v as a RubyString, right?
Then it makes sense to call toString() although it is not very efficient (good enough for now for debug output like this).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh I missed the guard with Chris' note. I think it's clearer to have RubyString as the argument type in this case.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RubyString#toString is the exception to that note. What we don't want to do is things like to_s as toString or hash as hatched - we don't want to map the Ruby API into the Java API like that (because those methods don't give us anywhere to store state for optimisation).

@pitr-ch pitr-ch force-pushed the bigdecimal branch 2 times, most recently from 0bdce40 to 72a6979 Compare May 28, 2015 17:03
@pitr-ch
Copy link
Copy Markdown
Member Author

pitr-ch commented May 28, 2015

I had to add coerce specializations to other numerical classes, to make > work. If that's ok I'll finish rest of the comparisons and operations with special values to make this merge-able.

@chrisseaton
Copy link
Copy Markdown
Contributor

Looks good. Do you mean you'll add specialisations to classes like Float for comparing against BigDecimal? That doesn't sound right - as in MRI and Rubinius BigDecimal is a C extension and can't modify the other class methods like that. Look at the way Rational is handled - I think in some cases Fixnum > BigDecimal is done as BigDecimal <= Fixnum in some way.

@eregon
Copy link
Copy Markdown
Member

eregon commented May 29, 2015

Yes coerce should be used for these cases and should already be handled in Fixnum/Bignum/Float.

@eregon
Copy link
Copy Markdown
Member

eregon commented May 29, 2015

But I think @pitr-ch meant BigDecimal < Float for instance (in <=>), in which case it's fine to optimize that direction and probably even expected (to not need to call coerce).

@pitr-ch
Copy link
Copy Markdown
Member Author

pitr-ch commented May 29, 2015

I mean changes like https://github.com/jruby/jruby/pull/2985/files#diff-03ee9d17196ada218812f3319c5c3f0c. It was either raising always an exception or missing completely. So for 1 > BigDecimal("0.5") it would raise argument error or missing node for FixnumNodes.Greater(int,BigDecimal). With this changes, it calls coerce on BigDecimal so 1 > BigDecimal("0.5") is translated to BigDecimal(1) > BigDecimal("0.5") and evaluated successfully. The other way BigDecimal("0.5") > 1 is done usually ending up in @Specialization(guards = "isNormal(a)") public int compare(RubyBasicObject a, int b) { return compareBigDecimal(a, getBigDecimalValue(b)); }

@eregon
Copy link
Copy Markdown
Member

eregon commented May 29, 2015

great!

@pitr-ch
Copy link
Copy Markdown
Member Author

pitr-ch commented Jun 1, 2015

This PR can be merged, assuming that I can ignore the two failing jobs on Travis.

Comment thread lib/ruby/truffle/truffle/bigdecimal.rb Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BigDecimal() should raise so that implementation should be fine.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, thanks, I'll remove it.

@chrisseaton
Copy link
Copy Markdown
Contributor

Great - yeah those failures aren't our problem - do you want to merge it yourself? Might as well rebase instead of creating a merge commit.

@chrisseaton chrisseaton added this to the truffle-dev milestone Jun 1, 2015
@eregon
Copy link
Copy Markdown
Member

eregon commented Jun 1, 2015

(it might be hard to rebase with the renames etc)

@pitr-ch
Copy link
Copy Markdown
Member Author

pitr-ch commented Jun 1, 2015

Right I can push directly now :) I've already rebased this PR in the morning so I should not be more than few commits behind, rebase should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants