Top Description Inners Fields Constructors Methods
org.python.core

public Class PyFloat

extends AbstractPyObject
Class Inheritance
Known Direct Subclasses
org.python.core.PyFloat.Derived
Static Imports
org.python.core.PyFloatMethods.toDouble

The Python float object.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class
PyFloat.Derived

Instances in Python of sub-classes of 'float', are represented in Java by instances of this class.

public static enum
pack-priv static class
PyFloat.Formatter

A Formatter, constructed from a Spec, with specific validations for int.__format__.

Field Summary

Modifier and TypeField and Description
private static final String
pack-priv static final String
DIV_ZERO

Used as error message text for division by zero.

public static volatile PyFloat.Format
private static final long
private static final int
private static final int
public static volatile PyFloat.Format
private static final long
private static double
INT_LONG_BOUNDARY

Smallest value that cannot be represented as an int

pack-priv static final String
MOD_ZERO

Used as error message text for modulo zero.

pack-priv static final Double
NAN

A constant Python float("nan").

pack-priv static final Double
ONE

A constant Python float(1).

private static final long
private static final long
private static final int
pack-priv static final InternalFormat.Spec
SPEC_REPR

Format specification used by repr().

pack-priv static final InternalFormat.Spec
SPEC_STR

Format specification used by str().

public static final PyType
TYPE

The type float.

pack-priv final double
value

Value of this float object.

pack-priv static final Double
ZERO

A constant Python float(0).

Constructor Summary

AccessConstructor and Description
pack-priv
PyFloat(PyType
actual type
type
,
double
of the float
value
)

Constructor for Python sub-class specifying type.

public
PyFloat(double v)

public
PyFloat(float v)

Method Summary

Modifier and TypeMethod and Description
pack-priv Object
pack-priv static final Object
pack-priv static final Object
__format__(Object self, Object formatSpec)

pack-priv final PyTuple
pack-priv static final PyTuple
pack-priv final int
pack-priv static final int
pack-priv static final int
__hash__(double value)

pack-priv final Object
pack-priv static final Object
private static final Object
__int__(double v)

pack-priv static Object
__pow__(Object left, Object right, Object modulus)

pack-priv static final String
pack-priv static Object
__rpow__(Object right, Object left)

pack-priv static final String
pack-priv final Object
pack-priv static final Object
pack-priv final PyTuple
pack-priv static final PyTuple
private static PyTuple
as_integer_ratio(double value)

pack-priv static double

Returns:

converted value
asDouble
(Object
to convert
o
)

Convert the argument to a Java double value.

pack-priv static BigInteger

Returns:

BigInteger equivalent.
bigIntegerFromDouble
(double
to convert
value
)

Convert a Java double to Java BigInteger by truncation.

private static OverflowError
private static ValueError
pack-priv final Object
pack-priv static final Object
pack-priv static double

Returns:

converted to double
convertToDouble
(Object
to convert
v
)

Convert a Python float, int or bool to a Java double (or throw NoConversion).

pack-priv static final PyTuple

Returns:

