[29] | 1 | #include "RealNumberTypes.h" |
---|
| 2 | |
---|
| 3 | #include <math.h> |
---|
| 4 | |
---|
| 5 | #ifdef GMP_BIGNUM |
---|
| 6 | |
---|
| 7 | const mpf_class mpf_TWO = 2.0; |
---|
| 8 | |
---|
| 9 | bool pow(mpf_class &res, const mpf_class &base, unsigned long int iExp) |
---|
| 10 | { |
---|
| 11 | mpf_pow_ui(res.get_mpf_t(),base.get_mpf_t(), iExp); |
---|
| 12 | return true; |
---|
| 13 | } |
---|
| 14 | |
---|
| 15 | bool pow2(mpf_class &res, unsigned long int iExp) |
---|
| 16 | { |
---|
| 17 | mpf_class x(2.0,res.get_prec()); |
---|
| 18 | // x= 2.0; |
---|
| 19 | mpf_pow_ui(res.get_mpf_t(),x.get_mpf_t(), iExp); |
---|
| 20 | return true; |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | bool to_div_2exp(mpf_class &res, const mpf_class &op1, unsigned long int iExp) |
---|
| 24 | { |
---|
| 25 | mpf_div_2exp(res.get_mpf_t(),op1.get_mpf_t(),iExp); |
---|
| 26 | return true; |
---|
| 27 | } |
---|
| 28 | |
---|
| 29 | double to_doubleT(const mpf_class &num) |
---|
| 30 | { |
---|
| 31 | return mpf_get_d(num.get_mpf_t()); |
---|
| 32 | } |
---|
| 33 | |
---|
| 34 | #else |
---|
| 35 | |
---|
| 36 | bool pow(CRealNum &res, double &base, unsigned long int iExp) |
---|
| 37 | { |
---|
| 38 | res = pow(base, iExp); |
---|
| 39 | return true; |
---|
| 40 | } |
---|
| 41 | |
---|
| 42 | bool pow2(CRealNum &res, unsigned long int iExp) |
---|
| 43 | { |
---|
| 44 | res = pow(2.00, iExp); |
---|
| 45 | return true; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | bool to_div_2exp(CRealNum &res, const CRealNum &op1, unsigned long int iExp) |
---|
| 50 | { |
---|
| 51 | res = op1 / pow(2.00,iExp); |
---|
| 52 | return true; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | |
---|
| 56 | long double to_doubleT(const CRealNum &num) |
---|
| 57 | { |
---|
| 58 | return (long double) num; |
---|
| 59 | } |
---|
| 60 | #endif |
---|