2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-23 17:52:09 +00:00
Files
math/tools/ntl.diff
John Maddock aa2c565d12 Initial commit.
[SVN r2955]
2006-05-21 15:45:37 +00:00

136 lines
3.3 KiB
Diff

diff -b -r -u WinNTL-5_4/include/NTL/RR.h WinNTL-5_4_patch/include/NTL/RR.h
--- WinNTL-5_4/include/NTL/RR.h 2005-03-25 07:59:12.000000000 +0000
+++ WinNTL-5_4_patch/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 -b -r -u WinNTL-5_4/include/NTL/quad_float.h WinNTL-5_4_patch/include/NTL/quad_float.h
--- WinNTL-5_4/include/NTL/quad_float.h 2005-03-25 07:59:14.000000000 +0000
+++ WinNTL-5_4_patch/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 -b -r -u WinNTL-5_4/src/RR.cpp WinNTL-5_4_patch/src/RR.cpp
--- WinNTL-5_4/src/RR.cpp 2005-03-25 07:59:08.000000000 +0000
+++ WinNTL-5_4_patch/src/RR.cpp 2006-03-25 13:31:14.338248000 +0000
@@ -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)
{