org.jruby
Class RubyBigDecimal

java.lang.Object
  extended by org.jruby.RubyBasicObject
      extended by org.jruby.RubyObject
          extended by org.jruby.RubyNumeric
              extended by org.jruby.RubyBigDecimal
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<IRubyObject>, InstanceVariables, InternalVariables, IRubyObject, CoreObjectType

public class RubyBigDecimal
extends RubyNumeric

Author:
Ola Bini
See Also:
Serialized Form

Nested Class Summary
static class RubyBigDecimal.BigDecimalKernelMethods
           
 
Nested classes/interfaces inherited from class org.jruby.RubyNumeric
RubyNumeric.InvalidIntegerException, RubyNumeric.NumberTooLargeException
 
Nested classes/interfaces inherited from class org.jruby.RubyObject
RubyObject.ObjectMethods
 
Nested classes/interfaces inherited from class org.jruby.RubyBasicObject
RubyBasicObject.BasicObjectMethods, RubyBasicObject.Finalizer
 
Field Summary
static int BASE
           
static int EXCEPTION_ALL
           
static int EXCEPTION_INFINITY
           
static int EXCEPTION_NaN
           
static int EXCEPTION_OVERFLOW
           
static int EXCEPTION_UNDERFLOW
           
static int EXCEPTION_ZERODIVIDE
           
static int ROUND_CEILING
           
static int ROUND_DOWN
           
static int ROUND_FLOOR
           
static int ROUND_HALF_DOWN
           
static int ROUND_HALF_EVEN
           
static int ROUND_HALF_UP
           
static int ROUND_MODE
           
static int ROUND_UP
           
static int SIGN_NaN
           
static int SIGN_NEGATIVE_FINITE
           
static int SIGN_NEGATIVE_INFINITE
           
static int SIGN_NEGATIVE_ZERO
           
static int SIGN_POSITIVE_FINITE
           
static int SIGN_POSITIVE_INFINITE
           
static int SIGN_POSITIVE_ZERO
           
 
Fields inherited from class org.jruby.RubyNumeric
DBL_EPSILON, NUMERIC_ALLOCATOR
 
Fields inherited from class org.jruby.RubyObject
OBJECT_ALLOCATOR
 
Fields inherited from class org.jruby.RubyBasicObject
ALL_F, ERR_INSECURE_SET_INST_VAR, FALSE_F, FL_USHIFT, flags, FROZEN_F, metaClass, NEVER, NIL_F, TAINTED_F, UNDEF, UNTRUSTED_F, USER0_F, USER1_F, USER2_F, USER3_F, USER4_F, USER5_F, USER6_F, USER7_F
 
Fields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY
 
Constructor Summary
RubyBigDecimal(Ruby runtime, java.math.BigDecimal value)
           
RubyBigDecimal(Ruby runtime, RubyClass klass)
           
 
Method Summary
 IRubyObject abs()
           
 IRubyObject add2(ThreadContext context, IRubyObject b, IRubyObject digits)
           
static java.math.BigDecimal bigSqrt(java.math.BigDecimal squarD, java.math.MathContext rootMC)
          Returns the correctly rounded square root of a positive BigDecimal.
 IRubyObject ceil(IRubyObject[] args)
           
 IRubyObject coerce(IRubyObject other)
          num_coerce
static RubyClass createBigDecimal(Ruby runtime)
           
 IRubyObject divmod(ThreadContext context, IRubyObject other)
          num_divmod
static IRubyObject double_fig(IRubyObject recv)
           
 IRubyObject dump(IRubyObject[] args, Block unusedBlock)
           
 IRubyObject eql_p(ThreadContext context, IRubyObject arg)
          num_eql
 IRubyObject exponent()
           
 IRubyObject finite_p()
           
 IRubyObject fix()
           
 IRubyObject floor(IRubyObject[] args)
           
static int formatFractionalDigitGroups(java.lang.String format)
           
