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.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 TypeFieldDescriptionstatic final intstatic final doublestatic final intstatic final doublestatic final intstatic final intstatic final intstatic final intstatic final intstatic final doublestatic final ByteListstatic final ByteListstatic final ByteListstatic final intstatic final intFields 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, 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_absvoidappendIntoString(RubyString target) asBigInteger(ThreadContext context) Return a BigInteger representation of this numerical valuedoubleasDouble(ThreadContext context) Return a double representation of this numerical valueintasInt(ThreadContext context) Returns the value of this numeric and a java int.longasLong(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 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(ThreadContext context, RubyClass Numeric) denominator(ThreadContext context) flo_denominatordivmod(ThreadContext context, IRubyObject other) flo_divmodfinal booleaneql(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.booleanThis override does not do a "checked" dispatch.booleanfinite_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.doublegetValue()Get the raw float value.hash(ThreadContext context) Will return the hash code of this object.final 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.Deprecated.infinite_p(ThreadContext context) booleanbooleanisNaN()isNegative(ThreadContext context) num_negative_pbooleanisNegativeNumber(ThreadContext context) isPositive(ThreadContext context) num_positive_pbooleanisPositiveNumber(ThreadContext context) final booleanisZero(ThreadContext context) magnitude(ThreadContext context) flo_abs/1.9static voidmarshalTo(RubyFloat aFloat, MarshalStream output) Deprecated, for removal: This API element is subject to removal in a future version.static voidmarshalTo(ThreadContext context, RubyOutputStream out, RubyFloat aFloat, MarshalDumper output) nan_p()Deprecated.nan_p(ThreadContext context) flo_is_nan_pstatic RubyFloatDeprecated.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) intsignum()Deprecated.intsignum(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 RubyFloatunmarshalFrom(UnmarshalStream input) Deprecated, for removal: This API element is subject to removal in a future version.static RubyFloatunmarshalFrom(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, truncateMethods 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, toStringMethods 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, yieldUnderMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods 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: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- Returns:
- the ClassIndex of the native type this object was constructed from
- See Also:
-
singletonClass
Description copied from class:RubyBasicObjectWill 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:
singletonClassin interfaceIRubyObject- Overrides:
singletonClassin classRubyBasicObject- Parameters:
context- the current thread context- Returns:
- the singleton of this type
-
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()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:RubyNumericReturn a BigInteger representation of this numerical value- Overrides:
asBigIntegerin classRubyNumeric- Parameters:
context- the current thread context- Returns:
- a BigInteger
-
asDouble
Description copied from class:RubyNumericReturn a double representation of this numerical value- Overrides:
asDoublein classRubyNumeric- Parameters:
context- the current thread context- Returns:
- a double
-
asInt
Description copied from class:RubyNumericReturns the value of this numeric and a java int.- Overrides:
asIntin classRubyNumeric
-
asLong
Description copied from class:RubyNumericReturn the value of this numeric as a 64-bit long.- Overrides:
asLongin 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
-
signum
Deprecated. -
signum
-
isNegative
Description copied from class:RubyNumericnum_negative_p- Overrides:
isNegativein classRubyNumeric
-
isPositive
Description copied from class:RubyNumericnum_positive_p- Overrides:
isPositivein classRubyNumeric
-
isNegativeNumber
- Overrides:
isNegativeNumberin classRubyNumeric
-
isPositiveNumber
- Overrides:
isPositiveNumberin 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
Description copied from class:RubyNumericnum_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
-
divmod
flo_divmod- Overrides:
divmodin classRubyNumeric
-
op_pow
flo_pow -
op_pow
-
op_equal
flo_eq- Specified by:
op_equalin interfaceIRubyObject- Overrides:
op_equalin classRubyBasicObject
-
op_equal
-
op_not_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 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:RubyNumericnum_eql- Overrides:
eql_pin classRubyNumeric
-
eql
short circuit for Float key comparison- Specified by:
eqlin interfaceIRubyObject- Overrides:
eqlin classRubyBasicObject- Returns:
- Will by default just call the Ruby method "eql?"
-
equals
Description copied from class:RubyObjectThis override does not do a "checked" dispatch.- Overrides:
equalsin classRubyObject- Parameters:
other- object to compare- Returns:
- true if equals
- See Also:
-
hash
Description copied from class:RubyBasicObjectWill 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:
hashin classRubyBasicObject- Parameters:
context- the current thread context- Returns:
- the hash value
-
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- Returns:
- the hash code
- See Also:
-
to_f
Deprecated. -
to_f
-
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
- 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 -
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 -
nan_p
flo_is_nan_p -
nan_p
Deprecated. -
isNaN
public boolean isNaN() -
infinite_p
Deprecated. -
infinite_p
- Overrides:
infinite_pin classRubyNumeric
-
isInfinite
public boolean isInfinite() -
finite_p
Deprecated. -
finite_p
- Overrides:
finite_pin 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:
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
-
appendIntoString
- Specified by:
appendIntoStringin interfaceAppendable
-
zero_p
Deprecated. -
floor
Deprecated. -
round
Deprecated.
-