tuple of (x//y, x%y)
divmod
(double
operand
x
,
double
operand
y
)

Inner method for __divmod__ and __rdivmod__.

public static double

Returns:

double value
doubleValue
(Object
claimed float
v
)

Present the value as a Java double when the argument is expected to be a Python float or a sub-class of it.

public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public static String
public static void
float___setformat__(PyType type, String typestr, String format)

public static Object
public Object
pack-priv static final double

Returns:

x//y
floordiv
(double
operand
x
,
double
operand
y
)

Inner method for __floordiv__ and __rfloordiv__.

private static String

Returns:

formatted value
formatDouble
(double
to format
value
,
InternalFormat.Spec
parsed format specification string
spec
)

Format this float according to the specification passed in. Supports __format__, __str__ and __repr__.

public Object
public Object
public double
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
pack-priv final boolean
pack-priv static final boolean
pack-priv static final boolean
is_integer(double self)

pack-priv static final double

Returns:

x%y
mod
(double
operand
x
,
double
operand
y
)

Inner method for __mod__ and __rmod__.

private static double

Returns:

x % y
modulo
(double
dividend
x
,
double
divisor
y
)

Python % operator: y = n*x + z.

pack-priv static double

Returns:

v
nonzero
(double
value to check is not zero
v
,
String
for exception if v==0.0
msg
)

Convenience function to throw a ZeroDivisionError if the argument is zero.

pack-priv static double

Returns:

v
nonzero
(double
value to check is not zero
v
)

Convenience function to throw a ZeroDivisionError if the argument is zero.

pack-priv static double

Returns:

v ** w
pow
(double
base value
v
,
double
exponent
w
)

Exponentiation with Python semantics.

private String
private static boolean

Returns:

if signs equal (works for signed zeros, etc.)
sameSign
(double
a double
u
,
double
another double
v
)

Test that two doubles have the same sign.

public String
toString()

Overrides org.python.core.AbstractPyObject.toString.

Returns a string representation of the object.
Inherited from org.python.core.AbstractPyObject:
getType

Field Detail

CANNOT_CONVERTback to summary
private static final String CANNOT_CONVERT
DIV_ZEROback to summary
pack-priv static final String DIV_ZERO

Used as error message text for division by zero.

double_formatback to summary
public static volatile PyFloat.Format double_format
EXPONENTback to summary
private static final long EXPONENT
EXPONENT_BIASback to summary
private static final int EXPONENT_BIAS
EXPONENT_BITSback to summary
private static final int EXPONENT_BITS
float_formatback to summary
public static volatile PyFloat.Format float_format
IMPLIED_ONEback to summary
private static final long IMPLIED_ONE
INT_LONG_BOUNDARYback to summary
private static double INT_LONG_BOUNDARY

Smallest value that cannot be represented as an int

MOD_ZEROback to summary
pack-priv static final String MOD_ZERO

Used as error message text for modulo zero.

NANback to summary
pack-priv static final Double NAN

A constant Python float("nan").

ONEback to summary
pack-priv static final Double ONE

A constant Python float(1).

SIGNback to summary
private static final long SIGN
SIGNIFICANDback to summary
private static final long SIGNIFICAND
SIGNIFICAND_BITSback to summary
private static final int SIGNIFICAND_BITS
SPEC_REPRback to summary
pack-priv static final InternalFormat.Spec SPEC_REPR

Format specification used by repr().

SPEC_STRback to summary
pack-priv static final InternalFormat.Spec SPEC_STR

Format specification used by str().

TYPEback to summary
public static final PyType TYPE

The type float.

valueback to summary
pack-priv final double value

Value of this float object.

ZEROback to summary
pack-priv static final Double ZERO

A constant Python float(0).

Constructor Detail

PyFloatback to summary
pack-priv PyFloat(PyType type, double value)

Constructor for Python sub-class specifying type.

Parameters
type:PyType

actual type

value:double

of the float

PyFloatback to summary
public PyFloat(double v)
PyFloatback to summary
public PyFloat(float v)

Method Detail

__float__back to summary
pack-priv Object __float__()
__float__back to summary
pack-priv static final Object __float__(Double self)
__format__back to summary
pack-priv static final Object __format__(Object self, Object formatSpec)
__getnewargs__back to summary
pack-priv final PyTuple __getnewargs__()
__getnewargs__back to summary
pack-priv static final PyTuple __getnewargs__(Double self)
__hash__back to summary
pack-priv final int __hash__()
__hash__back to summary
pack-priv static final int __hash__(Double self)
__hash__back to summary
pack-priv static final int __hash__(double value)
__int__back to summary
pack-priv final Object __int__()
__int__back to summary
pack-priv static final Object __int__(Double self)
__int__back to summary
private static final Object __int__(double v)
__pow__back to summary
pack-priv static Object __pow__(Object left, Object right, Object modulus)
__repr__back to summary
pack-priv static final String __repr__(Object self)
__rpow__back to summary
pack-priv static Object __rpow__(Object right, Object left)
__str__back to summary
pack-priv static final String __str__(Object self)
__trunc__back to summary
pack-priv final Object __trunc__()
__trunc__back to summary
pack-priv static final Object __trunc__(Double self)
as_integer_ratioback to summary
pack-priv final PyTuple as_integer_ratio()
as_integer_ratioback to summary
pack-priv static final PyTuple as_integer_ratio(Double self)
as_integer_ratioback to summary
private static PyTuple as_integer_ratio(double value)
asDoubleback to summary
pack-priv static double asDouble(Object o) throws TypeError, Throwable

Convert the argument to a Java double value. If o is not a Python float try the __float__() method, then __index__().

Parameters
o:Object

to convert

Returns:double

converted value

Exceptions
TypeError:
if o cannot be interpreted as a float
Throwable:
from __float__) or __index__

bigIntegerFromDoubleback to summary
pack-priv static BigInteger bigIntegerFromDouble(double value) throws OverflowError, ValueError

Convert a Java double to Java BigInteger by truncation.

Parameters
value:double

to convert

Returns:BigInteger

BigInteger equivalent.

Exceptions
OverflowError:
when this is a floating infinity
ValueError:
when this is a floating NaN

cannotConvertInfback to summary
private static OverflowError cannotConvertInf(String to)
cannotConvertNaNback to summary
private static ValueError cannotConvertNaN(String to)
conjugateback to summary
pack-priv final Object conjugate()
conjugateback to summary
pack-priv static final Object conjugate(Double self)
convertToDoubleback to summary
pack-priv static double convertToDouble(Object v) throws NoConversion, OverflowError