static boolean formatHasFloatingPointNotation(java.lang.String format)
           
static boolean formatHasLeadingPlus(java.lang.String format)
           
static boolean formatHasLeadingSpace(java.lang.String format)
           
 IRubyObject frac()
           
 double getDoubleValue()
           
 long getLongValue()
           
 java.math.BigDecimal getValue()
           
 RubyFixnum hash()
          rb_obj_id Will return the hash code of this object.
static IRubyObject induced_from(IRubyObject recv, IRubyObject arg)
           
 IRubyObject infinite_p()
           
 IRubyObject inspect(ThreadContext context)
           
static IRubyObject limit(IRubyObject recv, IRubyObject[] args)
           
static RubyBigDecimal load(IRubyObject recv, IRubyObject from, Block block)
           
static IRubyObject mode(ThreadContext context, IRubyObject recv, IRubyObject[] args)
           
 IRubyObject mult2(ThreadContext context, IRubyObject b, IRubyObject n)
           
 RubyNumeric multiplyWith(ThreadContext context, RubyBignum value)
           
 RubyNumeric multiplyWith(ThreadContext context, RubyFloat value)
           
 RubyNumeric multiplyWith(ThreadContext context, RubyInteger value)
           
 IRubyObject nan_p()
           
static RubyBigDecimal newBigDecimal(IRubyObject recv, IRubyObject[] args, Block unusedBlock)
           
static RubyBigDecimal newInstance(IRubyObject recv, IRubyObject[] args)
           
 IRubyObject nonzero_p()
           
 IRubyObject op_cmp(ThreadContext context, IRubyObject arg)
           
 IRubyObject op_div(ThreadContext context, IRubyObject other)
           
 IRubyObject op_div(ThreadContext context, IRubyObject other, IRubyObject digits)
           
 IRubyObject op_ge(ThreadContext context, IRubyObject arg)
           
 IRubyObject op_gt(ThreadContext context, IRubyObject arg)
           
 IRubyObject op_le(ThreadContext context, IRubyObject arg)
           
 IRubyObject op_lt(ThreadContext context, IRubyObject arg)
           
 IRubyObject op_minus(ThreadContext context, IRubyObject arg)
           
 IRubyObject op_mod(ThreadContext context, IRubyObject arg)
           
 IRubyObject op_mul(ThreadContext context, IRubyObject arg)
           
 IRubyObject op_plus(ThreadContext context, IRubyObject b)
           
 IRubyObject op_pow(IRubyObject arg)
           
 IRubyObject op_quo(ThreadContext context, IRubyObject other)
           
 IRubyObject op_uminus()
           
 IRubyObject op_uplus()
          num_uplus
 IRubyObject precs()
           
 IRubyObject remainder(ThreadContext context, IRubyObject arg)
          num_remainder
 IRubyObject round(IRubyObject[] args)
           
 IRubyObject sign()
           
 RubyArray split()
           
 IRubyObject sqrt(IRubyObject arg)
           
 IRubyObject sub2(ThreadContext context, IRubyObject b, IRubyObject n)
           
 IRubyObject to_f()
           
 IRubyObject to_int()
           
 IRubyObject to_s(IRubyObject[] args)
           
 IRubyObject truncate()
          num_truncate
 IRubyObject truncate(IRubyObject arg)
           
static IRubyObject ver(IRubyObject recv)
           
 IRubyObject zero_p()
           
 
Methods inherited from class org.jruby.RubyNumeric
abs, abs2, arg, asNumeric, callCoerced, callCoerced, ceil, checkInt, coerceBin, coerceBody, coerceCmp, coerceRelOp, conjugate, createNumericClass, dbl_cmp, dbl2num, denominator, div, doCoerce, fdiv, fix2int, fix2int, fix2long, floatStep, floor, getCoerced, image, initialize_copy, int2fix, integer_p, magnitude, modulo, newNumeric, nonzero_p, num2chr, num2dbl, num2fix, num2int, num2long, numerator, op_cmp, op_num_equal, op_uminus, polar, quo_19, quo, real, rect, round, sadded, scalar_p, step, step, step, step19, step19, str2fnum, str2fnum, str2inum, str2inum, to_c, to_int, zero_p
 
