org.jruby
Class RubyNumeric

java.lang.Object
  extended by org.jruby.RubyBasicObject
      extended by org.jruby.RubyObject
          extended by org.jruby.RubyNumeric
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, InstanceVariables, InternalVariables, IRubyObject, CoreObjectType
Direct Known Subclasses:
RubyBigDecimal, RubyComplex, RubyFloat, RubyInteger, RubyRational

public class RubyNumeric
extends RubyObject

Base class for all numerical types in ruby.

See Also:
Serialized Form

Nested Class Summary
static class RubyNumeric.InvalidIntegerException
           
static class 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, RubyBasicObject.VariableTableEntry
 
Field Summary
static double DBL_EPSILON
           
protected static ObjectAllocator NUMERIC_ALLOCATOR
           
 
Fields inherited from class org.jruby.RubyObject
OBJECT_ALLOCATOR
 
Fields inherited from class org.jruby.RubyBasicObject
ALL_F, dataStruct, ERR_INSECURE_SET_INST_VAR, FALSE_F, FL_USHIFT, flags, FROZEN_F, metaClass, NEVER, NIL_F, TAINTED_F, UNDEF, USER0_F, USER1_F, USER2_F, USER3_F, USER4_F, USER5_F, USER6_F, USER7_F, VARIABLE_TABLE_DEFAULT_CAPACITY, VARIABLE_TABLE_EMPTY_TABLE, VARIABLE_TABLE_LOAD_FACTOR, VARIABLE_TABLE_MAXIMUM_CAPACITY, variableTable, variableTableSize, variableTableThreshold
 
Fields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY
 
Constructor Summary
RubyNumeric(Ruby runtime, RubyClass metaClass)
           
RubyNumeric(Ruby runtime, RubyClass metaClass, boolean useObjectSpace)
           
RubyNumeric(Ruby runtime, RubyClass metaClass, boolean useObjectSpace, boolean canBeTainted)
           
 
Method Summary
 IRubyObject abs(ThreadContext context)
          num_abs
 IRubyObject abs2(ThreadContext context)
          numeric_abs2
 IRubyObject arg(ThreadContext context)
          numeric_arg
 RubyNumeric asNumeric()
           
protected  IRubyObject callCoerced(ThreadContext context, java.lang.String method, IRubyObject other)
           
protected  IRubyObject callCoerced(ThreadContext context, java.lang.String method, IRubyObject other, boolean err)
           
 IRubyObject ceil()
          num_ceil
static void checkInt(IRubyObject arg, long num)
          check_int
 IRubyObject coerce(IRubyObject other)
          num_coerce
protected  IRubyObject coerceBin(ThreadContext context, java.lang.String method, IRubyObject other)
          rb_num_coerce_bin coercion taking two arguments
protected  IRubyObject coerceBody(ThreadContext context, IRubyObject other)
          coerce_body
protected  IRubyObject coerceCmp(ThreadContext context, java.lang.String method, IRubyObject other)
          rb_num_coerce_cmp coercion used for comparisons
protected  IRubyObject coerceRelOp(ThreadContext context, java.lang.String method, IRubyObject other)
          rb_num_coerce_relop coercion used for relative operators
 IRubyObject conjugate(ThreadContext context)
          numeric_real
static RubyClass createNumericClass(Ruby runtime)
           
static IRubyObject dbl_cmp(Ruby runtime, double a, double b)
          rb_dbl_cmp (numeric.c)
static IRubyObject dbl2num(Ruby runtime, double val)
          rb_dbl2big + LONG2FIX at once (numeric.c)
 IRubyObject denominator(ThreadContext context)
          num_denominator
 IRubyObject div(ThreadContext context, IRubyObject other)
          num_div
 IRubyObject divmod(ThreadContext context, IRubyObject other)
          num_divmod
protected  RubyArray doCoerce(ThreadContext context, IRubyObject other, boolean err)
          do_coerce
 IRubyObject eql_p(ThreadContext context, IRubyObject other)
          num_eql
 IRubyObject fdiv(ThreadContext context, IRubyObject other)
          num_fdiv (1.9)
static int fix2int(IRubyObject arg)
           
static long fix2long(IRubyObject arg)
           
 IRubyObject floor()
          num_floor
protected  IRubyObject[] getCoerced(ThreadContext context, IRubyObject other, boolean error)
          Numeric methods.
 double getDoubleValue()
           
 long getLongValue()
           
 IRubyObject image(ThreadContext context)
          numeric_image
 IRubyObject initialize_copy(IRubyObject arg)
          num_init_copy
