Benny Prijono | 4766ffe | 2005-11-01 17:56:59 +0000 | [diff] [blame] | 1 | /* $Id$ |
| 2 | * |
| 3 | */ |
Benny Prijono | dd859a6 | 2005-11-01 16:42:51 +0000 | [diff] [blame] | 4 | #ifndef __PJ_COMPAT_HIGH_PRECISION_H__ |
| 5 | #define __PJ_COMPAT_HIGH_PRECISION_H__ |
| 6 | |
| 7 | |
| 8 | #if defined(PJ_HAS_FLOATING_POINT) && PJ_HAS_FLOATING_POINT != 0 |
| 9 | /* |
| 10 | * The first choice for high precision math is to use double. |
| 11 | */ |
| 12 | # include <math.h> |
| 13 | typedef double pj_highprec_t; |
| 14 | |
| 15 | # define PJ_HIGHPREC_VALUE_IS_ZERO(a) (a==0) |
| 16 | # define pj_highprec_mod(a,b) (a=fmod(a,b)) |
| 17 | |
| 18 | #elif defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0 |
| 19 | |
| 20 | # include <asm/div64.h> |
| 21 | |
| 22 | typedef pj_int64_t pj_highprec_t; |
| 23 | |
| 24 | # define pj_highprec_div(a1,a2) do_div(a1,a2) |
| 25 | # define pj_highprec_mod(a1,a2) (a1=do_mod(a1, a2)) |
| 26 | |
| 27 | PJ_INLINE(pj_int64_t) do_mod( pj_int64_t a1, pj_int64_t a2) |
| 28 | { |
| 29 | return do_div(a1,a2); |
| 30 | } |
| 31 | |
| 32 | |
| 33 | #elif defined(PJ_HAS_INT64) && PJ_HAS_INT64 != 0 |
| 34 | /* |
| 35 | * Next choice is to use 64-bit arithmatics. |
| 36 | */ |
| 37 | typedef pj_int64_t pj_highprec_t; |
| 38 | |
| 39 | #else |
| 40 | # warning "High precision math is not available" |
| 41 | |
| 42 | /* |
| 43 | * Last, fallback to 32-bit arithmetics. |
| 44 | */ |
| 45 | typedef pj_int32_t pj_highprec_t; |
| 46 | |
| 47 | #endif |
| 48 | |
| 49 | /** |
| 50 | * @def pj_highprec_mul |
| 51 | * pj_highprec_mul(a1, a2) - High Precision Multiplication |
| 52 | * Multiply a1 and a2, and store the result in a1. |
| 53 | */ |
| 54 | #ifndef pj_highprec_mul |
| 55 | # define pj_highprec_mul(a1,a2) (a1 = a1 * a2) |
| 56 | #endif |
| 57 | |
| 58 | /** |
| 59 | * @def pj_highprec_div |
| 60 | * pj_highprec_div(a1, a2) - High Precision Division |
| 61 | * Divide a2 from a1, and store the result in a1. |
| 62 | */ |
| 63 | #ifndef pj_highprec_div |
| 64 | # define pj_highprec_div(a1,a2) (a1 = a1 / a2) |
| 65 | #endif |
| 66 | |
| 67 | /** |
| 68 | * @def pj_highprec_mod |
| 69 | * pj_highprec_mod(a1, a2) - High Precision Modulus |
| 70 | * Get the modulus a2 from a1, and store the result in a1. |
| 71 | */ |
| 72 | #ifndef pj_highprec_mod |
| 73 | # define pj_highprec_mod(a1,a2) (a1 = a1 % a2) |
| 74 | #endif |
| 75 | |
| 76 | |
| 77 | /** |
| 78 | * @def PJ_HIGHPREC_VALUE_IS_ZERO(a) |
| 79 | * Test if the specified high precision value is zero. |
| 80 | */ |
| 81 | #ifndef PJ_HIGHPREC_VALUE_IS_ZERO |
| 82 | # define PJ_HIGHPREC_VALUE_IS_ZERO(a) (a==0) |
| 83 | #endif |
| 84 | |
| 85 | |
| 86 | #endif /* __PJ_COMPAT_HIGH_PRECISION_H__ */ |
| 87 | |