2009-07-24 08:35:21 +00:00
|
|
|
#ifndef _PYC_NUMERIC_H
|
|
|
|
#define _PYC_NUMERIC_H
|
|
|
|
|
2011-10-23 17:48:10 -07:00
|
|
|
#include "pyc_object.h"
|
2014-06-05 15:11:06 +11:00
|
|
|
#include "data.h"
|
2022-12-01 11:35:14 -08:00
|
|
|
#include <vector>
|
2011-09-23 21:46:05 -07:00
|
|
|
#include <string>
|
2009-07-24 08:35:21 +00:00
|
|
|
|
|
|
|
class PycInt : public PycObject {
|
|
|
|
public:
|
|
|
|
PycInt(int value = 0, int type = TYPE_INT)
|
|
|
|
: PycObject(type), m_value(value) { }
|
|
|
|
|
2019-10-02 14:40:25 -07:00
|
|
|
bool isEqual(PycRef<PycObject> obj) const override
|
2009-07-25 02:41:15 +00:00
|
|
|
{
|
2017-07-05 16:36:04 -07:00
|
|
|
return (type() == obj.type()) &&
|
2009-07-25 02:41:15 +00:00
|
|
|
(m_value == obj.cast<PycInt>()->m_value);
|
|
|
|
}
|
2009-07-24 21:15:51 +00:00
|
|
|
|
2019-10-02 14:40:25 -07:00
|
|
|
void load(class PycData* stream, class PycModule* mod) override;
|
2009-07-24 08:35:21 +00:00
|
|
|
|
|
|
|
int value() const { return m_value; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_value;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PycLong : public PycObject {
|
|
|
|
public:
|
|
|
|
PycLong(int type = TYPE_LONG)
|
|
|
|
: PycObject(type), m_size(0) { }
|
|
|
|
|
2019-10-02 14:40:25 -07:00
|
|
|
bool isEqual(PycRef<PycObject> obj) const override;
|
2009-07-24 21:15:51 +00:00
|
|
|
|
2019-10-02 14:40:25 -07:00
|
|
|
void load(class PycData* stream, class PycModule* mod) override;
|
2009-07-24 08:35:21 +00:00
|
|
|
|
|
|
|
int size() const { return m_size; }
|
2022-12-01 11:35:14 -08:00
|
|
|
const std::vector<int>& value() const { return m_value; }
|
2009-07-24 08:35:21 +00:00
|
|
|
|
2011-09-23 21:46:05 -07:00
|
|
|
std::string repr() const;
|
|
|
|
|
2009-07-24 08:35:21 +00:00
|
|
|
private:
|
|
|
|
int m_size;
|
2022-12-01 11:35:14 -08:00
|
|
|
std::vector<int> m_value;
|
2009-07-24 08:35:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PycFloat : public PycObject {
|
|
|
|
public:
|
|
|
|
PycFloat(int type = TYPE_FLOAT)
|
2019-10-02 16:01:54 -07:00
|
|
|
: PycObject(type) { }
|
2009-07-24 08:35:21 +00:00
|
|
|
|
2019-10-02 14:40:25 -07:00
|
|
|
bool isEqual(PycRef<PycObject> obj) const override;
|
2009-07-24 21:15:51 +00:00
|
|
|
|
2019-10-02 14:40:25 -07:00
|
|
|
void load(class PycData* stream, class PycModule* mod) override;
|
2009-07-24 08:35:21 +00:00
|
|
|
|
2019-10-02 16:01:54 -07:00
|
|
|
const char* value() const { return m_value.c_str(); }
|
2009-07-24 08:35:21 +00:00
|
|
|
|
|
|
|
private:
|
2019-10-02 16:01:54 -07:00
|
|
|
std::string m_value; // Floats are stored as strings
|
2009-07-24 08:35:21 +00:00
|
|
|
};
|
|
|
|
|
2009-07-25 02:41:15 +00:00
|
|
|
class PycComplex : public PycFloat {
|
|
|
|
public:
|
|
|
|
PycComplex(int type = TYPE_COMPLEX)
|
2019-10-02 16:01:54 -07:00
|
|
|
: PycFloat(type) { }
|
2009-07-25 02:41:15 +00:00
|
|
|
|
2019-10-02 14:40:25 -07:00
|
|
|
bool isEqual(PycRef<PycObject> obj) const override;
|
2009-07-25 02:41:15 +00:00
|
|
|
|
2019-10-02 14:40:25 -07:00
|
|
|
void load(class PycData* stream, class PycModule* mod) override;
|
2009-07-25 02:41:15 +00:00
|
|
|
|
2019-10-02 16:01:54 -07:00
|
|
|
const char* imag() const { return m_imag.c_str(); }
|
2009-07-25 02:41:15 +00:00
|
|
|
|
|
|
|
private:
|
2019-10-02 16:01:54 -07:00
|
|
|
std::string m_imag;
|
2009-07-25 02:41:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PycCFloat : public PycObject {
|
|
|
|
public:
|
|
|
|
PycCFloat(int type = TYPE_BINARY_FLOAT)
|
2014-06-05 12:17:06 +11:00
|
|
|
: PycObject(type), m_value(0.0) { }
|
2009-07-25 02:41:15 +00:00
|
|
|
|
2019-10-02 14:40:25 -07:00
|
|
|
bool isEqual(PycRef<PycObject> obj) const override
|
2009-07-25 02:41:15 +00:00
|
|
|
{
|
2017-07-05 16:36:04 -07:00
|
|
|
return (type() == obj.type()) &&
|
2014-06-05 12:26:16 +11:00
|
|
|
(m_value == obj.cast<PycCFloat>()->m_value);
|
2009-07-25 02:41:15 +00:00
|
|
|
}
|
|
|
|
|
2019-10-02 14:40:25 -07:00
|
|
|
void load(class PycData* stream, class PycModule* mod) override;
|
2009-07-25 02:41:15 +00:00
|
|
|
|
2014-06-05 12:17:06 +11:00
|
|
|
double value() const { return m_value; }
|
2009-07-25 02:41:15 +00:00
|
|
|
|
|
|
|
private:
|
2017-07-05 15:53:35 -07:00
|
|
|
double m_value;
|
2009-07-25 02:41:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class PycCComplex : public PycCFloat {
|
|
|
|
public:
|
|
|
|
PycCComplex(int type = TYPE_BINARY_COMPLEX)
|
|
|
|
: PycCFloat(type), m_imag(0.0) { }
|
|
|
|
|
2019-10-02 14:40:25 -07:00
|
|
|
bool isEqual(PycRef<PycObject> obj) const override
|
2009-07-25 02:41:15 +00:00
|
|
|
{
|
|
|
|
return (PycCFloat::isEqual(obj)) &&
|
|
|
|
(m_imag == obj.cast<PycCComplex>()->m_imag);
|
|
|
|
}
|
|
|
|
|
2019-10-02 14:40:25 -07:00
|
|
|
void load(class PycData* stream, class PycModule* mod) override;
|
2009-07-25 02:41:15 +00:00
|
|
|
|
|
|
|
double imag() const { return m_imag; }
|
|
|
|
|
|
|
|
private:
|
2017-07-05 15:53:35 -07:00
|
|
|
double m_imag;
|
2009-07-25 02:41:15 +00:00
|
|
|
};
|
|
|
|
|
2009-07-24 08:35:21 +00:00
|
|
|
#endif
|