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>
,Appendable
,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.NumberTooLargeException
Nested classes/interfaces inherited from class org.jruby.RubyObject
RubyObject.Data
Nested classes/interfaces inherited from class org.jruby.RubyBasicObject
RubyBasicObject.Finalizer
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final double
static final int
static final double
static final int
static final int
static final int
static final int
static final int
static final double
static final ByteList
static final ByteList
static final ByteList
static final int
static final int
Fields inherited from class org.jruby.RubyNumeric
DBL_EPSILON
Fields inherited from class org.jruby.RubyObject
IVAR_INSPECTING_OBJECT_ALLOCATOR, OBJECT_ALLOCATOR, REIFYING_OBJECT_ALLOCATOR
Fields 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, 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
Fields inherited from interface org.jruby.runtime.builtin.IRubyObject
NULL_ARRAY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabs
(ThreadContext context) flo_absvoid
appendIntoString
(RubyString target) asBigInteger
(ThreadContext context) Return a BigInteger representation of this numerical valuedouble
asDouble
(ThreadContext context) Return a double representation of this numerical valueint
asInt
(ThreadContext context) Returns the value of this numeric and a java int.long
asLong
(ThreadContext context) Return the value of this numeric as a 64-bit long.ceil
(ThreadContext context) MRI: flo_ceilceil
(ThreadContext context, IRubyObject digits) MRI: flo_ceilcoerce
(ThreadContext context, IRubyObject other) num_coercefinal int
compareTo
(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 RubyClass
createFloatClass
(ThreadContext context, RubyClass Numeric) denominator
(ThreadContext context) flo_denominatordivmod
(ThreadContext context, IRubyObject other) flo_divmodfinal boolean
eql
(IRubyObject other) short circuit for Float key comparisoneql_p
(ThreadContext context, IRubyObject other) num_eqlequal_p
(ThreadContext context, IRubyObject obj) Compare this Float object with the given object and determine whether they are effectively identical.boolean
This override does not do a "checked" dispatch.boolean
finite_p()
Deprecated.finite_p
(ThreadContext context) floor
(ThreadContext context) MRI: flo_floorfloor
(ThreadContext context, IRubyObject digits) MRI: flo_floorfloor
(ThreadContext context, IRubyObject[] args) Deprecated.Class
<?> Will return the Java interface that most closely can represent this object, when working through Java integration translations.This is overridden in the other concrete Java builtins to provide a fast way to determine what type they are.double
getValue()
Get the raw float value.hash
(ThreadContext context) Will return the hash code of this object.final int
hashCode()
This override does not do "checked" dispatch since Object usually has #hash defined.id()
Produce an object ID for this Float.static IRubyObject
induced_from
(ThreadContext context, IRubyObject recv, IRubyObject number) Deprecated.Deprecated.infinite_p
(ThreadContext context) boolean
boolean
isNaN()
isNegative
(ThreadContext context) num_negative_pboolean
isNegativeNumber
(ThreadContext context) isPositive
(ThreadContext context) num_positive_pboolean
isPositiveNumber
(ThreadContext context) final boolean
isZero
(ThreadContext context) magnitude
(ThreadContext context) flo_abs/1.9static void
marshalTo
(RubyFloat aFloat, MarshalStream output) Deprecated, for removal: This API element is subject to removal in a future version.static void
marshalTo
(ThreadContext context, RubyOutputStream out, RubyFloat aFloat, MarshalDumper output) nan_p()
Deprecated.nan_p
(ThreadContext context) flo_is_nan_pstatic RubyFloat
Deprecated.next_float
(ThreadContext context) nonzero_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_modop_mul
(ThreadContext context, double other) op_mul
(ThreadContext context, IRubyObject other) flo_mulop_not_equal
(ThreadContext context, double other) op_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_powDeprecated.op_uminus
(ThreadContext context) flo_uminusDeprecated.prev_float
(ThreadContext context) 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_roundroundShared
(ThreadContext context, int ndigits, RoundingMode mode) int
signum()
Deprecated.int
signum
(ThreadContext context) singletonClass
(ThreadContext context) Will either return the existing singleton class for this object, or create a new one and return that.to_f()
Deprecated.to_f
(ThreadContext context) to_r
(ThreadContext context) to_s
(ThreadContext context) flo_to_struncate
(ThreadContext context) MRI: flo_truncatetruncate
(ThreadContext context, IRubyObject n) MRI: flo_truncatestatic RubyFloat
unmarshalFrom
(UnmarshalStream input) Deprecated, for removal: This API element is subject to removal in a future version.static RubyFloat
unmarshalFrom
(ThreadContext context, RubyInputStream in, MarshalLoader 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, coerce, coerceBin, coerceBin, coerceBit, coerceBit, coerceCmp, coerceCmp, coerceFailed, coerceRelOp, coerceRelOp, coerceRescue, compareWithZero, conjugate, convertToRational, convertToRational, createNumericClass, dbl_cmp, dbl2ival, dbl2num, div, doCoerce, dup, fdiv, fix2int, fix2int, fix2long, fixable, float2long, float2ulong, floatStep, floatStepSize, floor, getBigIntegerValue, getCoerced, getDoubleValue, getIntValue, getLongValue, getRoundingMode, idiv, idiv, image, initialize_copy, int2fix, integer_p, integer_p, intervalStepSize, isNegative, isPositive, isReal, isZero, modulo, negativeInt, negFixable, negFixable, newNumeric, num_imaginary, num2chr, num2dbl, num2dbl, num2fix, num2fix, num2int, num2long, num2ulong, numFuncall, numFuncall, numRemainder, op_not, op_num_equal, op_uplus, op_uplus, polar, posFixable, posFixable, positiveInt, rbClone, rbClone, rbClone, rbClone, real, real_p, rect, remainder, round, scalar_p, singleton_method_added, step, str2fnum, str2fnum, str2fnum, str2inum, str2inum, str2inum, to_c, to_int, toJava, truncate
Methods inherited from class org.jruby.RubyObject
attachToObjectSpace, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, convertToType, dig, dig1, dig2, eqlInternal, equalInternal, finishObjectClass, inspect, op_eqq, puts, specificEval, toRubyString, toString
Methods inherited from class org.jruby.RubyBasicObject
addFinalizer, addFinalizer, anyToString, asJavaString, asString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkCallMethod, checkCallMethod, checkFrozen, checkStringType, cloneSetup, convertToArray, convertToHash, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, dataGetStruct, dataGetStructChecked, dataWrapStruct, decode, display, dupFinalizer, dupSetup, ensureInstanceVariablesSettable, eql_p, evalUnder, extend, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, finishBasicObjectClass, forEachInstanceVariable, forEachInstanceVariableName, freeze, frozen_p, getCurrentContext, getFFIHandle, getFlag, getInstanceEvalClass, getInstanceEvalClass, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getMarshalVariableList, getMetaClass, getMetaClass, getNativeHandle, getNativeTypeIndex, getObjectId, getRuntime, getSingletonClass, getSingletonClassClone, getSingletonClassCloneAndAttach, getSingletonClassCloneAndAttach, getType, getVariable, getVariableCount, getVariableList, getVariableNameList, hash, hashyInspect, hasInstanceVariable, hasInstanceVariables, hasInternalVariable, hasVariables, infectBy, initialize, initialize_copy, inspect, inspect, inspectHashCode, 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, isBuiltin, isClass, isFalse, isFrozen, isImmediate, isModule, isNil, isSpecialConst, isSpecialObject, isTaint, isTrue, isUntrusted, kind_of_p, makeMetaClass, makeMetaClass, makeMetaClassBootstrap, method, method, method, method_missing, methods, methods, nil_p, nonFixnumHashCode, nonFixnumHashCode, OBJ_INIT_COPY, objInitCopy, op_match, op_not_equal, op_not_match, private_methods, protected_methods, public_methods, rbInspect, remove_instance_variable, removeFinalizers, removeInstanceVariable, removeInternalVariable, respond_to_p, respond_to_p, respondsTo, respondsToMissing, respondsToMissing, send, send, send, send, send, setFFIHandle, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setNativeHandle, setTaint, setUntrusted, setVariable, singleton_method, singleton_method, singleton_method_added, singleton_method_removed, singleton_method_undefined, singleton_methods, specificEval, specificEval, specificEval, specificEval, syncVariables, syncVariables, taint, taint, tainted_p, testFrozen, testFrozen, to_a, to_a, to_s, trust, type, untaint, untrust, untrusted_p, validateInstanceVariable, validateInstanceVariable, validateInstanceVariable, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableRemove, variableTableStore, variableTableSync, yieldUnder, yieldUnder
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.jruby.runtime.builtin.IRubyObject
checkStringType19, dup, marshalLiveVariables
-
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:
-
POSITIVE_INFINITY_TO_S_BYTELIST
-
NEGATIVE_INFINITY_TO_S_BYTELIST
-
NAN_TO_S_BYTELIST
-
-
Constructor Details
-
RubyFloat
-
RubyFloat
-
-
Method Details
-
createFloatClass
-
getNativeClassIndex
Description copied from class:RubyObject
This 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:
getNativeClassIndex
in interfaceCoreObjectType
- Overrides:
getNativeClassIndex
in classRubyObject
- Returns:
- the ClassIndex of the native type this object was constructed from
- See Also:
-
singletonClass
Description copied from class:RubyBasicObject
Will either return the existing singleton class for this object, or create a new one and return that. For a few types a singleton class is not possible so it will throw an error.- Specified by:
singletonClass
in interfaceIRubyObject
- Overrides:
singletonClass
in classRubyBasicObject
- Parameters:
context
- the current thread context- Returns:
- the singleton of this type
-
getJavaClass
Description copied from class:RubyBasicObject
Will return the Java interface that most closely can represent this object, when working through Java integration translations.- Specified by:
getJavaClass
in interfaceIRubyObject
- Overrides:
getJavaClass
in classRubyBasicObject
- Returns:
- the true Java class of this (Ruby) object
-
getValue
public double getValue()Get the raw float value. If you want to access this as other Java primitive types then you should useasLong(ThreadContext)
,asBigInteger(ThreadContext)
, orasInt(ThreadContext)
. Those will ensure that the double will fit into the range and create the type if needed (e.g. make a BigInteger). If you KNOW the double is in the right range then you can just use this method and manually cast it.- Returns:
- Value of property value.
-
asBigInteger
Description copied from class:RubyNumeric
Return a BigInteger representation of this numerical value- Overrides:
asBigInteger
in classRubyNumeric
- Parameters:
context
- the current thread context- Returns:
- a BigInteger
-
asDouble
Description copied from class:RubyNumeric
Return a double representation of this numerical value- Overrides:
asDouble
in classRubyNumeric
- Parameters:
context
- the current thread context- Returns:
- a double
-
asInt
Description copied from class:RubyNumeric
Returns the value of this numeric and a java int.- Overrides:
asInt
in classRubyNumeric
-
asLong
Description copied from class:RubyNumeric
Return the value of this numeric as a 64-bit long.- Overrides:
asLong
in classRubyNumeric
-
convertToFloat
Description copied from class:RubyBasicObject
Tries to convert this object to a Ruby Float using the "to_f" method.- Specified by:
convertToFloat
in interfaceIRubyObject
- Overrides:
convertToFloat
in classRubyBasicObject
- Returns:
- float representation of this
-
convertToInteger
Description copied from class:RubyBasicObject
Tries to convert this object to a Ruby Integer using the "to_int" method.- Specified by:
convertToInteger
in interfaceIRubyObject
- Overrides:
convertToInteger
in classRubyBasicObject
- Returns:
- an integer representation of this
-
signum
Deprecated. -
signum
-
isNegative
Description copied from class:RubyNumeric
num_negative_p- Overrides:
isNegative
in classRubyNumeric
-
isPositive
Description copied from class:RubyNumeric
num_positive_p- Overrides:
isPositive
in classRubyNumeric
-
isNegativeNumber
- Overrides:
isNegativeNumber
in classRubyNumeric
-
isPositiveNumber
- Overrides:
isPositiveNumber
in 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_s
in classRubyBasicObject
-
coerce
Description copied from class:RubyNumeric
num_coerce- Overrides:
coerce
in classRubyNumeric
-
op_uminus
flo_uminus- Overrides:
op_uminus
in classRubyNumeric
-
op_uminus
Deprecated. -
op_plus
flo_plus- Overrides:
op_plus
in classRubyNumeric
-
op_plus
-
op_minus
flo_minus- Overrides:
op_minus
in classRubyNumeric
-
op_minus
-
op_mul
flo_mul -
op_mul
-
op_div
MRI: flo_div -
op_div
-
quo
flo_quo- Overrides:
quo
in classRubyNumeric
-
op_mod
flo_mod -
op_mod
-
divmod
flo_divmod- Overrides:
divmod
in classRubyNumeric
-
op_pow
flo_pow -
op_pow
-
op_equal
flo_eq- Specified by:
op_equal
in interfaceIRubyObject
- Overrides:
op_equal
in classRubyBasicObject
-
op_equal
-
op_not_equal
-
fastEqual
-
compareTo
Description copied from class:RubyBasicObject
Compares this Ruby object with another.- Specified by:
compareTo
in interfaceComparable<IRubyObject>
- Overrides:
compareTo
in 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_cmp
in classRubyNumeric
-
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
Description copied from class:RubyNumeric
num_eql- Overrides:
eql_p
in classRubyNumeric
-
eql
short circuit for Float key comparison- Specified by:
eql
in interfaceIRubyObject
- Overrides:
eql
in classRubyBasicObject
- Returns:
- Will by default just call the Ruby method "eql?"
-
equals
Description copied from class:RubyObject
This override does not do a "checked" dispatch.- Overrides:
equals
in classRubyObject
- Parameters:
other
- object to compare- Returns:
- true if equals
- See Also:
-
hash
Description copied from class:RubyBasicObject
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 classRubyBasicObject
- Parameters:
context
- the current thread context- Returns:
- the hash value
-
hashCode
public final int hashCode()Description copied from class:RubyObject
This override does not do "checked" dispatch since Object usually has #hash defined.- Overrides:
hashCode
in classRubyObject
- Returns:
- the hash code
- See Also:
-
to_f
Deprecated. -
to_f
-
abs
flo_abs- Overrides:
abs
in classRubyNumeric
-
magnitude
flo_abs/1.9- Overrides:
magnitude
in classRubyNumeric
-
zero_p
MRI: flo_zero_p- Overrides:
zero_p
in classRubyNumeric
-
isZero
- Overrides:
isZero
in classRubyNumeric
-
nonzero_p
Description copied from class:RubyNumeric
num_nonzero_p- Overrides:
nonzero_p
in classRubyNumeric
-
truncate
MRI: flo_truncate- Overrides:
truncate
in classRubyNumeric
-
truncate
MRI: flo_truncate -
numerator
flo_numerator- Overrides:
numerator
in classRubyNumeric
-
denominator
flo_denominator- Overrides:
denominator
in classRubyNumeric
-
to_r
-
rationalize
float_rationalize -
floor
MRI: flo_floor- Overrides:
floor
in classRubyNumeric
-
floor
MRI: flo_floor -
ceil
MRI: flo_ceil- Overrides:
ceil
in classRubyNumeric
-
ceil
MRI: flo_ceil -
round
MRI: flo_round- Overrides:
round
in classRubyNumeric
-
round
MRI: flo_round -
round
MRI: flo_round -
nan_p
flo_is_nan_p -
nan_p
Deprecated. -
isNaN
public boolean isNaN() -
infinite_p
Deprecated. -
infinite_p
- Overrides:
infinite_p
in classRubyNumeric
-
isInfinite
public boolean isInfinite() -
finite_p
Deprecated. -
finite_p
- Overrides:
finite_p
in classRubyNumeric
-
marshalTo
@Deprecated(since="10.0", forRemoval=true) public static void marshalTo(RubyFloat aFloat, MarshalStream output) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.- Throws:
IOException
-
marshalTo
public static void marshalTo(ThreadContext context, RubyOutputStream out, RubyFloat aFloat, MarshalDumper output) -
unmarshalFrom
@Deprecated(since="10.0", forRemoval=true) public static RubyFloat unmarshalFrom(UnmarshalStream input) throws IOException Deprecated, for removal: This API element is subject to removal in a future version.- Throws:
IOException
-
unmarshalFrom
public static RubyFloat unmarshalFrom(ThreadContext context, RubyInputStream in, MarshalLoader input) -
next_float
Deprecated. -
next_float
-
prev_float
Deprecated. -
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:
id
in interfaceIRubyObject
- Overrides:
id
in 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_p
in 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
-
appendIntoString
- Specified by:
appendIntoString
in interfaceAppendable
-
zero_p
Deprecated. -
floor
Deprecated. -
round
Deprecated.
-