Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: f7abd923b097
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: bbdcc94cc8c1
Choose a head ref
  • 16 commits
  • 22 files changed
  • 2 contributors

Commits on Jun 24, 2015

  1. [Truffle] BigDecimal: add handling of ExceptionMode, Limit, Rounding

    * Add coerce and cast node for BigDecimal
    * Add create node (single entry point for BigDecimal creation)
    * BigDecimalCoreMethodNode has helpers for: BigDecimal creation, getLimit
      getRoudingMode.
    * BigDecimalCoerceNode is used to reduce number of Specializations in operation
      nodes
    * Operation nodes have beter structure and share code
    * add, sub, mult, div are handling special values
    * All operations respect fiber local ExceptionMode, Limit, Rounding settings
    pitr-ch committed Jun 24, 2015
    Copy the full SHA
    47a4ace View commit details
  2. Copy the full SHA
    41c38b2 View commit details
  3. Copy the full SHA
    b010bae View commit details
  4. Copy the full SHA
    8caa445 View commit details
  5. [Truffle] BigDecimal: fix rouding edge case

    when rounding to a digit before the first one
    pitr-ch committed Jun 24, 2015
    Copy the full SHA
    a583a64 View commit details
  6. Copy the full SHA
    c9c619a View commit details
  7. Copy the full SHA
    2f6bbe8 View commit details
  8. Copy the full SHA
    2d85ebf View commit details
  9. Copy the full SHA
    cec8bb4 View commit details
  10. [Truffle] remove neverPartOfCompilation in unprofiled branches

    It could lead to failing compilation of the methods.
    pitr-ch committed Jun 24, 2015
    Copy the full SHA
    b01a26a View commit details
  11. Copy the full SHA
    ebd9654 View commit details

Commits on Jun 25, 2015

  1. Copy the full SHA
    2e47e93 View commit details
  2. [Truffle] BigDecimal: do not round when not neccessary

    It was leading in some cases to computation of BigInteger.TEN.pow(100000000)
    which takes quite some time.
    pitr-ch committed Jun 25, 2015
    Copy the full SHA
    6454405 View commit details
  3. Copy the full SHA
    5c2ad52 View commit details
  4. [Truffle] FindBugs: fixes

    pitr-ch committed Jun 25, 2015
    Copy the full SHA
    c23eaf8 View commit details
  5. Merge pull request #3077 from pitr-ch/bigdecimal

    [Truffle] BigDecimal: add handling of ExceptionMode, Limit, Rounding
    Petr Chalupa committed Jun 25, 2015
    Copy the full SHA
    bbdcc94 View commit details
120 changes: 116 additions & 4 deletions lib/ruby/truffle/truffle/bigdecimal.rb
Original file line number Diff line number Diff line change
@@ -6,10 +6,68 @@ class Truffle::BigDecimal < Numeric
SIGN_NEGATIVE_INFINITE = -3
SIGN_NEGATIVE_FINITE = -2
SIGN_NEGATIVE_ZERO = -1
SIGN_NaN = 0
SIGN_POSITIVE_ZERO = 1
SIGN_POSITIVE_FINITE = 2
SIGN_POSITIVE_INFINITE = 3
SIGN_NaN = 0
SIGN_POSITIVE_ZERO = 1
SIGN_POSITIVE_FINITE = 2
SIGN_POSITIVE_INFINITE = 3

EXCEPTION_INFINITY = 1
EXCEPTION_OVERFLOW = 1
EXCEPTION_NaN = 2
EXCEPTION_UNDERFLOW = 4
EXCEPTION_ZERODIVIDE = 16
EXCEPTION_ALL = 255
ROUND_MODE = 256

ROUND_UP = 1
ROUND_DOWN = 2
ROUND_HALF_UP = 3
ROUND_HALF_DOWN = 4
ROUND_CEILING = 5
ROUND_FLOOR = 6
ROUND_HALF_EVEN = 7

