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: c147443b3f35
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: eabb23a1ffeb
Choose a head ref
  • 20 commits
  • 13 files changed
  • 1 contributor

Commits on Jul 3, 2015

  1. Copy the full SHA
    04c0a32 View commit details
  2. Copy the full SHA
    72f470d View commit details
  3. Copy the full SHA
    588cb3f View commit details
  4. Copy the full SHA
    7cfe43a View commit details
  5. Copy the full SHA
    71f40c2 View commit details
  6. Copy the full SHA
    8f83005 View commit details
  7. Copy the full SHA
    40e74c4 View commit details
  8. Copy the full SHA
    8415308 View commit details
  9. Copy the full SHA
    ceede47 View commit details
  10. [Truffle] BigDecimal: readd tags for tests which fail internally

    com.oracle.truffle.api.dsl.UnsupportedSpecializationException
    pitr-ch committed Jul 3, 2015
    Copy the full SHA
    77e0392 View commit details
  11. Copy the full SHA
    0adb2ea View commit details
  12. Copy the full SHA
    a2bf575 View commit details
  13. Copy the full SHA
    4ddcd6a View commit details
  14. [Truffle] BigDecimal: use UnreachableCodeBranch instead of generic Un…

    …supportedOperationException
    pitr-ch committed Jul 3, 2015
    Copy the full SHA
    e3efbd1 View commit details
  15. Copy the full SHA
    eb9cdcd View commit details
  16. [Truffle] BigDecimal: cleanup initialize and support digits arg. for …

    …all types
    
    * move creation from string to CreateBigDecimalNode
    pitr-ch committed Jul 3, 2015
    2
    Copy the full SHA
    6dddb2e View commit details
  17. Copy the full SHA
    0f7f756 View commit details
  18. Copy the full SHA
    2d6cc4e View commit details
  19. Copy the full SHA
    acdb909 View commit details
  20. Copy the full SHA
    eabb23a View commit details
119 changes: 110 additions & 9 deletions lib/ruby/truffle/truffle/bigdecimal.rb
Original file line number Diff line number Diff line change
@@ -39,15 +39,16 @@ def self.mode(key, value = nil)
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
when true
Thread.current[:'BigDecimal.exception_mode'] |= key
return value
when false
Thread.current[:'BigDecimal.exception_mode'] &= ~key
return value
when nil
return Thread.current[:'BigDecimal.exception_mode']
else
raise ArgumentError, 'second argument must be true or false'
end
end
end
@@ -69,6 +70,14 @@ def self.name
'BigDecimal'
end

def self.double_fig
20
end

def self.ver
'1.1.0'
end

def ==(o)
(self <=> o) == 0 rescue false
end
@@ -181,6 +190,98 @@ def frac
self
end
end

def to_s(format = 'E')
if finite?
float_format = format[-1] == 'F'
space_frequency = format.to_i
prefix = if self > 0 && [' ', '+'].include?(format[0])
format[0]
elsif self < 0
'-'
else
''
end
unscaled_value = unscaled
exponent_value = exponent

if float_format
case
when exponent_value > unscaled_value.size
before_dot = unscaled_value + '0' * (exponent_value - unscaled_value.size)
after_dot = '0'
when exponent_value <= 0
before_dot = '0'
after_dot = '0' * exponent_value.abs + unscaled_value
else
before_dot = unscaled_value[0...exponent_value]
rest = unscaled_value[exponent_value..-1]
after_dot = rest.empty? ? '0' : rest
end

format '%s%s.%s',
prefix,
add_spaces_to_s(before_dot, true, space_frequency),
add_spaces_to_s(after_dot, false, space_frequency)
else
format '%s0.%sE%d',
prefix,
add_spaces_to_s(unscaled_value, false, space_frequency),
exponent_value
end
else
(sign < 0 ? '-' : '') + unscaled
end
end

def inspect
precs1, precs2 = precs

format "#<BigDecimal:%s,'%s',%d(%d)>",
object_id.to_s(16),
to_s,
precs1,
precs2
end

def _dump(level)
# TODO (pitr 30-jun-2015): increase density
to_s
end

def self._load(data)
new data
end

private

def add_spaces_to_s(string, reverse, space_frequency)
return string if space_frequency == 0

remainder = string.size % space_frequency
shift = reverse ? remainder : 0
pieces = (string.size / space_frequency).times.map { |i| string[space_frequency*i + shift, space_frequency] }

if remainder > 0
if reverse
pieces.unshift string[0...remainder]
else
pieces.push string[-remainder..-1]
end
end

pieces.join ' '
end

def self.boolean_mode(key, value = nil)
if value.nil?
mode(key) & key == key
else
mode key, value
end
end

