Skip to content

Commit deb18a8

Browse files
committed
Merge branch 'kf/libcxx' of git://github.com/Keno/eclib into Keno-kf/libcxx
Conflicts: libsrc/timer.cc
2 parents 8f3fc6a + 6ad4e87 commit deb18a8

File tree

1 file changed

+74
-2
lines changed

1 file changed

+74
-2
lines changed

libsrc/eclib/interface.h

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,11 @@
4141
#include <vector>
4242
#include <map>
4343
#include <algorithm>
44-
//#include <numeric>
44+
#ifdef _LIBCPP_VERSION
45+
#include <numeric>
46+
#else
4547
#include <ext/numeric>
48+
#endif
4649
#include <iterator>
4750
using namespace std;
4851
#include "templates.h"
@@ -154,12 +157,81 @@ inline int is_approx_zero(const RR& x)
154157
if (n>=0) return 0;
155158
// cout<<"x="<<x<<", exponent="<<x.exponent()<<", mantissa="<<x.mantissa()<<", precision="<<RR::precision()<<endl;
156159
// cout<<"is_approx_zero() returns "<<(x.mantissa()<power2_ZZ(-n))<<endl;
157-
return abs(x.mantissa())<power2_ZZ(-n);}
160+
return abs(x.mantissa())<power2_ZZ(-n);
161+
}
158162
} // namespace NTL
163+
#ifdef _LIBCPP_VERSION
164+
namespace std {
165+
inline namespace __1 {
166+
inline bool isinf(const RR& z) {
167+
return false;
168+
}
169+
inline bool isnan(const RR& z) {
170+
return false;
171+
}
172+
inline RR copysign(const RR& x, const RR& y) {
173+
if (sign(x) != sign(y)) {
174+
return -y;
175+
}
176+
return y;
177+
}
178+
inline bool signbit(const RR& x) {
179+
return sign(x) < 0;
180+
}
181+
inline RR fmax(const RR& x, const RR& y)
182+
{
183+
return x < y ? y : x;
184+
}
185+
}
186+
}
187+
#endif
188+
159189
#include <complex>
160190
typedef complex<RR> CC;
161191
#define bigcomplex CC
162192

193+
#ifdef _LIBCPP_VERSION
194+
template <> inline RR std::abs(const CC &z)
195+
{
196+
RR re = z.real();
197+
RR im = z.imag();
198+
return sqrt(re*re + im*im);
199+
}
200+
template <> inline CC std::exp(const CC &z)
201+
{
202+
RR im = z.imag();
203+
RR e = exp(z.real());
204+
return CC(e * cos(im), e * sin(im));
205+
}
206+
inline CC operator/(const CC &a, const CC &b)
207+
{
208+
RR are = a.real();
209+
RR aim = a.imag();
210+
RR bre = b.real();
211+
RR bim = b.imag();
212+
if (abs(bre) <= abs(bim)) {
213+
RR r = bre / bim;
214+
RR den = bim + r*bre;
215+
return CC((are*r + aim)/den, (aim*r - are)/den);
216+
} else {
217+
RR r = bim / bre;
218+
RR den = bre + r*bim;
219+
return CC((are + aim*r)/den, (aim - are*r)/den);
220+
}
221+
}
222+
inline CC operator /(const RR &a, const CC &b)
223+
{
224+
CC r(a);
225+
return r/b;
226+
}
227+
inline CC &operator /=(CC &a, const CC &b)
228+
{
229+
a = a/b;
230+
return a;
231+
}
232+
233+
#endif
234+
163235
inline void set_precision(long n)
164236
{RR::SetPrecision(long(n*3.33));RR::SetOutputPrecision(n);}
165237
inline void set_bit_precision(long n)

0 commit comments

Comments
 (0)