|
@@ -29,11 +29,9 @@ Rational::Rational(float x)
|
|
|
uint32_t significand = (1u << 23u) | mantisBits;
|
|
|
|
|
|
const int64_t sign = signBit ? -1 : 1;
|
|
|
-
|
|
|
const int32_t exp = exponentBits - 127 - 23;
|
|
|
static uint32_t smth = 1 << (uint32_t)(-exp);
|
|
|
|
|
|
- cout << sign * (int64_t)(significand) << '/' << smth;
|
|
|
num = sign * (int64_t)(significand);
|
|
|
denum = smth;
|
|
|
simple();
|
|
@@ -48,20 +46,11 @@ Rational::Rational(double x)
|
|
|
unsigned long long int significant = (long long int)pow(2, 52) | mantisBits;
|
|
|
|
|
|
const long long int sign = signBit ? -1 : 1;
|
|
|
-
|
|
|
const long long int exp = exponentBits - 1023 - 52;
|
|
|
|
|
|
- cout << bitset<64>(bits) << endl;
|
|
|
- cout << bitset<64>(signBit) << endl;
|
|
|
- cout << bitset<64>(exponentBits) << endl;
|
|
|
- cout << bitset<64>(mantisBits) << endl;
|
|
|
- cout << bitset<64>(pow(2,52)) << endl;
|
|
|
- cout << bitset<64>(significant) << endl;
|
|
|
- cout << bitset<64>(exp) << endl;
|
|
|
-
|
|
|
- cout << setprecision(15) << fixed << sign * significant << '/' << (unsigned long long int)pow(2, -exp) << endl;
|
|
|
- cout << (sign * significant) / pow(2, -exp) << endl;
|
|
|
- cout << sign * pow(2, -1022) * significant << endl;
|
|
|
+ num = (long long int)(sign * significant);
|
|
|
+ denum = (long long int)pow(2, -exp);
|
|
|
+ simple();
|
|
|
}
|
|
|
|
|
|
Rational& Rational::operator += (const Rational& r)
|
|
@@ -135,7 +124,7 @@ Rational::operator int() const
|
|
|
return int(double(*this));
|
|
|
}
|
|
|
|
|
|
-int Rational::lcm(long long int num1, long long int num2)
|
|
|
+long long int Rational::lcm(long long int num1, long long int num2)
|
|
|
{
|
|
|
int result = 1;
|
|
|
for(int dnum = 2; num1 > 1 or num2 > 1; dnum++)
|
|
@@ -151,7 +140,7 @@ int Rational::lcm(long long int num1, long long int num2)
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
-int Rational::gcd(long long int num1, long long int num2)
|
|
|
+long long int Rational::gcd(long long int num1, long long int num2)
|
|
|
{
|
|
|
while (num1 && num2)
|
|
|
if (num1 >= num2)
|
|
@@ -163,7 +152,7 @@ int Rational::gcd(long long int num1, long long int num2)
|
|
|
|
|
|
void Rational::simple()
|
|
|
{
|
|
|
- int gct = gcd(num, denum);
|
|
|
+ long long int gct = gcd(num, denum);
|
|
|
num /= gct;
|
|
|
denum /= gct;
|
|
|
}
|