private_class_method :boolean_mode
end

BigDecimal = Truffle::BigDecimal
2 changes: 2 additions & 0 deletions spec/ruby/library/bigdecimal/div_spec.rb
Original file line number Diff line number Diff line change
@@ -45,6 +45,7 @@
it "raises FloatDomainError if NaN is involved" do
lambda { @one.div(@nan) }.should raise_error(FloatDomainError)
lambda { @nan.div(@one) }.should raise_error(FloatDomainError)
lambda { @nan.div(@nan) }.should raise_error(FloatDomainError)
end

it "returns 0 if divided by Infinity and no precision given" do
@@ -66,6 +67,7 @@

lambda { @zero.div(@zero) }.should raise_error(ZeroDivisionError)
lambda { @zero_minus.div(@zero_plus) }.should raise_error(ZeroDivisionError)
lambda { @zero_minus.div(@zero_minus) }.should raise_error(ZeroDivisionError)
lambda { @zero_plus.div(@zero_minus) }.should raise_error(ZeroDivisionError)
end

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

This file was deleted.

14 changes: 0 additions & 14 deletions spec/truffle/tags/library/bigdecimal/divmod_tags.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,2 @@
fails:BigDecimal#mod_part_of_divmod returns self modulo other
fails:BigDecimal#mod_part_of_divmod returns a [Float value] when the argument is Float
fails:BigDecimal#mod_part_of_divmod returns NaN if NaN is involved
fails:BigDecimal#mod_part_of_divmod returns NaN if the dividend is Infinity
fails:BigDecimal#mod_part_of_divmod returns the dividend if the divisor is Infinity
fails:BigDecimal#mod_part_of_divmod raises TypeError if the argument cannot be coerced to BigDecimal
fails:BigDecimal#divmod divides value, returns an array
fails:BigDecimal#divmod array contains quotient and modulus as BigDecimal
fails:BigDecimal#divmod Can be reversed with * and +
fails:BigDecimal#divmod returns an array of two NaNs if NaN is involved
fails:BigDecimal#divmod returns an array of Infinity and NaN if the dividend is Infinity
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
1 change: 0 additions & 1 deletion spec/truffle/tags/library/bigdecimal/double_fig_tags.txt

This file was deleted.

6 changes: 0 additions & 6 deletions spec/truffle/tags/library/bigdecimal/inspect_tags.txt

This file was deleted.

12 changes: 0 additions & 12 deletions spec/truffle/tags/library/bigdecimal/modulo_tags.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
fails:BigDecimal#% returns self modulo other
fails:BigDecimal#% returns a [Float value] when the argument is Float
fails:BigDecimal#% returns NaN if NaN is involved
fails:BigDecimal#% returns NaN if the dividend is Infinity
fails:BigDecimal#% returns the dividend if the divisor is Infinity
fails:BigDecimal#% raises TypeError if the argument cannot be coerced to BigDecimal
fails:BigDecimal#modulo returns self modulo other
fails:BigDecimal#modulo returns a [Float value] when the argument is Float
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
7 changes: 0 additions & 7 deletions spec/truffle/tags/library/bigdecimal/remainder_tags.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1 @@
fails:BigDecimal#remainder it equals modulo, if both values are of same sign
fails:BigDecimal#remainder means self-arg*(self/arg).truncate
fails:BigDecimal#remainder returns NaN used with zero
fails:BigDecimal#remainder returns zero if used on zero
fails:BigDecimal#remainder returns NaN if NaN is involved
fails:BigDecimal#remainder returns NaN if Infinity is involved
fails:BigDecimal#remainder coerces arguments to BigDecimal if possible
fails:BigDecimal#remainder raises TypeError if the argument cannot be coerced to BigDecimal
3 changes: 3 additions & 0 deletions spec/truffle/tags/library/bigdecimal/sqrt_tags.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fails:BigDecimal#sqrt raises TypeError if nil is given
fails:BigDecimal#sqrt raises TypeError if a string is given
fails:BigDecimal#sqrt raises TypeError if a plain Object is given
7 changes: 0 additions & 7 deletions spec/truffle/tags/library/bigdecimal/to_s_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/library/bigdecimal/ver_tags.txt

This file was deleted.

637 changes: 446 additions & 191 deletions truffle/src/main/java/org/jruby/truffle/nodes/ext/BigDecimalNodes.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This
* code is released under a tri EPL/GPL/LGPL license. You can use it,
* redistribute it and/or modify it under the terms of the:
*
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*/
package org.jruby.truffle.nodes.internal;

public class UnreachableCodeBranch extends UnsupportedOperationException {
public UnreachableCodeBranch() {
super("This branch of code should be never reached");
}
}