Methods inherited from class org.jruby.RubyObject
as, attachToObjectSpace, callInit, checkFrozen, convertToType, createObjectClass, display, dup, eql_p, eqlInternal, equal_p, equalInternal, equals, evalUnder, evalUnder, extend, freeze, frozen_p, getNativeTypeIndex, hashCode, id_deprecated, id, initialize, inspect, instance_eval, instance_eval, instance_eval, instance_eval, instance_eval, instance_exec, instance_of_p, instance_variable_defined_p, instance_variable_get, instance_variable_set, instance_variables, kind_of_p, method, methods, nil_p, op_eqq, op_equal, op_match, private_methods, protected_methods, public_methods, puts, rbClone, remove_instance_variable, respond_to_p, respond_to_p, send, send, send, send, send, singleton_methods, singleton_methods19, singletonMethods, specificEval, specificEval, specificEval, specificEval, specificEval, taint, tainted_p, to_a, to_java, to_s, toString, trust, type_deprecated, type, untaint, untrust, untrusted_p, validateInstanceVariable
 
Methods inherited from class org.jruby.RubyBasicObject
addFinalizer, anyToString, asJavaString, asString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkStringType, compareTo, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, createBasicObjectClass, dataGetStruct, dataWrapStruct, ensureInstanceVariablesSettable, eql, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, getFlag, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getJavaClass, getMetaClass, getRuntime, getSingletonClass, getSingletonClassClone, getType, getVariable, getVariableCount, getVariableList, getVariableNameList, hasInstanceVariable, hasInternalVariable, hasVariables, infectBy, isClass, isFalse, isFrozen, isImmediate, isModule, isNil, isTaint, isTrue, isUntrusted, makeMetaClass, op_not_equal, op_not, removeFinalizers, removeInstanceVariable, removeInternalVariable, respondsTo, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setTaint, setUntrusted, setVariable, syncVariables, taint, testFrozen, testFrozen, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableGetSize, variableTableRemove, variableTableStore, variableTableSync
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ROUND_DOWN

public static final int ROUND_DOWN
See Also:
Constant Field Values

ROUND_CEILING

public static final int ROUND_CEILING
See Also:
Constant Field Values

ROUND_UP

public static final int ROUND_UP
See Also:
Constant Field Values

ROUND_HALF_DOWN

public static final int ROUND_HALF_DOWN
See Also:
Constant Field Values

ROUND_HALF_EVEN

public static final int ROUND_HALF_EVEN
See Also:
Constant Field Values

ROUND_HALF_UP

public static final int ROUND_HALF_UP
See Also:
Constant Field Values

ROUND_FLOOR

public static final int ROUND_FLOOR
See Also:
Constant Field Values

SIGN_POSITIVE_INFINITE

public static final int SIGN_POSITIVE_INFINITE
See Also:
Constant Field Values

EXCEPTION_OVERFLOW

public static final int EXCEPTION_OVERFLOW
See Also:
Constant Field Values

SIGN_POSITIVE_ZERO

public static final int SIGN_POSITIVE_ZERO
See Also:
Constant Field Values

EXCEPTION_ALL

public static final int EXCEPTION_ALL
See Also:
Constant Field Values

SIGN_NEGATIVE_FINITE

public static final int SIGN_NEGATIVE_FINITE
See Also:
Constant Field Values

EXCEPTION_UNDERFLOW

public static final int EXCEPTION_UNDERFLOW
See Also:
Constant Field Values

SIGN_NaN

public static final int SIGN_NaN
See Also:
Constant Field Values

BASE

public static final int BASE
See Also:
Constant Field Values