Convert a Python float, int or bool to a Java double (or throw NoConversion). Conversion from an int may overflow.

If the method throws the special non-Python exception NoConversion, the caller must deal with it by throwing an appropriate Python exception or taking an alternative course of action. OverlowError could be allowed to propagate since it is a Python exception.

Parameters
v:Object

to convert

Returns:double

converted to double

Exceptions
NoConversion:
if v is not a float, int or bool
OverflowError:
if v is an int out of range

divmodback to summary
pack-priv static final PyTuple divmod(double x, double y)

Inner method for __divmod__ and __rdivmod__.

Parameters
x:double

operand

y:double

operand

Returns:PyTuple

tuple of (x//y, x%y)

doubleValueback to summary
public static double doubleValue(Object v) throws TypeError

Present the value as a Java double when the argument is expected to be a Python float or a sub-class of it.

Parameters
v:Object

claimed float

Returns:double

double value

Exceptions
TypeError:
if v is not a Python float

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override

float___getformat__back to summary
public static String float___getformat__(PyType type, String typestr)
float___setformat__back to summary
public static void float___setformat__(PyType type, String typestr, String format)
float_fromhexback to summary
public static Object float_fromhex(PyType type, Object o)
float_hexback to summary
public Object float_hex()
floordivback to summary
pack-priv static final double floordiv(double x, double y)

Inner method for __floordiv__ and __rfloordiv__.

Parameters
x:double

operand

y:double

operand

Returns:double

x//y

formatDoubleback to summary
private static String formatDouble(double value, InternalFormat.Spec spec)

Format this float according to the specification passed in. Supports __format__, __str__ and __repr__.

Parameters
value:double

to format

spec:InternalFormat.Spec

parsed format specification string

Returns:String

formatted value

getImagback to summary
public Object getImag()
getRealback to summary
public Object getReal()
getValueback to summary
public double getValue()
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override

is_integerback to summary
pack-priv final boolean is_integer()
is_integerback to summary
pack-priv static final boolean is_integer(Double self)
is_integerback to summary
pack-priv static final boolean is_integer(double self)
modback to summary
pack-priv static final double mod(double x, double y)

Inner method for __mod__ and __rmod__.

Parameters
x:double

operand

y:double

operand

Returns:double

x%y

moduloback to summary
private static double modulo(double x, double y)

Python % operator: y = n*x + z. The modulo operator always yields a result with the same sign as its second operand (or zero). (Compare java.Math.IEEEremainder)

Parameters
x:double

dividend

y:double

divisor

Returns:double

x % y

nonzeroback to summary
pack-priv static double nonzero(double v, String msg)

Convenience function to throw a ZeroDivisionError if the argument is zero. (Java float arithmetic does not throw whatever the arguments.)

Parameters
v:double

value to check is not zero

msg:String

for exception if v==0.0

Returns:double

v

nonzeroback to summary
pack-priv static double nonzero(double v)

Convenience function to throw a ZeroDivisionError if the argument is zero. (Java float arithmetic does not throw whatever the arguments.)

Parameters
v:double

value to check is not zero

Returns:double

v

powback to summary
pack-priv static double pow(double v, double w)

Exponentiation with Python semantics.

Parameters
v:double

base value

w:double

exponent

Returns:double

v ** w

pyHexStringback to summary
private String pyHexString(Double f)
sameSignback to summary
private static boolean sameSign(double u, double v)

Test that two doubles have the same sign.

Parameters
u:double

a double

v:double

another double

Returns:boolean

if signs equal (works for signed zeros, etc.)

toStringback to summary
public String toString()

Overrides org.python.core.AbstractPyObject.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override

org.python.core back to summary

pack-priv Class PyFloat.Derived

extends PyFloat
implements DictPyObject
Class Inheritance
All Implemented Interfaces
org.python.core.DictPyObject, org.python.core.CraftedPyObject

Instances in Python of sub-classes of 'float', are represented in Java by instances of this class.

Field Summary

Inherited from org.python.core.PyFloat:
DIV_ZEROdouble_formatfloat_formatMOD_ZERONANONESPEC_REPRSPEC_STRTYPEvalueZERO

Constructor Summary

AccessConstructor and Description
protected
Derived(PyType subType, double value)

Method Summary

Modifier and TypeMethod and Description
public Map<Object, Object>
getDict()

Implements org.python.core.DictPyObject.getDict.

The dictionary of the instance, (not necessarily a Python dict or writable.
Inherited from org.python.core.PyFloat:
__float____float____format____getnewargs____getnewargs____hash____hash____hash____int____int____pow____repr____rpow____str____trunc____trunc__as_integer_ratioas_integer_ratioasDoublebigIntegerFromDoubleconjugateconjugateconvertToDoubledivmoddoubleValueequalsfloat___getformat__float___setformat__float_fromhexfloat_hexfloordivgetImaggetRealgetValuehashCodeis_integeris_integeris_integermodnonzerononzeropowtoString

Constructor Detail

Derivedback to summary
protected Derived(PyType subType, double value)

Method Detail

getDictback to summary
public Map<Object, Object> getDict()

Implements org.python.core.DictPyObject.getDict.

Doc from org.python.core.DictPyObject.getDict.

The dictionary of the instance, (not necessarily a Python dict or writable. If the returned Map is not writable, it should throw a Java UnsupportedOperationException on attempts to modify it.

Returns:Map<Object, Object>

a mapping to treat like a dictionary (not null).

Annotations
@Override

org.python.core back to summary

public final Enum PyFloat.Format

extends Enum<PyFloat.Format>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final PyFloat.Format
private final String
public static final PyFloat.Format
public static final PyFloat.Format

Constructor Summary

AccessConstructor and Description
private
Format(String format)

Method Summary

Modifier and TypeMethod and Description
public String
public static PyFloat.Format
public static PyFloat.Format[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

BEback to summary
public static final PyFloat.Format BE
formatback to summary
private final String format
LEback to summary
public static final PyFloat.Format LE
UNKNOWNback to summary
public static final PyFloat.Format UNKNOWN

Constructor Detail

Formatback to summary
private Format(String format)

Method Detail

formatback to summary
public String format()
valueOfback to summary
public static PyFloat.Format valueOf(String name)
valuesback to summary
public static PyFloat.Format[] values()
org.python.core back to summary

pack-priv Class PyFloat.Formatter

extends FloatFormatter
Class Inheritance

A Formatter, constructed from a Spec, with specific validations for int.__format__.

Field Summary

Modifier and TypeField and Description
pack-priv final boolean
printf

If true, give printf-style meanings to Spec#type.

Constructor Summary

AccessConstructor and Description
pack-priv
Formatter(InternalFormat.Spec
a parsed format specification.
spec
,
boolean
f true, interpret spec printf-style, otherwise as Formatter(Spec)
printf
)

Prepare a Formatter in support of str.__mod__, that is, traditional printf-style formatting.

pack-priv
Formatter(InternalFormat.Spec
a parsed PEP-3101 format specification.
spec
)

Prepare a Formatter in support of float.

Method Summary

Modifier and TypeMethod and Description
public FloatFormatter
format(Object
to format
o
)

Implements abstract org.python.core.stringlib.InternalFormat.AbstractFormatter.format.

Format an object into the buffer according to the specification with which this instance has been initialised.
private static InternalFormat.Spec

Returns:

validated spec with defaults filled
validated
(InternalFormat.Spec
to validate
spec
,
boolean printf)

Validations and defaults specific to float.

Inherited from org.python.core.stringlib.FloatFormatter:
appendappendappendformatformatresetsectionLengthssetMinFracDigitssizeuppercase

Field Detail

printfback to summary
pack-priv final boolean printf

If true, give printf-style meanings to Spec#type.

Constructor Detail

Formatterback to summary
pack-priv Formatter(InternalFormat.Spec spec, boolean printf) throws FormatError

Prepare a Formatter in support of str.__mod__, that is, traditional printf-style formatting.

Parameters
spec:InternalFormat.Spec

a parsed format specification.

printf:boolean

f true, interpret spec printf-style, otherwise as Formatter(Spec)

Exceptions
FormatError:
if an unsupported format character is encountered
FormatOverflow:
if a value is out of range (including the precision)
Formatterback to summary
pack-priv Formatter(InternalFormat.Spec spec) throws FormatError

Prepare a Formatter in support of float.__format__.

Parameters
spec:InternalFormat.Spec

a parsed PEP-3101 format specification.

Exceptions
FormatError:
if an unsupported format character is encountered
FormatOverflow:
if a value is out of range (including the precision)

Method Detail

formatback to summary
public FloatFormatter format(Object o) throws NoConversion, FormatError

Implements abstract org.python.core.stringlib.InternalFormat.AbstractFormatter.format.

Doc from org.python.core.stringlib.InternalFormat.AbstractFormatter.format.

Format an object into the buffer according to the specification with which this instance has been initialised. The specific behaviour, and the acceptable types, are for a sub-class to define. Also, it is usually desirable for the return type in an implementing class to be a more specific.

Parameters
o:Object

to format

Returns:FloatFormatter

this formatter

Annotations
@Override
Exceptions
NoConversion:
if o is not convertible
FormatError:
from the process of formatting

validatedback to summary
private static InternalFormat.Spec validated(InternalFormat.Spec spec, boolean printf) throws FormatError

Validations and defaults specific to float.

Parameters
spec:InternalFormat.Spec

to validate

Returns:InternalFormat.Spec

validated spec with defaults filled

Exceptions
FormatError:
on failure to validate