mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-30 04:00:02 +02:00
[poincare] Add a constructor in Integer
Change-Id: Icf84821d1b898dbe353a2ee3cda7cfbb5c0b5468
This commit is contained in:
@@ -217,7 +217,7 @@ protected:
|
||||
typedef float SinglePrecision;
|
||||
typedef double DoublePrecision;
|
||||
template<typename T> static T epsilon();
|
||||
constexpr static float k_maxNumberOfSteps = 10000.0f;
|
||||
constexpr static int k_maxNumberOfSteps = 10000;
|
||||
|
||||
/* Simplification */
|
||||
/* SimplificationOrder returns:
|
||||
|
||||
@@ -16,6 +16,7 @@ class Integer {
|
||||
public:
|
||||
typedef uint16_t half_native_uint_t;
|
||||
typedef int32_t native_int_t;
|
||||
typedef int64_t double_native_int_t;
|
||||
typedef uint32_t native_uint_t;
|
||||
typedef uint64_t double_native_uint_t;
|
||||
|
||||
@@ -26,6 +27,7 @@ public:
|
||||
m_negative(i<0)
|
||||
{
|
||||
}
|
||||
Integer(double_native_int_t i);
|
||||
Integer(const char * digits, bool negative = false); // Digits are NOT NULL-terminated
|
||||
static Integer exponent(int fractionalPartLength, const char * exponent, int exponentLength, bool exponentNegative);
|
||||
static Integer numerator(const char * integralPart, int integralPartLength, const char * fractionalPart, int fractionalPartLength, bool negative, Integer * exponent);
|
||||
|
||||
@@ -34,6 +34,21 @@ static inline int8_t sign(bool negative) {
|
||||
|
||||
// Constructors
|
||||
|
||||
Integer::Integer(double_native_int_t i) {
|
||||
double_native_uint_t j = i < 0 ? -i : i;
|
||||
if (j <= 0xFFFFFFFF) {
|
||||
m_digit = j;
|
||||
m_numberOfDigits = 1;
|
||||
} else {
|
||||
native_uint_t * digits = new native_uint_t [2];
|
||||
digits[0] = j & 0xFFFFFFFF;
|
||||
digits[1] = (j >> 32) & 0xFFFFFFFF;
|
||||
m_digits = digits;
|
||||
m_numberOfDigits = 2;
|
||||
}
|
||||
m_negative = i < 0;
|
||||
}
|
||||
|
||||
/* Caution: string is NOT guaranteed to be NULL-terminated! */
|
||||
Integer::Integer(const char * digits, bool negative) :
|
||||
Integer(0)
|
||||
@@ -408,9 +423,9 @@ IntegerDivision Integer::udiv(const Integer & numerator, const Integer & denomin
|
||||
}
|
||||
Integer A = numerator;
|
||||
Integer B = denominator;
|
||||
native_uint_t base = (double_native_uint_t)1 << 16;
|
||||
native_int_t base = (double_native_uint_t)1 << 16;
|
||||
// TODO: optimize by just swifting digit and finding 2^kB that makes B normalized
|
||||
native_uint_t d = base/(native_uint_t)(B.halfDigit(B.numberOfHalfDigits()-1)+1);
|
||||
native_int_t d = base/(native_int_t)(B.halfDigit(B.numberOfHalfDigits()-1)+1);
|
||||
A = Multiplication(Integer(d), A);
|
||||
B = Multiplication(Integer(d), B);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user