ROUND_MODE

public static final int ROUND_MODE
See Also:
Constant Field Values

SIGN_POSITIVE_FINITE

public static final int SIGN_POSITIVE_FINITE
See Also:
Constant Field Values

EXCEPTION_INFINITY

public static final int EXCEPTION_INFINITY
See Also:
Constant Field Values

SIGN_NEGATIVE_INFINITE

public static final int SIGN_NEGATIVE_INFINITE
See Also:
Constant Field Values

EXCEPTION_ZERODIVIDE

public static final int EXCEPTION_ZERODIVIDE
See Also:
Constant Field Values

SIGN_NEGATIVE_ZERO

public static final int SIGN_NEGATIVE_ZERO
See Also:
Constant Field Values

EXCEPTION_NaN

public static final int EXCEPTION_NaN
See Also:
Constant Field Values
Constructor Detail

RubyBigDecimal

public RubyBigDecimal(Ruby runtime,
                      RubyClass klass)

RubyBigDecimal

public RubyBigDecimal(Ruby runtime,
                      java.math.BigDecimal value)
Method Detail

createBigDecimal

public static RubyClass createBigDecimal(Ruby runtime)

getValue

public java.math.BigDecimal getValue()

newBigDecimal

public static RubyBigDecimal newBigDecimal(IRubyObject recv,
                                           IRubyObject[] args,
                                           Block unusedBlock)

ver

public static IRubyObject ver(IRubyObject recv)

dump

public IRubyObject dump(IRubyObject[] args,
                        Block unusedBlock)

load

public static RubyBigDecimal load(IRubyObject recv,
                                  IRubyObject from,
                                  Block block)

double_fig

public static IRubyObject double_fig(IRubyObject recv)

limit

public static IRubyObject limit(IRubyObject recv,
                                IRubyObject[] args)

mode

public static IRubyObject mode(ThreadContext context,
                               IRubyObject recv,
                               IRubyObject[] args)

induced_from

public static IRubyObject induced_from(IRubyObject recv,
                                       IRubyObject arg)

newInstance

public static RubyBigDecimal newInstance(IRubyObject recv,
                                         IRubyObject[] args)

hash

public RubyFixnum hash()
Description copied from class: RubyObject
rb_obj_id Will return the hash code of this object. In comparison to MRI, this method will use the Java identity hash code instead of using rb_obj_id, since the usage of id in JRuby will incur the cost of some. ObjectSpace maintenance.

Overrides:
hash in class RubyObject

op_mod

public IRubyObject op_mod(ThreadContext context,
                          IRubyObject arg)

remainder

public IRubyObject remainder(ThreadContext context,
                             IRubyObject arg)
Description copied from class: RubyNumeric
num_remainder

Overrides:
remainder in class RubyNumeric

op_mul

public IRubyObject op_mul(ThreadContext context,
                          IRubyObject arg)

mult2

public IRubyObject mult2(ThreadContext context,
                         IRubyObject b,
                         IRubyObject n)

op_pow

public IRubyObject op_pow(IRubyObject arg)

op_plus

public IRubyObject op_plus(ThreadContext context,
                           IRubyObject b)

add2

public IRubyObject add2(ThreadContext context,
                        IRubyObject b,
                        IRubyObject digits)

op_uplus

public IRubyObject op_uplus()
Description copied from class: RubyNumeric
num_uplus

Overrides:
op_uplus in class RubyNumeric

op_minus

public IRubyObject op_minus(ThreadContext context,
                            IRubyObject arg)

sub2

public IRubyObject sub2(ThreadContext context,
                        IRubyObject b,
                        IRubyObject n)

op_uminus

public IRubyObject op_uminus()

op_quo

public IRubyObject op_quo(ThreadContext context,
                          IRubyObject other)

op_div

public IRubyObject op_div(ThreadContext context,
                          IRubyObject other)

op_div