def self.mode(key, value = nil)
raise ArgumentError, 'requires key to be Fixnum' unless key.is_a? Fixnum
if key == ROUND_MODE
Thread.current[:'BigDecimal.rounding_mode'] ||= 3
if value
Thread.current[:'BigDecimal.rounding_mode'] = value
else
Thread.current[:'BigDecimal.rounding_mode']
end
else
Thread.current[:'BigDecimal.exception_mode'] ||= 0
case value
when true
Thread.current[:'BigDecimal.exception_mode'] |= key
return value
when false
Thread.current[:'BigDecimal.exception_mode'] &= ~key
return value
when nil
# FIXME (pitr 20-Jun-2015): CRuby always returns BigDecimal.exception_mode internal value ignoring the key
return Thread.current[:'BigDecimal.exception_mode'] & key == key
end
end
end

def self.limit(limit = nil)
Thread.current[:'BigDecimal.precision_limit'] ||= 0
if limit
raise ArgumentError, 'requires key to be Fixnum' unless limit.is_a? Fixnum
old = Thread.current[:'BigDecimal.precision_limit']
Thread.current[:'BigDecimal.precision_limit'] = limit
old
else
Thread.current[:'BigDecimal.precision_limit']
end
end

# TODO (pitr 20-jun-2015): remove when lazy setup is added
def self.name
'BigDecimal'
end

def ==(o)
(self <=> o) == 0 rescue false
@@ -69,6 +127,60 @@ def split
sign = -1 if sign < -1
[sign, unscaled, 10, exponent]
end

def floor(digit = nil)
if digit
round digit, ROUND_FLOOR
else
rounded = round 0, ROUND_FLOOR
integer = rounded.to_i
return rounded == integer ? integer : rounded
end
end

def truncate(digit = nil)
if finite?
if digit
round digit, ROUND_DOWN
else
rounded = round 0, ROUND_DOWN
integer = rounded.to_i
return rounded == integer ? integer : rounded
end
else
if digit
self
else
raise FloatDomainError
end
end
end

def ceil(digit = nil)
if digit
round digit, ROUND_CEILING
else
rounded = round 0, ROUND_CEILING
integer = rounded.to_i
return rounded == integer ? integer : rounded
end
end

def fix
if finite?
round 0, ROUND_DOWN
else
self
end
end

def frac
if finite?
self - fix
else
self
end
end
end

BigDecimal = Truffle::BigDecimal
6 changes: 6 additions & 0 deletions spec/ruby/library/bigdecimal/round_spec.rb
Original file line number Diff line number Diff line change
@@ -187,4 +187,10 @@
@n2_49.round(0, BigDecimal::ROUND_HALF_EVEN).should == @neg_two
end
end

it 'raise exception, if self is special value' do
lambda { BigDecimal('NaN').round }.should raise_error(FloatDomainError)
lambda { BigDecimal('Infinity').round }.should raise_error(FloatDomainError)
lambda { BigDecimal('-Infinity').round }.should raise_error(FloatDomainError)
end
end
7 changes: 2 additions & 5 deletions spec/truffle/tags/library/bigdecimal/add_tags.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
fails:BigDecimal#add favors the precision specified in the second argument over the global limit
fails:BigDecimal#add uses the current rounding mode if rounding is needed
fails:BigDecimal#add returns NaN if NaN is involved
fails:BigDecimal#add returns Infinity or -Infinity if these are involved
fails:BigDecimal#add returns NaN if Infinity + (- Infinity)
fails:BigDecimal#add raises TypeError when precision parameter is nil
fails:BigDecimal#add raises TypeError when adds nil
fails:BigDecimal#add raises ArgumentError when precision parameter is negative
5 changes: 0 additions & 5 deletions spec/truffle/tags/library/bigdecimal/ceil_tags.txt

This file was deleted.

8 changes: 1 addition & 7 deletions spec/truffle/tags/library/bigdecimal/div_tags.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
fails:BigDecimal#div with precision set to 0 returns a / b
fails:BigDecimal#div with precision set to 0 returns 0 if divided by Infinity
fails:BigDecimal#div with precision set to 0 returns (+|-) Infinity if (+|-) Infinity divided by one
fails:BigDecimal#div with precision set to 0 returns NaN if Infinity / ((+|-) Infinity)
fails:BigDecimal#div with precision set to 0 returns (+|-) Infinity if divided by zero
fails:BigDecimal#div with precision set to 0 returns NaN if zero is divided by zero
fails:BigDecimal#div returns a / b with optional precision
fails:BigDecimal#div raises FloatDomainError if NaN is involved
fails:BigDecimal#div raises ZeroDivisionError if divided by zero and no precision given
fails:BigDecimal#div returns 0 if divided by Infinity and no precision given
fails:BigDecimal#div returns 0 if divided by Infinity with given precision
fails:BigDecimal#div returns NaN if zero is divided by zero
fails:BigDecimal#div raises FloatDomainError if (+|-) Infinity divided by 1 and no precision given
fails:BigDecimal#div returns (+|-)Infinity if (+|-)Infinity by 1 and precision given
fails:BigDecimal#div returns NaN if Infinity / ((+|-) Infinity)
2 changes: 2 additions & 0 deletions spec/truffle/tags/library/bigdecimal/divmod_tags.txt
Original file line number Diff line number Diff line change
@@ -12,3 +12,5 @@ fails:BigDecimal#divmod returns an array of Infinity and NaN if the dividend is
fails:BigDecimal#divmod returns an array of zero and the dividend if the divisor is Infinity
fails:BigDecimal#divmod returns an array of two zero if the diviend is zero
fails:BigDecimal#divmod raises TypeError if the argument cannot be coerced to BigDecimal
fails:BigDecimal#mod_part_of_divmod raises ZeroDivisionError if other is zero
fails:BigDecimal#divmod raises ZeroDivisionError if the divisor is zero
8 changes: 0 additions & 8 deletions spec/truffle/tags/library/bigdecimal/exponent_tags.txt

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/library/bigdecimal/fix_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/truffle/tags/library/bigdecimal/floor_tags.txt

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/library/bigdecimal/frac_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/library/bigdecimal/limit_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/library/bigdecimal/mode_tags.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
fails:BigDecimal.mode returns the appropriate value and continue the computation if the flag is false
fails:BigDecimal.mode returns Infinity when too big
fails:BigDecimal.mode raise an exception if the flag is true
2 changes: 2 additions & 0 deletions spec/truffle/tags/library/bigdecimal/modulo_tags.txt
Original file line number Diff line number Diff line change
@@ -10,3 +10,5 @@ fails:BigDecimal#modulo returns NaN if NaN is involved
fails:BigDecimal#modulo returns NaN if the dividend is Infinity
fails:BigDecimal#modulo returns the dividend if the divisor is Infinity
fails:BigDecimal#modulo raises TypeError if the argument cannot be coerced to BigDecimal
fails:BigDecimal#% raises ZeroDivisionError if other is zero
fails:BigDecimal#modulo raises ZeroDivisionError if other is zero
5 changes: 0 additions & 5 deletions spec/truffle/tags/library/bigdecimal/mult_tags.txt

This file was deleted.

8 changes: 0 additions & 8 deletions spec/truffle/tags/library/bigdecimal/power_tags.txt

This file was deleted.

8 changes: 0 additions & 8 deletions spec/truffle/tags/library/bigdecimal/round_tags.txt

This file was deleted.

16 changes: 0 additions & 16 deletions spec/truffle/tags/library/bigdecimal/sqrt_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/library/bigdecimal/sub_tags.txt

This file was deleted.

7 changes: 0 additions & 7 deletions spec/truffle/tags/library/bigdecimal/truncate_tags.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -91,7 +91,6 @@ public Object cast(Object nil) {
return nil;

default: {
CompilerAsserts.neverPartOfCompilation();
throw new UnsupportedOperationException();
}
}
Original file line number Diff line number Diff line change
@@ -71,7 +71,6 @@ public RubyBasicObject splat(Object nil) {
return ArrayNodes.fromObject(getContext().getCoreLibrary().getArrayClass(), nil());

default: {
CompilerAsserts.neverPartOfCompilation();
throw new UnsupportedOperationException();
}
}
1,496 changes: 1,025 additions & 471 deletions truffle/src/main/java/org/jruby/truffle/nodes/ext/BigDecimalNodes.java

Large diffs are not rendered by default.