org.jruby
Class RubyNumeric

java.lang.Object
  extended by org.jruby.RubyObject
      extended by org.jruby.RubyNumeric
All Implemented Interfaces:
java.lang.Cloneable, IRubyObject
Direct Known Subclasses:
RubyBigDecimal, RubyFloat, RubyInteger

public class RubyNumeric
extends RubyObject

Base class for all numerical types in ruby.


Nested Class Summary
static class RubyNumeric.InvalidIntegerException
           
static class RubyNumeric.NumberTooLargeException
           
 
Nested classes/interfaces inherited from class org.jruby.RubyObject
RubyObject.Finalizer
 
Field Summary
static double DBL_EPSILON
           
protected static ObjectAllocator NUMERIC_ALLOCATOR
           
 
Fields inherited from class org.jruby.RubyObject
instanceVariables, isTrue, metaClass, NEVER, OBJECT_ALLOCATOR
 
Fields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY
 
Constructor Summary
RubyNumeric(Ruby runtime, RubyClass metaClass)
           
 
Method Summary
 IRubyObject abs()
          num_abs
 RubyNumeric asNumeric()
           
protected  IRubyObject callCoerced(java.lang.String method, IRubyObject other)
           
protected  IRubyObject callCoerced(java.lang.String method, IRubyObject other, boolean err)
           
 IRubyObject ceil()
          num_ceil
static void checkInt(IRubyObject arg, long num)
          check_int
 IRubyObject cmp(IRubyObject other)
          num_cmp
 IRubyObject coerce(IRubyObject other)
          num_coerce
protected  IRubyObject coerceBin(java.lang.String method, IRubyObject other)
          rb_num_coerce_bin coercion taking two arguments
protected  IRubyObject coerceBody(IRubyObject other)
          coerce_body
protected  IRubyObject coerceCmp(java.lang.String method, IRubyObject other)
          rb_num_coerce_cmp coercion used for comparisons
protected  IRubyObject coerceRelOp(java.lang.String method, IRubyObject other)
          rb_num_coerce_relop coercion used for relative operators
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 div(IRubyObject other)
          num_div
 IRubyObject divmod(IRubyObject other)
          num_divmod
protected  RubyArray doCoerce(IRubyObject other, boolean err)
          do_coerce
 IRubyObject eql_p(IRubyObject other)
          num_eql
 IRubyObject equal(IRubyObject other)
          num_equal
static int fix2int(IRubyObject arg)
           
static long fix2long(IRubyObject arg)
           
 IRubyObject floor()
          num_floor
protected  IRubyObject[] getCoerced(IRubyObject other, boolean error)
          Numeric methods.
 double getDoubleValue()
           
 long getLongValue()
           
 IRubyObject init_copy(IRubyObject arg)
          num_init_copy
 IRubyObject int_p()
          num_int_p
static RubyNumeric int2fix(Ruby runtime, long val)
           
 IRubyObject modulo(IRubyObject other)
          num_modulo
static RubyNumeric newNumeric(Ruby runtime)
           
 IRubyObject nonzero_p()
          num_nonzero_p
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 quo(IRubyObject other)
          num_quo
 IRubyObject remainder(IRubyObject y)
          num_remainder
 IRubyObject round()
          num_round
 IRubyObject sadded(IRubyObject name)
          num_sadded
 IRubyObject step(IRubyObject[] args, 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_int()
          num_to_int
 IRubyObject truncate()
          num_truncate
 IRubyObject uminus()
          num_uminus
 IRubyObject uplus()
          num_uplus
 IRubyObject zero_p()
          num_zero_p
 
Methods inherited from class org.jruby.RubyObject
addFinalizer, anyToString, asString, asSymbol, attachToObjectSpace, callInit, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethodMissing, callMethodMissing, callSuper, checkArrayType, checkFrozen, checkStringType, compilerCallMethod, compilerCallMethodWithIndex, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToString, convertToType, convertToType, convertToType, convertToTypeWithCheck, createObjectClass, dataGetStruct, dataWrapStruct, display, doClone, dup, eql, eqlInternal, equalInternal, equals, evalSimple, evalUnder, evalWithBinding, extend, freeze, frozen, getInstanceVariable, getInstanceVariables, getInstanceVariablesSnapshot, getJavaClass, getMetaClass, getNativeTypeIndex, getRuntime, getSingletonClass, getSingletonClassClone, getType, hash, hashCode, id_deprecated, id, infectBy, inherited, initCopy, initialize_copy, initialize, inspect, instance_eval, instance_exec, instance_of, instance_variable_get, instance_variable_set, instance_variables, instanceVariableNames, isFalse, isFrozen, isImmediate, isKindOf, isNil, isSingleton, isTaint, isTrue, kind_of, makeMetaClass, match, method, methods, nil_p, obj_equal, private_methods, protected_methods, public_methods, puts, rbClone, remove_instance_variable, removeFinalizers, removeInstanceVariable, respond_to, respondsTo, safeGetInstanceVariables, safeHasInstanceVariables, send, setFrozen, setInstanceVariable, setInstanceVariable, setInstanceVariables, setMetaClass, setTaint, singleton_methods, specificEval, taint, tainted, testFrozen, to_s, toString, trueFalseNil, trueFalseNil, type_deprecated, type, untaint
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

NUMERIC_ALLOCATOR

protected static ObjectAllocator NUMERIC_ALLOCATOR

DBL_EPSILON

public static double DBL_EPSILON
Constructor Detail

RubyNumeric

public RubyNumeric(Ruby runtime,
                   RubyClass metaClass)
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


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(IRubyObject other,
                                   boolean error)
Numeric methods. (num_*)


callCoerced

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

callCoerced

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

coerceBody

protected final IRubyObject coerceBody(IRubyObject other)
coerce_body


doCoerce

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


coerceBin

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


coerceCmp

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


coerceRelOp

protected final IRubyObject coerceRelOp(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


init_copy

public IRubyObject init_copy(IRubyObject arg)
num_init_copy


coerce

public IRubyObject coerce(IRubyObject other)
num_coerce


uplus

public IRubyObject uplus()
num_uplus


uminus

public IRubyObject uminus()
num_uminus


cmp

public IRubyObject cmp(IRubyObject other)
num_cmp


eql_p

public IRubyObject eql_p(IRubyObject other)
num_eql


quo

public IRubyObject quo(IRubyObject other)
num_quo


div

public IRubyObject div(IRubyObject other)
num_div


divmod

public IRubyObject divmod(IRubyObject other)
num_divmod


modulo

public IRubyObject modulo(IRubyObject other)
num_modulo


remainder

public IRubyObject remainder(IRubyObject y)
num_remainder


abs

public IRubyObject abs()
num_abs


to_int

public IRubyObject to_int()
num_to_int


int_p

public IRubyObject int_p()
num_int_p


zero_p

public IRubyObject zero_p()
num_zero_p


nonzero_p

public IRubyObject nonzero_p()
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(IRubyObject[] args,
                        Block block)

equal

public IRubyObject equal(IRubyObject other)
num_equal

Specified by:
equal in interface IRubyObject
Overrides:
equal in class RubyObject


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