Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numeric#round(n, mode) - round modes are not supported #1509

Closed
deepj opened this issue Dec 7, 2018 · 11 comments

Comments

4 participants
@deepj
Copy link

commented Dec 7, 2018

At least Ruby 2.4 supports several round modes. See https://ruby-doc.org/stdlib-2.4.0/libdoc/bigdecimal/rdoc/BigDecimal.html#method-c-mode

Unfortunately, TruffleRuby triggers TypeError: Truffle doesn't have a case for the org.truffleruby.stdlib.bigdecimal.BigDecimalNodesFactory$RoundNodeFactory$RoundNodeGen node with values of type exception with any used round mode.

To reproduce:

require 'bigdecimal'

BigDecimal('1.516').round(2, :half_even)

Error:

TypeError: Truffle doesn't have a case for the org.truffleruby.stdlib.bigdecimal.BigDecimalNodesFactory$RoundNodeFactory$RoundNodeGen node with values of type  Truffle::BigDecimal(com.oracle.truffle.object.basic.DynamicObjectBasic) java.lang.Integer=2 Symbol(com.oracle.truffle.object.basic.DynamicObjectBasic)
	from (irb):5:in `round'
	from (irb):5
	from ~/.rubies/truffleruby-1.0.0-rc10/bin/irb:29:in `<main>'

@deepj deepj changed the title BigDecimal#round(n, mode) - round modes are not support BigDecimal#round(n, mode) - round modes are not supported Dec 7, 2018

@nirvdrum

This comment has been minimized.

Copy link
Member

commented Dec 7, 2018

Thanks for the report. TruffleRuby does work with some round modes. It passes all the BigDecimal#round specs. It looks like the symbol-based modes are problematic. We probably need a lookup table to translate them to integer values. It shouldn't be too difficult.

It looks like we should also improve the Ruby Spec Suite by adding more cases to test.

@nirvdrum nirvdrum added the bug label Dec 7, 2018

@nirvdrum

This comment has been minimized.

Copy link
Member

commented Dec 7, 2018

Are you sure that's supposed to work though? In MRI 2.4.x and 2.5.x, I get an ArgumentError:

> BigDecimal('1.516').round(2, :round_half_even)
ArgumentError: invalid rounding mode
	from (irb):2:in `round'
	from (irb):2
	from /home/kjmenard/.rbenv/versions/2.4.4/bin/irb:11:in `<main>'

So it looks like we might just need raise an ArgumentError with a better message.

@deepj

This comment has been minimized.

Copy link
Author

commented Dec 7, 2018

@nirvdrum You have a typo. It's half_even, not round_half_even :)

@deepj

This comment has been minimized.

Copy link
Author

commented Dec 7, 2018

screenshot 2018-12-07 at 23 43 21

@nirvdrum

This comment has been minimized.

Copy link
Member

commented Dec 7, 2018

Right you are. I messed up translating BigDecimal::ROUND_HALF_EVEN to a symbol. Thanks for pointing that out.

@chrisseaton

This comment has been minimized.

Copy link
Member

commented Jan 30, 2019

The three rounding issues #1509, #1510, #1514.

@deepj

This comment has been minimized.

Copy link
Author

commented Feb 23, 2019

@eregon @chrisseaton Could this be a priority for RC14, please? In fact, this is one of issues why I started to report bugs in TruffleRuby. I'd like to run a quite trivial script importing exchange rates on TruffleRuby one day :)

@chrisseaton

This comment has been minimized.

Copy link
Member

commented Apr 3, 2019

Sorry this hasn't managed to go into RC15, but we have a lot of time scheduled this month to look at this issue backlog.

@chrisseaton chrisseaton changed the title BigDecimal#round(n, mode) - round modes are not supported Numeric#round(n, mode) - round modes are not supported Apr 8, 2019

@chrisseaton

This comment has been minimized.

Copy link
Member

commented Apr 8, 2019

Working on this now.

@chrisseaton chrisseaton self-assigned this Apr 8, 2019

@chrisseaton

This comment has been minimized.

Copy link
Member

commented Apr 8, 2019

Fix for this done and on the way.

@chrisseaton

This comment has been minimized.

Copy link
Member

commented Apr 9, 2019

Fixed in 0beec8a.

@chrisseaton chrisseaton closed this Apr 9, 2019

@eregon eregon added this to the 1.0.0-rc16 milestone Apr 10, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.