Package org.jruby
Class RubyFloat
java.lang.Object
org.jruby.RubyBasicObject
org.jruby.RubyObject
org.jruby.RubyNumeric
org.jruby.RubyFloat
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<IRubyObject>,InstanceVariables,InternalVariables,IRubyObject,CoreObjectType
A representation of a float object
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.jruby.RubyNumeric
RubyNumeric.InvalidIntegerException, RubyNumeric.NumberTooLargeExceptionNested classes/interfaces inherited from class org.jruby.RubyObject
RubyObject.DataNested classes/interfaces inherited from class org.jruby.RubyBasicObject
RubyBasicObject.Finalizer -
Field Summary
FieldsModifier and TypeFieldDescription(package private) static final intfloat_to_r, float_decodestatic final intstatic final doublestatic final intstatic final doubleprivate static final ByteListstatic final intstatic final intstatic final intstatic final intstatic final intstatic final doubleprivate static final ByteListprivate static final ByteListstatic final intstatic final int(package private) final doubleFields inherited from class org.jruby.RubyNumeric
DBL_EPSILONFields inherited from class org.jruby.RubyObject
IVAR_INSPECTING_OBJECT_ALLOCATOR, OBJECT_ALLOCATOR, REIFYING_OBJECT_ALLOCATORFields inherited from class org.jruby.RubyBasicObject
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, varTableStampFields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabs(ThreadContext context) flo_absceil(ThreadContext context) MRI: flo_ceilceil(ThreadContext context, IRubyObject digits) MRI: flo_ceilcoerce(IRubyObject other) flo_coercefinal intcompareTo(IRubyObject other) Compares this Ruby object with another.Tries to convert this object to a Ruby Float using the "to_f" method.Tries to convert this object to a Ruby Integer using the "to_int" method.static RubyClasscreateFloatClass(Ruby runtime) denominator(ThreadContext context) flo_denominatordivmod(ThreadContext context, IRubyObject other) flo_divmodprivate static doubledoRound(ThreadContext context, RoundingMode roundingMode, double number, double scale) final booleaneql(IRubyObject other) short circuit for Float key comparisoneql_p(IRubyObject other) flo_eqlequal_p(ThreadContext context, IRubyObject obj) Compare this Float object with the given object and determine whether they are effectively identical.booleanThis override does not do a "checked" dispatch.private booleanbooleanfinite_p()flo_is_finite_pprivate static longprivate static booleanfloatRoundOverflow(int ndigits, long[] binexp) private static booleanfloatRoundUnderflow(int ndigits, long[] binexp) private static booleanflonumable(double value) Determine if the given double value is representable as a "flonum", a bit-manipulated version of itself that emulates the CRuby "flonum" tagged pointer.private static booleanflonumRange(long longBits) Determine if the given double bits are in the "flonum" range, excluding positive zero.floor(ThreadContext context) MRI: flo_floorfloor(ThreadContext context, IRubyObject digits) MRI: flo_floorfloor(ThreadContext context, IRubyObject[] args) Deprecated.doubleintReturn the value of this numeric as a 32-bit long.Class<?>Will return the Java interface that most closely can represent this object, when working through Java integration translations.longReturn the value of this numeric as a 64-bit long.This is overridden in the other concrete Java builtins to provide a fast way to determine what type they are.rb_singleton_class Note: this method is specialized for RubyFixnum, RubySymbol, RubyNil and RubyBoolean Will either return the existing singleton class for this object, or create a new one and return that.doublegetValue()Getter for property value.hash()flo_hashfinal inthashCode()This override does not do "checked" dispatch since Object usually has #hash defined.id()Produce an object ID for this Float.static IRubyObjectinduced_from(ThreadContext context, IRubyObject recv, IRubyObject number) Deprecated.flo_is_infinite_pbooleanbooleanisNaN()booleanisNegative(ThreadContext context) num_negative_pbooleanisPositive(ThreadContext context) num_positive_pfinal booleanisZero()magnitude(ThreadContext context) flo_abs/1.9private ByteListstatic voidmarshalTo(RubyFloat aFloat, MarshalStream output) nan_p()flo_is_nan_pstatic RubyFloatnonzero_p(ThreadContext context) num_nonzero_pnumerator(ThreadContext context) flo_numeratorop_cmp(ThreadContext context, double other) op_cmp(ThreadContext context, IRubyObject other) flo_cmpop_div(ThreadContext context, double other) op_div(ThreadContext context, IRubyObject other) MRI: flo_divop_equal(ThreadContext context, double other) op_equal(ThreadContext context, IRubyObject other) flo_eqop_ge(ThreadContext context, double other) op_ge(ThreadContext context, IRubyObject other) flo_geop_gt(ThreadContext context, double other) op_gt(ThreadContext context, IRubyObject other) flo_gtop_le(ThreadContext context, double other) op_le(ThreadContext context, IRubyObject other) flo_leop_lt(ThreadContext context, double other) op_lt(ThreadContext context, IRubyObject other) flo_ltop_minus(ThreadContext context, double other) op_minus(ThreadContext context, IRubyObject other) flo_minusop_mod(ThreadContext context, double other) op_mod(ThreadContext context, IRubyObject other) flo_modfinal IRubyObjectop_mod19(ThreadContext context, IRubyObject other) Deprecated.op_mul(ThreadContext context, double other) op_mul(ThreadContext context, IRubyObject other) flo_mulop_plus(ThreadContext context, double other) op_plus(ThreadContext context, IRubyObject other) flo_plusop_pow(ThreadContext context, double other) op_pow(ThreadContext context, IRubyObject other) flo_powop_pow19(ThreadContext context, IRubyObject other) Deprecated.Deprecated.op_uminus(ThreadContext context) flo_uminusprivate static booleanpositiveZero(long longBits) Determine of the given double bits represent positive zero.quo(ThreadContext context, IRubyObject other) flo_quorationalize(ThreadContext context, IRubyObject[] args) float_rationalizeround(ThreadContext context) MRI: flo_roundround(ThreadContext context, IRubyObject arg0) MRI: flo_roundround(ThreadContext context, IRubyObject[] args) Deprecated.round(ThreadContext context, IRubyObject _digits, IRubyObject _opts) MRI: flo_roundprivate static doubleroundHalfDown(double x, double s) private static doubleroundHalfEven(double x, double s) private static doubleroundHalfUp(double n) private static doubleroundHalfUp(double x, double s) roundShared(ThreadContext context, int ndigits, RoundingMode mode) intsignum()private static JavaSites.FloatSitessites(ThreadContext context) to_f()flo_foto_r(ThreadContext context) to_s()flo_to_sprivate RubyIntegertruncate(ThreadContext context) MRI: flo_truncatetruncate(ThreadContext context, IRubyObject n) MRI: flo_truncatestatic RubyFloatunmarshalFrom(UnmarshalStream input) zero_p()Deprecated.zero_p(ThreadContext context) MRI: flo_zero_pMethods inherited from class org.jruby.RubyNumeric
abs2, arg, asNumeric, callCoerced, callCoerced, callCoerced, callCoerced, ceil, checkInt, checkInt, coerceBin, coerceBin, coerceBit, coerceBit, coerceBody, coerceCmp, coerceCmp, coerceFailed, coerceRelOp, coerceRelOp, coerceRescue, compareWithZero, conjugate, convertToRational, createNumericClass, dbl_cmp, dbl2ival, dbl2num, div, div19, divmod19, doCoerce, dup, eql_p, fdiv, finite_p, fix2int, fix2int, fix2long, fixable, float2long, float2ulong, floatStep, floatStep, floatStepSize, floor, getCoerced, getRoundingMode, idiv, idiv, image, infinite_p, initialize_copy, int2fix, integer_p, intervalStepSize, isReal, modulo, modulo, modulo19, negativeInt, negFixable, negFixable, newNumeric, num_imaginary, num2chr, num2dbl, num2dbl, num2fix, num2int, num2long, num2ulong, numFuncall, numFuncall, numRemainder, op_cmp, op_not, op_num_equal, op_uplus, polar, posFixable, posFixable, positiveInt, quo_19, rbClone, rbClone, rbClone, rbClone, real, real_p, rect, remainder, round, scalar_p, singleton_method_added, step, str2fnum, str2fnum, str2fnum, str2fnum19, str2inum, str2inum, str2inum, to_c, to_int, toJava, truncateMethods inherited from class org.jruby.RubyObject
attachToObjectSpace, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, convertToType, createObjectClass, dig, dig1, dig2, eqlInternal, equalInternal, inspect, op_eqq, puts, specificEval, toRubyString, toStringMethods inherited from class org.jruby.RubyBasicObject
addFinalizer, anyToString, asJavaString, asString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkCallMethod, checkCallMethod, checkFrozen, checkStringType, checkStringType19, convertToArray, convertToHash, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, createBasicObjectClass, dataGetStruct, dataGetStructChecked, dataWrapStruct, decode, defaultToJava, display, ensureInstanceVariablesSettable, equal_p19, evalUnder, extend, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, freeze, frozen_p, getFFIHandle, getFlag, getInstanceEvalClass, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getMetaClass, getMetaClass, getNativeHandle, getNativeTypeIndex, getObjectId, getRuntime, getSingletonClassClone, getSingletonClassCloneAndAttach, getType, getVariable, getVariableCount, getVariableList, getVariableNameList, hashyInspect, hasInstanceVariable, hasInstanceVariables, hasInternalVariable, hasVariables, infectBy, infectBy, infectBy, 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, isSpecialObject, isTaint, isTrue, isUntrusted, kind_of_p, makeMetaClass, method, method_missing, method_missing19, method19, methods, methods, methods19, methodsImpl, nil_p, nonFixnumHashCode, OBJ_INIT_COPY, objInitCopy, op_equal_19, op_match, op_match19, op_not_equal, op_not_match, private_methods, private_methods19, protected_methods, protected_methods19, public_methods, public_methods19, rbInspect, recacheBuiltinMethods, remove_instance_variable, removeFinalizers, removeInstanceVariable, removeInternalVariable, respond_to_p, 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, singleton_method_added, singleton_method_added19, singleton_method_removed, singleton_method_removed19, singleton_method_undefined, singleton_method_undefined19, singleton_methods, specificEval, specificEval, specificEval, specificEval, syncVariables, syncVariables, taint, taint, tainted, tainted_p, testFrozen, testFrozen, to_a, to_a, trust, type, type_deprecated, untaint, untrust, untrusted_p, validateInstanceVariable, validateInstanceVariable, validateInstanceVariable, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableRemove, variableTableStore, variableTableSync, yieldUnder, yieldUnder
-
Field Details
-
ROUNDS
public static final int ROUNDS- See Also:
-
RADIX
public static final int RADIX- See Also:
-
MANT_DIG
public static final int MANT_DIG- See Also:
-
DIG
public static final int DIG- See Also:
-
MIN_EXP
public static final int MIN_EXP- See Also:
-
MAX_EXP
public static final int MAX_EXP- See Also:
-
MAX_10_EXP
public static final int MAX_10_EXP- See Also:
-
MIN_10_EXP
public static final int MIN_10_EXP- See Also:
-
EPSILON
public static final double EPSILON- See Also:
-
INFINITY
public static final double INFINITY- See Also:
-
NAN
public static final double NAN- See Also:
-
FLOAT_DIG
public static final int FLOAT_DIG- See Also:
-
value
final double value -
DBL_MANT_DIG
static final int DBL_MANT_DIGfloat_to_r, float_decode- See Also:
-
NAN_BYTELIST
-
NEGATIVE_INFINITY_BYTELIST
-
INFINITY_BYTELIST
-
-
Constructor Details
-
RubyFloat
-
RubyFloat
-
RubyFloat
-
-
Method Details
-
createFloatClass
-
getNativeClassIndex
Description copied from class:RubyObjectThis is overridden in the other concrete Java builtins to provide a fast way to determine what type they are. Will generally return a value from org.jruby.runtime.ClassIndex- Specified by:
getNativeClassIndexin interfaceCoreObjectType- Overrides:
getNativeClassIndexin classRubyObject- See Also:
-
getSingletonClass
Description copied from class:RubyBasicObjectrb_singleton_class Note: this method is specialized for RubyFixnum, RubySymbol, RubyNil and RubyBoolean Will either return the existing singleton class for this object, or create a new one and return that.- Specified by:
getSingletonClassin interfaceIRubyObject- Overrides:
getSingletonClassin classRubyBasicObject- Returns:
- the Ruby singleton class
-
getJavaClass
Description copied from class:RubyBasicObjectWill return the Java interface that most closely can represent this object, when working through Java integration translations.- Specified by:
getJavaClassin interfaceIRubyObject- Overrides:
getJavaClassin classRubyBasicObject- Returns:
- the true Java class of this (Ruby) object
-
getValue
public double getValue()Getter for property value.- Returns:
- Value of property value.
-
getDoubleValue
public double getDoubleValue()- Overrides:
getDoubleValuein classRubyNumeric
-
getLongValue
public long getLongValue()Description copied from class:RubyNumericReturn the value of this numeric as a 64-bit long. If the value does not fit in 64 bits, it will be truncated.- Overrides:
getLongValuein classRubyNumeric
-
getIntValue
public int getIntValue()Description copied from class:RubyNumericReturn the value of this numeric as a 32-bit long. If the value does not fit in 32 bits, it will be truncated.- Overrides:
getIntValuein classRubyNumeric
-
getBigIntegerValue
- Overrides:
getBigIntegerValuein classRubyNumeric
-
convertToFloat
Description copied from class:RubyBasicObjectTries to convert this object to a Ruby Float using the "to_f" method.- Specified by:
convertToFloatin interfaceIRubyObject- Overrides:
convertToFloatin classRubyBasicObject- Returns:
- float representation of this
-
convertToInteger
Description copied from class:RubyBasicObjectTries to convert this object to a Ruby Integer using the "to_int" method.- Specified by:
convertToIntegerin interfaceIRubyObject- Overrides:
convertToIntegerin classRubyBasicObject- Returns:
- an integer representation of this
-
toInteger
-
signum
public int signum() -
isNegative
Description copied from class:RubyNumericnum_negative_p- Overrides:
isNegativein classRubyNumeric
-
isPositive
Description copied from class:RubyNumericnum_positive_p- Overrides:
isPositivein classRubyNumeric
-
isNegative
public boolean isNegative()- Overrides:
isNegativein classRubyNumeric
-
isPositive
public boolean isPositive()- Overrides:
isPositivein classRubyNumeric
-
newFloat
-
induced_from
@Deprecated public static IRubyObject induced_from(ThreadContext context, IRubyObject recv, IRubyObject number) Deprecated.rb_flo_induced_from -
to_s
flo_to_s- Overrides:
to_sin classRubyBasicObject
-
coerce
flo_coerce- Overrides:
coercein classRubyNumeric
-
op_uminus
flo_uminus- Overrides:
op_uminusin classRubyNumeric
-
op_uminus
Deprecated. -
op_plus
flo_plus- Overrides:
op_plusin classRubyNumeric
-
op_plus
-
op_minus
flo_minus- Overrides:
op_minusin classRubyNumeric
-
op_minus
-
op_mul
flo_mul -
op_mul
-
op_div
MRI: flo_div -
op_div
-
quo
flo_quo- Overrides:
quoin classRubyNumeric
-
op_mod
flo_mod -
op_mod
-
op_mod19
Deprecated. -
divmod
flo_divmod- Overrides:
divmodin classRubyNumeric
-
op_pow
flo_pow -
op_pow
-
op_pow19
Deprecated. -
op_equal
flo_eq- Specified by:
op_equalin interfaceIRubyObject- Overrides:
op_equalin classRubyBasicObject
-
op_equal
-
fastEqual
-
compareTo
Description copied from class:RubyBasicObjectCompares this Ruby object with another.- Specified by:
compareToin interfaceComparable<IRubyObject>- Overrides:
compareToin classRubyBasicObject- Parameters:
other- another IRubyObject- Returns:
- 0 if equal, < 0 if this is less than other, > 0 if this is greater than other
-
op_cmp
flo_cmp- Overrides:
op_cmpin classRubyBasicObject
-
op_cmp
-
op_gt
flo_gt -
op_gt
-
op_ge
flo_ge -
op_ge
-
op_lt
flo_lt -
op_lt
-
op_le
flo_le -
op_le
-
eql_p
flo_eql- Overrides:
eql_pin classRubyBasicObject
-
eql
short circuit for Float key comparison- Specified by:
eqlin interfaceIRubyObject- Overrides:
eqlin classRubyBasicObject
-
equals
Description copied from class:RubyObjectThis override does not do a "checked" dispatch.- Overrides:
equalsin classRubyObject- See Also:
-
equals
-
hash
flo_hash- Overrides:
hashin classRubyBasicObject
-
hashCode
public final int hashCode()Description copied from class:RubyObjectThis override does not do "checked" dispatch since Object usually has #hash defined.- Overrides:
hashCodein classRubyObject- See Also:
-
floatHash
-
to_f
flo_fo -
abs
flo_abs- Overrides:
absin classRubyNumeric
-
magnitude
flo_abs/1.9- Overrides:
magnitudein classRubyNumeric
-
zero_p
MRI: flo_zero_p- Overrides:
zero_pin classRubyNumeric
-
isZero
public final boolean isZero()- Overrides:
isZeroin classRubyNumeric
-
nonzero_p
Description copied from class:RubyNumericnum_nonzero_p- Overrides:
nonzero_pin classRubyNumeric
-
truncate
MRI: flo_truncate- Overrides:
truncatein classRubyNumeric
-
truncate
MRI: flo_truncate -
numerator
flo_numerator- Overrides:
numeratorin classRubyNumeric
-
denominator
flo_denominator- Overrides:
denominatorin classRubyNumeric
-
to_r
-
rationalize
float_rationalize -
floor
MRI: flo_floor- Overrides:
floorin classRubyNumeric
-
floor
MRI: flo_floor -
floatRoundOverflow
private static boolean floatRoundOverflow(int ndigits, long[] binexp) -
floatRoundUnderflow
private static boolean floatRoundUnderflow(int ndigits, long[] binexp) -
ceil
MRI: flo_ceil- Overrides:
ceilin classRubyNumeric
-
ceil
MRI: flo_ceil -
round
MRI: flo_round- Overrides:
roundin classRubyNumeric
-
round
MRI: flo_round -
round
MRI: flo_round -
doRound
private static double doRound(ThreadContext context, RoundingMode roundingMode, double number, double scale) -
roundHalfUp
private static double roundHalfUp(double x, double s) -
roundHalfDown
private static double roundHalfDown(double x, double s) -
roundHalfUp
private static double roundHalfUp(double n) -
roundHalfEven
private static double roundHalfEven(double x, double s) -
nan_p
flo_is_nan_p -
isNaN
public boolean isNaN() -
infinite_p
flo_is_infinite_p -
isInfinite
public boolean isInfinite() -
finite_p
flo_is_finite_p -
marshalDump
-
marshalTo
- Throws:
IOException
-
unmarshalFrom
- Throws:
IOException
-
next_float
-
prev_float
-
id
Produce an object ID for this Float. Values within the "flonum" range will produce a special object ID that emulates the CRuby tagged "flonum" pointer logic. This ID is never registered but can be reversed by ObjectSpace._id2ref using the same bit manipulation as in CRuby.- Specified by:
idin interfaceIRubyObject- Overrides:
idin classRubyBasicObject- Returns:
- the object ID for this Float
-
equal_p
Compare this Float object with the given object and determine whether they are effectively identical. This logic for Float considers all values in the "flonum" range to be identical, since in CRuby they would have the same pointer value (a tagged "flonum" pointer). We do not support flonums, but emulate this behavior for compatibility.- Overrides:
equal_pin classRubyBasicObject- Parameters:
context- the current contextobj- the object with which to compare- Returns:
- true if this Float and the given object are effectively identical, false otherwise
-
flonumable
private static boolean flonumable(double value) Determine if the given double value is representable as a "flonum", a bit-manipulated version of itself that emulates the CRuby "flonum" tagged pointer.- Parameters:
value- the double value in question- Returns:
- true of the value can be represented as a "flonum", false otherwise
-
flonumRange
private static boolean flonumRange(long longBits) Determine if the given double bits are in the "flonum" range, excluding positive zero.- Parameters:
longBits- the bits of the double in question- Returns:
- true if the double is in the non-zero "flonum" range, false otherwise
-
positiveZero
private static boolean positiveZero(long longBits) Determine of the given double bits represent positive zero.- Parameters:
longBits- the bits of the double in question- Returns:
- true of the bits represent positive zero, false otherwise
-
zero_p
Deprecated. -
floor
Deprecated. -
round
Deprecated. -
sites
-