public IRubyObject op_div(ThreadContext context,
                          IRubyObject other,
                          IRubyObject digits)

op_cmp

public IRubyObject op_cmp(ThreadContext context,
                          IRubyObject arg)

eql_p

public IRubyObject eql_p(ThreadContext context,
                         IRubyObject arg)
Description copied from class: RubyNumeric
num_eql

Overrides:
eql_p in class RubyNumeric

op_lt

public IRubyObject op_lt(ThreadContext context,
                         IRubyObject arg)

op_le

public IRubyObject op_le(ThreadContext context,
                         IRubyObject arg)

op_gt

public IRubyObject op_gt(ThreadContext context,
                         IRubyObject arg)

op_ge

public IRubyObject op_ge(ThreadContext context,
                         IRubyObject arg)

abs

public IRubyObject abs()

ceil

public IRubyObject ceil(IRubyObject[] args)

coerce

public IRubyObject coerce(IRubyObject other)
Description copied from class: RubyNumeric
num_coerce

Overrides:
coerce in class RubyNumeric

getDoubleValue

public double getDoubleValue()
Overrides:
getDoubleValue in class RubyNumeric

getLongValue

public long getLongValue()
Overrides:
getLongValue in class RubyNumeric

multiplyWith

public RubyNumeric multiplyWith(ThreadContext context,
                                RubyInteger value)

multiplyWith

public RubyNumeric multiplyWith(ThreadContext context,
                                RubyFloat value)

multiplyWith

public RubyNumeric multiplyWith(ThreadContext context,
                                RubyBignum value)

divmod

public IRubyObject divmod(ThreadContext context,
                          IRubyObject other)
Description copied from class: RubyNumeric
num_divmod

Overrides:
divmod in class RubyNumeric

exponent

public IRubyObject exponent()

finite_p

public IRubyObject finite_p()

floor

public IRubyObject floor(IRubyObject[] args)

frac

public IRubyObject frac()

infinite_p

public IRubyObject infinite_p()

inspect

public IRubyObject inspect(ThreadContext context)

nan_p

public IRubyObject nan_p()

nonzero_p

public IRubyObject nonzero_p()

precs

public IRubyObject precs()

round

public IRubyObject round(IRubyObject[] args)

sign

public IRubyObject sign()

split

public RubyArray split()

sqrt

public IRubyObject sqrt(IRubyObject arg)

to_f

public IRubyObject to_f()

to_int

public IRubyObject to_int()

formatHasLeadingPlus

public static boolean formatHasLeadingPlus(java.lang.String format)

formatHasLeadingSpace

public static boolean formatHasLeadingSpace(java.lang.String format)

formatHasFloatingPointNotation

public static boolean formatHasFloatingPointNotation(java.lang.String format)

formatFractionalDigitGroups

public static int formatFractionalDigitGroups(java.lang.String format)

to_s

public IRubyObject to_s(IRubyObject[] args)

fix

public IRubyObject fix()

truncate

public IRubyObject truncate()
Description copied from class: RubyNumeric
num_truncate

Overrides:
truncate in class RubyNumeric

truncate

public IRubyObject truncate(IRubyObject arg)

zero_p

public IRubyObject zero_p()

bigSqrt

public static java.math.BigDecimal bigSqrt(java.math.BigDecimal squarD,
                                           java.math.MathContext rootMC)
Returns the correctly rounded square root of a positive BigDecimal. This method performs the fast Square Root by Coupled Newton Iteration algorithm by Timm Ahrendt, from the book "Pi, unleashed" by J??rg Arndt in a neat loop.

The code is based on Frans Lelieveld's code , used here with permission.

Parameters:
squarD - The number to get the root from.
rootMC - Precision and rounding mode.
Returns:
the root of the argument number
Throws:
java.lang.ArithmeticException - if the argument number is negative
java.lang.IllegalArgumentException - if rootMC has precision 0


Copyright © 2002-2007 JRuby Team. All Rights Reserved.