mirror of
https://github.com/boostorg/math.git
synced 2026-01-19 04:22:09 +00:00
176 lines
4.1 KiB
Diff
176 lines
4.1 KiB
Diff
diff -r -u ntl/WinNTL-5_4/include/NTL/RR.h WinNTL-5_4/include/NTL/RR.h
|
|
--- ntl/WinNTL-5_4/include/NTL/RR.h 2005-03-25 07:59:12.000000000 +0000
|
|
+++ WinNTL-5_4/include/NTL/RR.h 2006-03-23 17:06:36.742860800 +0000
|
|
@@ -17,6 +17,13 @@
|
|
|
|
RR() { e = 0; }
|
|
|
|
+inline RR(long double t)
|
|
+: e(0)
|
|
+{
|
|
+ *this = t;
|
|
+}
|
|
+RR(quad_float const& t);
|
|
+
|
|
inline RR(INIT_VAL_TYPE, const ZZ& a);
|
|
inline RR(INIT_VAL_TYPE, int a);
|
|
inline RR(INIT_VAL_TYPE, long a);
|
|
@@ -30,7 +37,7 @@
|
|
inline RR(INIT_VAL_TYPE, const RR& a);
|
|
|
|
|
|
-inline RR& operator=(double a);
|
|
+inline RR& operator=(long double a);
|
|
|
|
RR(RR& z, INIT_TRANS_TYPE) : x(z.x, INIT_TRANS), e(z.e) { }
|
|
|
|
@@ -346,8 +353,9 @@
|
|
void conv(RR& z, unsigned long a);
|
|
inline void conv(RR& z, unsigned int a) { conv(z, (unsigned long)(a)); }
|
|
void conv(RR& z, const char *s);
|
|
-void conv(RR& z, double a);
|
|
-inline void conv(RR& z, float a) { conv(z, double(a)); }
|
|
+void conv(RR& z, long double a);
|
|
+inline void conv(RR& z, float a) { conv(z, (long double)(a)); }
|
|
+inline void conv(RR& z, double a) { conv(z, (long double)(a)); }
|
|
void conv(RR& z, const xdouble& a);
|
|
void conv(RR& z, const quad_float& a);
|
|
|
|
@@ -381,7 +389,7 @@
|
|
inline RR to_RR(const quad_float& a) { return RR(INIT_VAL, a); }
|
|
inline RR to_RR(const char *a) { return RR(INIT_VAL, a); }
|
|
|
|
-inline RR& RR::operator=(double a) { conv(*this, a); return *this; }
|
|
+inline RR& RR::operator=(long double a) { conv(*this, a); return *this; }
|
|
|
|
void conv(ZZ& z, const RR& a);
|
|
void conv(long& z, const RR& a);
|
|
@@ -488,6 +496,11 @@
|
|
inline RR cos(const RR& a)
|
|
{ RR z; cos(z, a); NTL_OPT_RETURN(RR, z); }
|
|
|
|
+inline RR::RR(quad_float const& t)
|
|
+: e(0)
|
|
+{
|
|
+ conv(*this, t);
|
|
+}
|
|
|
|
diff -r -u ntl/WinNTL-5_4/include/NTL/quad_float.h WinNTL-5_4/include/NTL/quad_float.h
|
|
--- ntl/WinNTL-5_4/include/NTL/quad_float.h 2005-03-25 07:59:14.000000000 +0000
|
|
+++ WinNTL-5_4/include/NTL/quad_float.h 2006-03-23 12:25:57.453315200 +0000
|
|
@@ -67,7 +67,7 @@
|
|
static void SetOutputPrecision(long p);
|
|
static long OutputPrecision() { return oprec; }
|
|
|
|
- quad_float(double x, double y) : hi(x), lo(y) { } // internal use only
|
|
+ quad_float(double x, double y = 0) : hi(x), lo(y) { } // internal use only
|
|
|
|
~quad_float() {}
|
|
|
|
diff -r -u ntl/WinNTL-5_4/src/RR.cpp WinNTL-5_4/src/RR.cpp
|
|
--- ntl/WinNTL-5_4/src/RR.cpp 2005-03-25 07:59:08.000000000 +0000
|
|
+++ WinNTL-5_4/src/RR.cpp 2006-09-12 17:28:15.281374400 +0100
|
|
@@ -66,7 +66,7 @@
|
|
Error("RR: overflow");
|
|
|
|
if (z.e <= -NTL_OVFBND)
|
|
- Error("RR: underflow");
|
|
+ z = 0; // Error("RR: underflow");
|
|
}
|
|
|
|
void normalize(RR& z, const RR& y, long residual = 0)
|
|
@@ -570,7 +570,7 @@
|
|
xcopy(z, t);
|
|
}
|
|
|
|
-void RoundPrec(RR& x, const RR& a, const RR& b, long p)
|
|
+void RoundPrec(RR& x, const RR& a, long p)
|
|
{
|
|
if (p < 1 || NTL_OVERFLOW(p, 1, 0))
|
|
Error("RoundPrec: bad precsion");
|
|
@@ -657,7 +657,7 @@
|
|
RR::prec = old_p;
|
|
}
|
|
|
|
-
|
|
+/*
|
|
void conv(RR& z, double a)
|
|
{
|
|
if (a == 0) {
|
|
@@ -687,6 +687,41 @@
|
|
|
|
xcopy(z, t);
|
|
}
|
|
+*/
|
|
+void conv(RR& z, long double a)
|
|
+{
|
|
+ if (a == 0) {
|
|
+ clear(z);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ if (a == 1) {
|
|
+ set(z);
|
|
+ return;
|
|
+ }
|
|
+
|
|
+ //if (!IsFinite(&a))
|
|
+ //Error("RR: conversion of a non-finite double");
|
|
+
|
|
+ int e;
|
|
+ long double f, term;
|
|
+ RR t;
|
|
+ clear(z);
|
|
+
|
|
+ f = frexp(a, &e);
|
|
+
|
|
+ while(f)
|
|
+ {
|
|
+ // extract 30 bits from f:
|
|
+ f = ldexp(f, 30);
|
|
+ term = floor(f);
|
|
+ e -= 30;
|
|
+ conv(t.x, (int)term);
|
|
+ t.e = e;
|
|
+ z += t;
|
|
+ f -= term;
|
|
+ }
|
|
+}
|
|
|
|
void ConvPrec(RR& x, double a, long p)
|
|
{
|
|
@@ -1069,7 +1104,7 @@
|
|
Error("RR: overflow");
|
|
|
|
if (z.e <= -NTL_OVFBND)
|
|
- Error("RR: underflow");
|
|
+ z = 0; // Error("RR: underflow");
|
|
}
|
|
|
|
void ConvPrec(RR& x, const xdouble& a, long p)
|
|
@@ -1100,11 +1135,12 @@
|
|
if (e >= NTL_OVFBND)
|
|
Error("RR: overflow");
|
|
|
|
- if (e <= -NTL_OVFBND)
|
|
- Error("RR: underflow");
|
|
|
|
set(z.x);
|
|
z.e = e;
|
|
+
|
|
+ if (e <= -NTL_OVFBND)
|
|
+ z = 0; // Error("RR: underflow");
|
|
}
|
|
|
|
void conv(RR& z, const quad_float& a)
|
|
@@ -2019,7 +2055,7 @@
|
|
|
|
bp[len] = '\0';
|
|
|
|
- if (k > 3 || k < -len - 3) {
|
|
+ if ((s.flags() & ostream::scientific) || (k > 3 || k < -len - 3)) {
|
|
// use scientific notation
|
|
|
|
if (neg) s << "-";
|
|
|