|
41 | 41 | #include <vector> |
42 | 42 | #include <map> |
43 | 43 | #include <algorithm> |
44 | | -//#include <numeric> |
| 44 | +#ifdef _LIBCPP_VERSION |
| 45 | +#include <numeric> |
| 46 | +#else |
45 | 47 | #include <ext/numeric> |
| 48 | +#endif |
46 | 49 | #include <iterator> |
47 | 50 | using namespace std; |
48 | 51 | #include "templates.h" |
@@ -154,12 +157,81 @@ inline int is_approx_zero(const RR& x) |
154 | 157 | if (n>=0) return 0; |
155 | 158 | // cout<<"x="<<x<<", exponent="<<x.exponent()<<", mantissa="<<x.mantissa()<<", precision="<<RR::precision()<<endl; |
156 | 159 | // 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 | +} |
158 | 162 | } // 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 | + |
159 | 189 | #include <complex> |
160 | 190 | typedef complex<RR> CC; |
161 | 191 | #define bigcomplex CC |
162 | 192 |
|
| 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 | + |
163 | 235 | inline void set_precision(long n) |
164 | 236 | {RR::SetPrecision(long(n*3.33));RR::SetOutputPrecision(n);} |
165 | 237 | inline void set_bit_precision(long n) |
|
0 commit comments