static RubyNumeric int2fix(Ruby runtime, long val)
           
 IRubyObject integer_p()
          num_int_p
 IRubyObject magnitude(ThreadContext context)
          num_abs/1.9
 IRubyObject modulo(ThreadContext context, IRubyObject other)
          num_modulo
static RubyNumeric newNumeric(Ruby runtime)
           
 IRubyObject nonzero_p(ThreadContext context)
          num_nonzero_p
static byte num2chr(IRubyObject arg)
          NUM2CHR
static double num2dbl(IRubyObject arg)
          rb_num2dbl and NUM2DBL
static IRubyObject num2fix(IRubyObject val)
          rb_num2fix
static int num2int(IRubyObject arg)
          rb_num2int, NUM2INT
static long num2long(IRubyObject arg)
          rb_num2long and FIX2LONG (numeric.c)
 IRubyObject numerator(ThreadContext context)
          num_numerator
 IRubyObject op_cmp(IRubyObject other)
          num_cmp
protected  IRubyObject op_num_equal(ThreadContext context, IRubyObject other)
          num_equal, doesn't override RubyObject.op_equal
 IRubyObject op_uminus(ThreadContext context)
          num_uminus
 IRubyObject op_uplus()
          num_uplus
 IRubyObject polar(ThreadContext context)
          numeric_polar
 IRubyObject quo_19(ThreadContext context, IRubyObject other)
          num_quo
 IRubyObject quo(ThreadContext context, IRubyObject other)
          num_quo
 IRubyObject real(ThreadContext context)
          numeric_real
 IRubyObject rect(ThreadContext context)
          numeric_rect
 IRubyObject remainder(ThreadContext context, IRubyObject dividend)
          num_remainder
 IRubyObject round()
          num_round
 IRubyObject sadded(IRubyObject name)
          num_sadded
 IRubyObject scalar_p()
          num_real_p
 IRubyObject step(ThreadContext context, IRubyObject[] args, Block block)
           
 IRubyObject step(ThreadContext context, IRubyObject arg0, Block block)
           
 IRubyObject step(ThreadContext context, IRubyObject to, IRubyObject step, Block block)
           
 IRubyObject step19(ThreadContext context, IRubyObject arg0, Block block)
           
 IRubyObject step19(ThreadContext context, IRubyObject to, IRubyObject step, Block block)
           
static RubyFloat str2fnum(Ruby runtime, RubyString arg)
           
static RubyFloat str2fnum(Ruby runtime, RubyString arg, boolean strict)
          Converts a string representation of a floating-point number to the numeric value.
static RubyInteger str2inum(Ruby runtime, RubyString str, int base)
           
static RubyInteger str2inum(Ruby runtime, RubyString str, int base, boolean strict)
          Converts a string representation of an integer to the integer value.
 IRubyObject to_c(ThreadContext context)
          numeric_to_c
 IRubyObject to_int(ThreadContext context)
          num_to_int
 IRubyObject truncate()
          num_truncate
 IRubyObject zero_p(ThreadContext context)
          num_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, hash, 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, type_deprecated, type, untaint, validateInstanceVariable
 
Methods inherited from class org.jruby.RubyBasicObject
addFinalizer, anyToString, asJavaString, asString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkStringType, 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, getInternalVariableList, getInternalVariables, getJavaClass, getMetaClass, getRuntime, getSingletonClass, getSingletonClassClone, getType, getVariableCount, getVariableList, getVariableMap, getVariableNameList, hasInstanceVariable, hasInternalVariable, hasVariables, infectBy, isClass, isFalse, isFrozen, isImmediate, isModule, isNil, isRubyVariable, isTaint, isTrue, makeMetaClass, op_not_equal, op_not, removeFinalizers, removeInstanceVariable, removeInternalVariable, respondsTo, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setTaint, syncVariables, taint, testFrozen, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableGetMap, variableTableGetMap, variableTableGetSize, variableTableGetTable, variableTableReadLocked, variableTableRehash, variableTableRemove, variableTableStore, variableTableSync
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NUMERIC_ALLOCATOR

protected static final ObjectAllocator NUMERIC_ALLOCATOR

DBL_EPSILON

public static double DBL_EPSILON
Constructor Detail

RubyNumeric

public RubyNumeric(Ruby runtime,
                   RubyClass metaClass)

RubyNumeric

