EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PyFloat Class Reference

Python floating point number. More...

#include "PyRep.h"

Inheritance diagram for PyFloat:
Collaboration diagram for PyFloat:

Public Member Functions

 PyFloat (const double &i)
 
 PyFloat (const PyFloat &oth)
 
 PyFloat (PyFloat &&oth)=delete
 
PyFloatoperator= (const PyFloat &oth)=delete
 
PyFloatoperator= (PyFloat &&oth)=delete
 
PyRepClone () const
 Clones object. More...
 
bool visit (PyVisitor &v) const
 Visits object. More...
 
double value () const
 
int32 hash () const
 virtual function to generate a hash value of a object. More...
 
- Public Member Functions inherited from PyRep
PyType GetType () const
 
bool IsInt () const
 
bool IsLong () const
 
bool IsFloat () const
 
bool IsBool () const
 
bool IsBuffer () const
 
bool IsString () const
 
bool IsWString () const
 
bool IsToken () const
 
bool IsTuple () const
 
bool IsList () const
 
bool IsDict () const
 
bool IsNone () const
 
bool IsSubStruct () const
 
bool IsSubStream () const
 
bool IsChecksumedStream () const
 
bool IsObject () const
 
bool IsObjectEx () const
 
bool IsPackedRow () const
 
const char * TypeString () const
 
PyIntAsInt ()
 
const PyIntAsInt () const
 
PyLongAsLong ()
 
const PyLongAsLong () const
 
PyFloatAsFloat ()
 
const PyFloatAsFloat () const
 
PyBoolAsBool ()
 
const PyBoolAsBool () const
 
PyBufferAsBuffer ()
 
const PyBufferAsBuffer () const
 
PyStringAsString ()
 
const PyStringAsString () const
 
PyWStringAsWString ()
 
const PyWStringAsWString () const
 
PyTokenAsToken ()
 
const PyTokenAsToken () const
 
PyTupleAsTuple ()
 
const PyTupleAsTuple () const
 
PyListAsList ()
 
const PyListAsList () const
 
PyDictAsDict ()
 
const PyDictAsDict () const
 
PyNoneAsNone ()
 
const PyNoneAsNone () const
 
PySubStructAsSubStruct ()
 
const PySubStructAsSubStruct () const
 
PySubStreamAsSubStream ()
 
const PySubStreamAsSubStream () const
 
PyChecksumedStreamAsChecksumedStream ()
 
const PyChecksumedStreamAsChecksumedStream () const
 
PyObjectAsObject ()
 
const PyObjectAsObject () const
 
PyObjectExAsObjectEx ()
 
const PyObjectExAsObjectEx () const
 
PyPackedRowAsPackedRow ()
 
const PyPackedRowAsPackedRow () const
 
void Dump (FILE *into, const char *pfx) const
 Dumps object to file. More...
 
void Dump (LogType type, const char *pfx) const
 Dumps object to console. More...
 
- Public Member Functions inherited from RefObject
 RefObject (size_t initRefCount)
 Initializes reference count. More...
 
virtual ~RefObject ()
 Destructor; must be virtual. More...
 
size_t GetCount ()
 

Protected Member Functions

virtual ~PyFloat ()
 
- Protected Member Functions inherited from PyRep
 PyRep (PyType t)
 
 PyRep (const PyRep &oth)
 
 PyRep (PyRep &&oth)=delete
 
PyRepoperator= (const PyRep &oth)=default
 
PyRepoperator= (PyRep &&oth)=default
 
virtual ~PyRep ()
 
- Protected Member Functions inherited from RefObject
void IncRef () const
 Increments reference count of object by one. More...
 
void DecRef () const
 Decrements reference count of object by one. More...
 

Protected Attributes

const double mValue
 
- Protected Attributes inherited from PyRep
const PyType mType
 
- Protected Attributes inherited from RefObject
size_t mRefCount
 Reference count of instance. More...
 
bool mDeleted
 

Additional Inherited Members

- Public Types inherited from PyRep
enum  PyType {
  PyTypeMin = 0, PyTypeInt = 1, PyTypeLong = 2, PyTypeFloat = 3,
  PyTypeBool = 4, PyTypeBuffer = 5, PyTypeString = 6, PyTypeWString = 7,
  PyTypeToken = 8, PyTypeTuple = 9, PyTypeList = 10, PyTypeDict = 11,
  PyTypeNone = 12, PyTypeSubStruct = 13, PyTypeSubStream = 14, PyTypeChecksumedStream = 15,
  PyTypeObject = 16, PyTypeObjectEx = 17, PyTypePackedRow = 18, PyTypeError = 19
}
 Python wire object types. More...
 
- Static Public Member Functions inherited from PyRep
static std::string StringContent (PyRep *pRep)
 
static int64 IntegerValue (PyRep *pRep)
 
static uint32 IntegerValueU32 (PyRep *pRep)
 

Detailed Description

Python floating point number.

Class representing floating point number.

Definition at line 292 of file PyRep.h.

Constructor & Destructor Documentation

PyFloat::PyFloat ( const double &  i)

Definition at line 238 of file PyRep.cpp.

Referenced by Clone().

238 : PyRep( PyRep::PyTypeFloat ), mValue( i ) { }
const double mValue
Definition: PyRep.h:315
PyRep(PyType t)
Definition: PyRep.cpp:73

