public class RubyNumeric extends RubyObject
Modifier and Type | Class and Description |
---|---|
static class |
RubyNumeric.InvalidIntegerException |
static class |
RubyNumeric.NumberTooLargeException |
RubyObject.Data
RubyBasicObject.Finalizer
Modifier and Type | Field and Description |
---|---|
static double |
DBL_EPSILON |
protected static ObjectAllocator |
NUMERIC_ALLOCATOR |
FIELD_ALLOCATED_CLASSES, FIELD_ALLOCATOR_SET, FIELD_ALLOCATORS, IVAR_INSPECTING_OBJECT_ALLOCATOR, OBJECT_ALLOCATOR, OBJECT_VAR0_ALLOCATOR, OBJECT_VAR1_ALLOCATOR, OBJECT_VAR2_ALLOCATOR, OBJECT_VAR3_ALLOCATOR, OBJECT_VAR4_ALLOCATOR, OBJECT_VAR5_ALLOCATOR, OBJECT_VAR6_ALLOCATOR, OBJECT_VAR7_ALLOCATOR, OBJECT_VAR8_ALLOCATOR, OBJECT_VAR9_ALLOCATOR, REIFYING_OBJECT_ALLOCATOR
ALL_F, BASICOBJECT_ALLOCATOR, COMPARE_BY_IDENTITY_F, ERR_INSECURE_SET_INST_VAR, FALSE_F, FL_USHIFT, flags, FROZEN_F, IS_OVERLAID_F, metaClass, NEVER, NIL_F, REFINED_MODULE_F, STAMP_OFFSET, TAINTED_F, UNDEF, UNTRUST_F, USER0_F, USER1_F, USER2_F, USER3_F, USER4_F, USER5_F, USER6_F, USER7_F, USER8_F, USER9_F, USERA_F, VAR_TABLE_OFFSET, varTable, varTableStamp
NULL_ARRAY
Constructor and Description |
---|
RubyNumeric(RubyClass metaClass) |
RubyNumeric(Ruby runtime,
RubyClass metaClass) |
RubyNumeric(Ruby runtime,
RubyClass metaClass,
boolean useObjectSpace) |
RubyNumeric(Ruby runtime,
RubyClass metaClass,
boolean useObjectSpace,
boolean canBeTainted)
Deprecated.
|
Modifier and Type | Method and Description |
---|---|
IRubyObject |
abs(ThreadContext context)
num_abs
|
IRubyObject |
abs2(ThreadContext context)
numeric_abs2
|
IRubyObject |
arg(ThreadContext context)
numeric_arg
|
RubyNumeric |
asNumeric() |
IRubyObject |
callCoerced(ThreadContext context,
CallSite site,
IRubyObject other) |
protected IRubyObject |
callCoerced(ThreadContext context,
CallSite site,
IRubyObject other,
boolean err) |
IRubyObject |
callCoerced(ThreadContext context,
String method,
IRubyObject other) |
protected IRubyObject |
callCoerced(ThreadContext context,
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,
CallSite site,
IRubyObject other) |
protected IRubyObject |
coerceBin(ThreadContext context,
String method,
IRubyObject other)
rb_num_coerce_bin
coercion taking two arguments
|
protected IRubyObject |
coerceBit(ThreadContext context,
CallSite site,
IRubyObject other) |
protected IRubyObject |
coerceBit(ThreadContext context,
String method,
IRubyObject other)
rb_num_coerce_bit
coercion taking two arguments
|
protected IRubyObject |
coerceBody(ThreadContext context,
IRubyObject other)
coerce_body
|
protected IRubyObject |
coerceCmp(ThreadContext context,
CallSite site,
IRubyObject other) |
protected IRubyObject |
coerceCmp(ThreadContext context,
String method,
IRubyObject other)
rb_num_coerce_cmp
coercion used for comparisons
|
protected void |
coerceFailed(ThreadContext context,
IRubyObject other)
coerce_failed
|
protected IRubyObject |
coerceRelOp(ThreadContext context,
CallSite site,
IRubyObject other) |
protected IRubyObject |
coerceRelOp(ThreadContext context,
String method,
IRubyObject other)
rb_num_coerce_relop
coercion used for relative operators
|
protected IRubyObject |
coerceRescue(ThreadContext context,
IRubyObject other)
coerce_rescue
|
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 |
div19(ThreadContext context,
IRubyObject other)
num_div
|
IRubyObject |
divmod(ThreadContext context,
IRubyObject other)
num_divmod
|
IRubyObject |
divmod19(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 int |
fix2int(RubyFixnum arg) |
static long |
fix2long(IRubyObject arg) |
static double |
floatStepSize(double beg,
double end,
double unit,
boolean excludeLast)
Returns the number of unit-sized steps between the given beg and end.
|
IRubyObject |
floor()
num_floor
|
BigInteger |
getBigIntegerValue() |
protected IRubyObject[] |
getCoerced(ThreadContext context,
IRubyObject other,
boolean error)
Numeric methods.
|
double |
getDoubleValue() |
int |
getIntValue()
Return the value of this numeric as a 32-bit long.
|
long |
getLongValue()
Return the value of this numeric as a 64-bit long.
|
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
|
static RubyNumeric |
intervalStepSize(ThreadContext context,
IRubyObject from,
IRubyObject to,
IRubyObject step,
boolean excludeLast) |
IRubyObject |
isNegative(ThreadContext context)
num_negative_p
|
IRubyObject |
isPositive(ThreadContext context)
num_positive_p
|
IRubyObject |
magnitude(ThreadContext context)
num_abs/1.9
|
IRubyObject |
modulo(ThreadContext context,
IRubyObject other)
num_modulo
|
IRubyObject |
modulo19(ThreadContext context,
IRubyObject other)
num_modulo
|
static RubyNumeric |
newNumeric(Ruby runtime) |
IRubyObject |
nonzero_p(ThreadContext context)
num_nonzero_p
|
IRubyObject |
num_imaginary(ThreadContext context)
num_imaginary
|
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 (1.9)
|
IRubyObject |
quo(ThreadContext context,
IRubyObject other)
num_quo (1.8)
quo and fdiv in 1.8 just invokes "/"
|
IRubyObject |
real(ThreadContext context)
numeric_real
|
IRubyObject |
rect(ThreadContext context)
numeric_rect
|
IRubyObject |
remainder(ThreadContext context,
IRubyObject dividend)
num_remainder
|
IRubyObject |
round()
num_round
|
static IRubyObject |
sadded(IRubyObject self,
IRubyObject name)
num_sadded
|
IRubyObject |
scalar_p()
num_real_p
|
IRubyObject |
step(ThreadContext context,
IRubyObject[] args,
Block block)
num_step
|
static RubyFloat |
str2fnum(Ruby runtime,
RubyString arg)
Same as RubyNumeric.str2fnum passing false for strict.
|
static RubyFloat |
str2fnum(Ruby runtime,
RubyString arg,
boolean strict)
Converts a string representation of a floating-point number to the
numeric value.
|
static RubyFloat |
str2fnum19(Ruby runtime,
RubyString arg,
boolean strict)
Deprecated.
|
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
|
Object |
toJava(Class target)
Convert the object to the specified Java class, if possible.
|
IRubyObject |
truncate()
num_truncate
|
IRubyObject |
zero_p(ThreadContext context)
num_zero_p
|
attachToObjectSpace, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, convertToType, createObjectClass, dig, eqlInternal, equalInternal, equals, getNativeClassIndex, hashCode, inspect, op_eqq, puts, specificEval, toString
addFinalizer, anyToString, asJavaString, asString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkCallMethod, checkCallMethod, checkFrozen, checkStringType, checkStringType19, compareTo, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, createBasicObjectClass, dataGetStruct, dataGetStructChecked, dataWrapStruct, display, dup, ensureInstanceVariablesSettable, eql_p, eql, equal_p, equal_p19, evalUnder, extend, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, freeze, frozen_p, getFFIHandle, getFlag, getInstanceEvalClass, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getJavaClass, getMetaClass, getNativeHandle, getNativeTypeIndex, getObjectId, getRuntime, getSingletonClass, getSingletonClassClone, getSingletonClassCloneAndAttach, getType, getVariable, getVariableCount, getVariableList, getVariableNameList, hash, hashyInspect, hasInstanceVariable, hasInternalVariable, hasVariables, id, infectBy, initialize, initialize, initialize19, inspect, inspectHashCode, instance_eval, instance_eval, instance_eval, instance_eval, instance_eval19, instance_eval19, instance_eval19, instance_eval19, instance_exec, instance_exec19, instance_of_p, instance_variable_defined_p, instance_variable_get, instance_variable_set, instance_variables, instance_variables19, isBuiltin, isClass, isFalse, isFrozen, isImmediate, isModule, isNil, isSpecialConst, isTaint, isTrue, isUntrusted, kind_of_p, makeMetaClass, method_missing19, method, method19, methods, methods, methods19, nil_p, nonFixnumHashCode, OBJ_INIT_COPY, objInitCopy, op_cmp, op_equal_19, op_equal, op_match, op_match19, op_not_equal, op_not_match, op_not, private_methods, private_methods19, protected_methods, protected_methods19, public_methods, public_methods19, rbClone, rbInspect, remove_instance_variable, removeFinalizers, removeInstanceVariable, removeInternalVariable, respond_to_p, respond_to_p, respond_to_p19, respond_to_p19, respondsTo, respondsToMissing, respondsToMissing, send, send, send, send, send, send19, send19, send19, send19, setFFIHandle, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setNativeHandle, setTaint, setUntrusted, setVariable, singleton_method_added19, singleton_method_removed19, singleton_method_undefined19, singleton_methods, specificEval, specificEval, specificEval, specificEval, syncVariables, syncVariables, taint, taint, tainted_p, testFrozen, testFrozen, to_a, to_s, trust, type_deprecated, type, untaint, untrust, untrusted_p, validateInstanceVariable, validateInstanceVariable, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableRemove, variableTableStore, variableTableSync, yieldUnder, yieldUnder
protected static final ObjectAllocator NUMERIC_ALLOCATOR
public static final double DBL_EPSILON
public RubyNumeric(RubyClass metaClass)
@Deprecated public RubyNumeric(Ruby runtime, RubyClass metaClass, boolean useObjectSpace, boolean canBeTainted)
public double getDoubleValue()
public long getLongValue()
public int getIntValue()
public BigInteger getBigIntegerValue()
public static RubyNumeric newNumeric(Ruby runtime)
public static int num2int(IRubyObject arg)
public static void checkInt(IRubyObject arg, long num)
public static byte num2chr(IRubyObject arg)
public static long num2long(IRubyObject arg)
public static IRubyObject dbl2num(Ruby runtime, double val)
public static double num2dbl(IRubyObject arg)
public static IRubyObject dbl_cmp(Ruby runtime, double a, double b)
public static long fix2long(IRubyObject arg)
public static int fix2int(IRubyObject arg)
public static int fix2int(RubyFixnum arg)
public static RubyInteger str2inum(Ruby runtime, RubyString str, int base)
public static RubyNumeric int2fix(Ruby runtime, long val)
public static IRubyObject num2fix(IRubyObject val)
public static RubyInteger str2inum(Ruby runtime, RubyString str, int base, boolean strict)
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.runtime
- the ruby runtimestr
- the string to be convertedbase
- 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/criteriapublic static RubyFloat str2fnum(Ruby runtime, RubyString arg)
runtime
- the ruby runtimearg
- the string to be convertedpublic static RubyFloat str2fnum(Ruby runtime, RubyString arg, boolean strict)
runtime
- the ruby runtimearg
- the string to be convertedstrict
- 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/criteriaprotected final IRubyObject[] getCoerced(ThreadContext context, IRubyObject other, boolean error)
protected IRubyObject callCoerced(ThreadContext context, String method, IRubyObject other, boolean err)
public IRubyObject callCoerced(ThreadContext context, String method, IRubyObject other)
protected IRubyObject callCoerced(ThreadContext context, CallSite site, IRubyObject other, boolean err)
public IRubyObject callCoerced(ThreadContext context, CallSite site, IRubyObject other)
protected final IRubyObject coerceBody(ThreadContext context, IRubyObject other)
protected final RubyArray doCoerce(ThreadContext context, IRubyObject other, boolean err)
protected final IRubyObject coerceRescue(ThreadContext context, IRubyObject other)
protected final void coerceFailed(ThreadContext context, IRubyObject other)
protected final IRubyObject coerceBin(ThreadContext context, String method, IRubyObject other)
protected final IRubyObject coerceBin(ThreadContext context, CallSite site, IRubyObject other)
protected final IRubyObject coerceBit(ThreadContext context, String method, IRubyObject other)
protected final IRubyObject coerceBit(ThreadContext context, CallSite site, IRubyObject other)
protected final IRubyObject coerceCmp(ThreadContext context, String method, IRubyObject other)
protected final IRubyObject coerceCmp(ThreadContext context, CallSite site, IRubyObject other)
protected final IRubyObject coerceRelOp(ThreadContext context, String method, IRubyObject other)
protected final IRubyObject coerceRelOp(ThreadContext context, CallSite site, IRubyObject other)
public RubyNumeric asNumeric()
public static IRubyObject sadded(IRubyObject self, IRubyObject name)
public IRubyObject initialize_copy(IRubyObject arg)
initialize_copy
in class RubyBasicObject
public IRubyObject coerce(IRubyObject other)
public IRubyObject op_uplus()
public IRubyObject num_imaginary(ThreadContext context)
public IRubyObject op_uminus(ThreadContext context)
public IRubyObject op_cmp(IRubyObject other)
public IRubyObject eql_p(ThreadContext context, IRubyObject other)
public IRubyObject quo(ThreadContext context, IRubyObject other)
public IRubyObject quo_19(ThreadContext context, IRubyObject other)
public IRubyObject div(ThreadContext context, IRubyObject other)
public IRubyObject div19(ThreadContext context, IRubyObject other)
public IRubyObject divmod(ThreadContext context, IRubyObject other)
public IRubyObject divmod19(ThreadContext context, IRubyObject other)
public IRubyObject fdiv(ThreadContext context, IRubyObject other)
public IRubyObject modulo(ThreadContext context, IRubyObject other)
public IRubyObject modulo19(ThreadContext context, IRubyObject other)
public IRubyObject remainder(ThreadContext context, IRubyObject dividend)
public IRubyObject abs(ThreadContext context)
public IRubyObject magnitude(ThreadContext context)
public IRubyObject to_int(ThreadContext context)
public IRubyObject scalar_p()
public IRubyObject integer_p()
public IRubyObject zero_p(ThreadContext context)
public IRubyObject nonzero_p(ThreadContext context)
public IRubyObject floor()
public IRubyObject ceil()
public IRubyObject round()
public IRubyObject truncate()
public IRubyObject step(ThreadContext context, IRubyObject[] args, Block block)
public static RubyNumeric intervalStepSize(ThreadContext context, IRubyObject from, IRubyObject to, IRubyObject step, boolean excludeLast)
public static double floatStepSize(double beg, double end, double unit, boolean excludeLast)
protected final IRubyObject op_num_equal(ThreadContext context, IRubyObject other)
public IRubyObject numerator(ThreadContext context)
public IRubyObject denominator(ThreadContext context)
public IRubyObject to_c(ThreadContext context)
public IRubyObject real(ThreadContext context)
public IRubyObject image(ThreadContext context)
public IRubyObject abs2(ThreadContext context)
public IRubyObject arg(ThreadContext context)
public IRubyObject rect(ThreadContext context)
public IRubyObject polar(ThreadContext context)
public IRubyObject conjugate(ThreadContext context)
public Object toJava(Class target)
IRubyObject
toJava
in interface IRubyObject
toJava
in class RubyBasicObject
target
- The target type to which the object should be converted.IRubyObject.toJava(java.lang.Class)
public IRubyObject isNegative(ThreadContext context)
public IRubyObject isPositive(ThreadContext context)
@Deprecated public static RubyFloat str2fnum19(Ruby runtime, RubyString arg, boolean strict)
Copyright © 2001-2017 JRuby. All Rights Reserved.