public RubyNumeric(Ruby runtime,
                   RubyClass metaClass,
                   boolean useObjectSpace)

RubyNumeric

public RubyNumeric(Ruby runtime,
                   RubyClass metaClass,
                   boolean useObjectSpace,
                   boolean canBeTainted)
Method Detail

createNumericClass

public static RubyClass createNumericClass(Ruby runtime)

getDoubleValue

public double getDoubleValue()

getLongValue

public long getLongValue()

newNumeric

public static RubyNumeric newNumeric(Ruby runtime)

num2int

public static int num2int(IRubyObject arg)
rb_num2int, NUM2INT


checkInt

public static void checkInt(IRubyObject arg,
                            long num)
check_int


num2chr

public static byte num2chr(IRubyObject arg)
NUM2CHR


num2long

public static long num2long(IRubyObject arg)
rb_num2long and FIX2LONG (numeric.c)


dbl2num

public static IRubyObject dbl2num(Ruby runtime,
                                  double val)
rb_dbl2big + LONG2FIX at once (numeric.c)


num2dbl

public static double num2dbl(IRubyObject arg)
rb_num2dbl and NUM2DBL


dbl_cmp

public static IRubyObject dbl_cmp(Ruby runtime,
                                  double a,
                                  double b)
rb_dbl_cmp (numeric.c)


fix2long

public static long fix2long(IRubyObject arg)

fix2int

public static int fix2int(IRubyObject arg)

str2inum

public static RubyInteger str2inum(Ruby runtime,
                                   RubyString str,
                                   int base)

int2fix

public static RubyNumeric int2fix(Ruby runtime,
                                  long val)

num2fix

public static IRubyObject num2fix(IRubyObject val)
rb_num2fix


str2inum

public static RubyInteger str2inum(Ruby runtime,
                                   RubyString str,
                                   int base,
                                   boolean strict)
Converts a string representation of an integer to the integer value. Parsing starts at the beginning of the string (after leading and trailing whitespace have been removed), and stops at the end or at the first character that can't be part of an integer. Leading signs are allowed. If base is zero, strings that begin with '0[xX]', '0[bB]', or '0' (optionally preceded by a sign) will be treated as hex, binary, or octal numbers, respectively. If a non-zero base is given, only the prefix (if any) that is appropriate to that base will be parsed correctly. For example, if the base is zero or 16, the string "0xff" will be converted to 256, but if the base is 10, it will come out as zero, since 'x' is not a valid decimal digit. If the string fails to parse as a number, zero is returned.

Parameters:
runtime - the ruby runtime
str - the string to be converted
base - the expected base of the number (for example, 2, 8, 10, 16), or 0 if the method should determine the base automatically (defaults to 10). Values 0 and 2-36 are permitted. Any other value will result in an ArgumentError.
strict - if true, enforce the strict criteria for String encoding of numeric values, as required by Integer('n'), and raise an exception when those criteria are not met. Otherwise, allow lax expression of values, as permitted by String#to_i, and return a value in almost all cases (excepting illegal radix). TODO: describe the rules/criteria
Returns:
a RubyFixnum or (if necessary) a RubyBignum representing the result of the conversion, which will be zero if the conversion failed.

str2fnum

public static RubyFloat str2fnum(Ruby runtime,
                                 RubyString arg)

str2fnum

public static RubyFloat str2fnum(Ruby runtime,
                                 RubyString arg,
                                 boolean strict)
Converts a string representation of a floating-point number to the numeric value. Parsing starts at the beginning of the string (after leading and trailing whitespace have been removed), and stops at the end or at the first character that can't be part of a number. If the string fails to parse as a number, 0.0 is returned.

Parameters:
runtime - the ruby runtime
arg - the string to be converted
strict - if true, enforce the strict criteria for String encoding of numeric values, as required by Float('n'), and raise an exception when those criteria are not met. Otherwise, allow lax expression of values, as permitted by String#to_f, and return a value in all cases. TODO: describe the rules/criteria
Returns:
a RubyFloat representing the result of the conversion, which will be 0.0 if the conversion failed.

getCoerced

protected IRubyObject[] getCoerced(ThreadContext context,
                                   IRubyObject other,
                                   boolean error)
Numeric methods. (num_*)


callCoerced

protected IRubyObject callCoerced(ThreadContext context,
                                  java.lang.String method,
                                  IRubyObject other,
                                  boolean err)

callCoerced

protected IRubyObject callCoerced(ThreadContext context,
                                  java.lang.String method,
                                  IRubyObject other)

coerceBody

protected final IRubyObject coerceBody(ThreadContext context,
                                       IRubyObject other)
coerce_body


doCoerce

protected final RubyArray doCoerce(ThreadContext context,
                                   IRubyObject other,
                                   boolean err)
do_coerce


coerceBin

protected final IRubyObject coerceBin(ThreadContext context,
                                      java.lang.String method,
                                      IRubyObject other)
rb_num_coerce_bin coercion taking two arguments


coerceCmp

protected final IRubyObject coerceCmp(ThreadContext context,
                                      java.lang.String method,
                                      IRubyObject other)
rb_num_coerce_cmp coercion used for comparisons


coerceRelOp

protected final IRubyObject coerceRelOp(ThreadContext context,
                                        java.lang.String method,
                                        IRubyObject other)
rb_num_coerce_relop coercion used for relative operators


asNumeric

public RubyNumeric asNumeric()

sadded

public IRubyObject sadded(IRubyObject name)
num_sadded


initialize_copy

public IRubyObject initialize_copy(IRubyObject arg)
num_init_copy

Overrides:
initialize_copy in class RubyObject

coerce

public IRubyObject coerce(IRubyObject other)
num_coerce


op_uplus

public IRubyObject op_uplus()
num_uplus


op_uminus

public IRubyObject op_uminus(ThreadContext context)
num_uminus


op_cmp

public IRubyObject op_cmp(IRubyObject other)
num_cmp


eql_p

public IRubyObject eql_p(ThreadContext context,
                         IRubyObject other)
num_eql


quo

public IRubyObject quo(ThreadContext context,
                       IRubyObject other)
num_quo


quo_19

public IRubyObject quo_19(ThreadContext context,
                          IRubyObject other)
num_quo


div

public IRubyObject div(ThreadContext context,
                       IRubyObject other)
num_div


divmod

public IRubyObject divmod(ThreadContext context,
                          IRubyObject other)
num_divmod


fdiv

public IRubyObject fdiv(ThreadContext context,
                        IRubyObject other)
num_fdiv (1.9)


modulo

public IRubyObject modulo(ThreadContext context,
                          IRubyObject other)
num_modulo


remainder

public IRubyObject remainder(ThreadContext context,
                             IRubyObject dividend)
num_remainder


abs

public IRubyObject abs(ThreadContext context)
num_abs


magnitude

public IRubyObject magnitude(ThreadContext context)
num_abs/1.9


to_int

public IRubyObject to_int(ThreadContext context)
num_to_int


scalar_p

public IRubyObject scalar_p()
num_real_p


integer_p

public IRubyObject integer_p()
num_int_p


zero_p

public IRubyObject zero_p(ThreadContext context)
num_zero_p


nonzero_p

public IRubyObject nonzero_p(ThreadContext context)
num_nonzero_p


floor

public IRubyObject floor()
num_floor


ceil

public IRubyObject ceil()
num_ceil


round

public IRubyObject round()
num_round


truncate

public IRubyObject truncate()
num_truncate


step

public IRubyObject step(ThreadContext context,
                        IRubyObject[] args,
                        Block block)

step

public IRubyObject step(ThreadContext context,
                        IRubyObject arg0,
                        Block block)

step19

public IRubyObject step19(ThreadContext context,
                          IRubyObject arg0,
                          Block block)

step

public IRubyObject step(ThreadContext context,
                        IRubyObject to,
                        IRubyObject step,
                        Block block)

step19

public IRubyObject step19(ThreadContext context,
                          IRubyObject to,
                          IRubyObject step,
                          Block block)

op_num_equal

protected final IRubyObject op_num_equal(ThreadContext context,
                                         IRubyObject other)
num_equal, doesn't override RubyObject.op_equal


numerator

public IRubyObject numerator(ThreadContext context)
num_numerator


denominator

public IRubyObject denominator(ThreadContext context)
num_denominator


to_c

public IRubyObject to_c(ThreadContext context)
numeric_to_c


real

public IRubyObject real(ThreadContext context)
numeric_real


image

public IRubyObject image(ThreadContext context)
numeric_image


abs2

public IRubyObject abs2(ThreadContext context)
numeric_abs2


arg

public IRubyObject arg(ThreadContext context)
numeric_arg


rect

public IRubyObject rect(ThreadContext context)
numeric_rect


polar

public IRubyObject polar(ThreadContext context)
numeric_polar


conjugate

public IRubyObject conjugate(ThreadContext context)
numeric_real



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