Here is the caller graph for this function:

PyFloat::PyFloat ( const PyFloat oth)

Definition at line 239 of file PyRep.cpp.

239 : PyRep( PyRep::PyTypeFloat ), mValue( oth.value() ) { }
double value() const
Definition: PyRep.h:309
const double mValue
Definition: PyRep.h:315
PyRep(PyType t)
Definition: PyRep.cpp:73
PyFloat::PyFloat ( PyFloat &&  oth)
delete
virtual PyFloat::~PyFloat ( )
inlineprotectedvirtual

Definition at line 314 of file PyRep.h.

314 { /* do we need to do anything here? */ }

Member Function Documentation

PyRep * PyFloat::Clone ( ) const
virtual

Clones object.

Returns
Indentical copy of object.

Implements PyRep.

Definition at line 241 of file PyRep.cpp.

References PyFloat().

242 {
243  return new PyFloat( *this );
244 }
PyFloat(const double &i)
Definition: PyRep.cpp:238

Here is the call graph for this function:

int32 PyFloat::hash ( ) const
virtual

virtual function to generate a hash value of a object.

virtual function to generate a hash value of a object to facilitate the various maps and checks.

Returns
returns a uint32 containing a hash function that represents the object.

Reimplemented from PyRep.

Definition at line 256 of file PyRep.cpp.

References PyRep::hash(), INT32_MAX, mValue, Py_IS_INFINITY, and PyDecRef.

257 {
258 #define Py_IS_INFINITY( X ) \
259  ( !finite( X ) && !isnan( X ) )
260 
261  double v = mValue;
262  double intpart=0.0, fractpart=0.0;
263  int expo=0;
264  long hipart=0, x=0; /* x is the final hash value */
265  /* This is designed so that Python numbers of different types
266  * that compare equal hash to the same value; otherwise comparisons
267  * of mapping keys will turn out weird.
268  */
269 
270  fractpart = modf(v, &intpart);
271  if (fractpart == 0.0) {
272  /* This must return the same hash as an equal int or long. */
273  if ((intpart > INT32_MAX) or (-intpart > INT32_MAX)) {
274  /* Convert to long and use its hash. */
275  if (Py_IS_INFINITY(intpart))
276  /* can't convert to long int -- arbitrary */
277  v = v < 0 ? -271828.0 : 314159.0;
278  //plong = PyLong_FromDouble(v);
279 
280  PyRep *plong = new PyLong( (int64)v ); // this is a hack
281  if (plong == nullptr)
282  return -1;
283  x = plong->hash();
284  PyDecRef( plong );
285  return x;
286  }
287  /* Fits in a C long == a Python int, so is its own hash. */
288  x = (long)intpart;
289  if (x == -1)
290  x = -2;
291  return x;
292  }
293  /* The fractional part is non-zero, so we don't have to worry about
294  * making this match the hash of some other type.
295  * Use frexp to get at the bits in the double.
296  * Since the VAX D double format has 56 mantissa bits, which is the
297  * most of any double format in use, each of these parts may have as
298  * many as (but no more than) 56 significant bits.
299  * So, assuming sizeof(long) >= 4, each part can be broken into two
300  * longs; frexp and multiplication are used to do that.
301  * Also, since the Cray double format has 15 exponent bits, which is
302  * the most of any double format in use, shifting the exponent field
303  * left by 15 won't overflow a long (again assuming sizeof(long) >= 4).
304  */
305  v = frexp(v, &expo);
306  v *= 2147483648.0; /* 2**31 */
307  hipart = (long)v; /* take the top 32 bits */
308  v = (v - (double)hipart) * 2147483648.0; /* get the next 32 bits */
309  x = hipart + (long)v + (expo << 15);
310  if (x == -1)
311  x = -2;
312  return x;
313 
314 #undef Py_IS_INFINITY
315 }
Base Python wire object.
Definition: PyRep.h:66
const double mValue
Definition: PyRep.h:315
virtual int32 hash() const
virtual function to generate a hash value of a object.
Definition: PyRep.cpp:96
#define PyDecRef(op)
Definition: PyRep.h:57
#define Py_IS_INFINITY(X)
signed __int64 int64
Definition: eve-compat.h:51
#define INT32_MAX
Definition: PyRep.cpp:253
Python long integer.
Definition: PyRep.h:261

Here is the call graph for this function:

PyFloat& PyFloat::operator= ( const PyFloat oth)
delete
PyFloat& PyFloat::operator= ( PyFloat &&  oth)
delete
double PyFloat::value ( ) const
inline
bool PyFloat::visit ( PyVisitor v) const
virtual

Visits object.

Parameters
[in]vVisitor to be used for visiting.
Return values
trueVisit successful.
falseError during visit.

Implements PyRep.

Definition at line 246 of file PyRep.cpp.

References PyVisitor::VisitReal().

247 {
248  return v.VisitReal( this );
249 }
virtual bool VisitReal(const PyFloat *rep)
Definition: PyVisitor.h:57

Here is the call graph for this function:

Member Data Documentation

const double PyFloat::mValue
protected

Definition at line 315 of file PyRep.h.

Referenced by hash(), and value().


The documentation for this class was generated from the following files: