high_precision.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  3. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. */
  19. #ifndef __PJ_COMPAT_HIGH_PRECISION_H__
  20. #define __PJ_COMPAT_HIGH_PRECISION_H__
  21. #if defined(PJ_HAS_FLOATING_POINT) && PJ_HAS_FLOATING_POINT != 0
  22. /*
  23. * The first choice for high precision math is to use double.
  24. */
  25. # include <math.h>
  26. typedef double pj_highprec_t;
  27. # define PJ_HIGHPREC_VALUE_IS_ZERO(a) (a==0)
  28. # define pj_highprec_mod(a,b) (a=fmod(a,b))
  29. #elif defined(PJ_HAS_INT64) && PJ_HAS_INT64 != 0
  30. /*
  31. * Next choice is to use 64-bit arithmatics.
  32. */
  33. typedef pj_int64_t pj_highprec_t;
  34. #else
  35. # warning "High precision math is not available"
  36. /*
  37. * Last, fallback to 32-bit arithmetics.
  38. */
  39. typedef pj_int32_t pj_highprec_t;
  40. #endif
  41. /**
  42. * @def pj_highprec_mul
  43. * pj_highprec_mul(a1, a2) - High Precision Multiplication
  44. * Multiply a1 and a2, and store the result in a1.
  45. */
  46. #ifndef pj_highprec_mul
  47. # define pj_highprec_mul(a1,a2) (a1 = a1 * a2)
  48. #endif
  49. /**
  50. * @def pj_highprec_div
  51. * pj_highprec_div(a1, a2) - High Precision Division
  52. * Divide a2 from a1, and store the result in a1.
  53. */
  54. #ifndef pj_highprec_div
  55. # define pj_highprec_div(a1,a2) (a1 = a1 / a2)
  56. #endif
  57. /**
  58. * @def pj_highprec_mod
  59. * pj_highprec_mod(a1, a2) - High Precision Modulus
  60. * Get the modulus a2 from a1, and store the result in a1.
  61. */
  62. #ifndef pj_highprec_mod
  63. # define pj_highprec_mod(a1,a2) (a1 = a1 % a2)
  64. #endif
  65. /**
  66. * @def PJ_HIGHPREC_VALUE_IS_ZERO(a)
  67. * Test if the specified high precision value is zero.
  68. */
  69. #ifndef PJ_HIGHPREC_VALUE_IS_ZERO
  70. # define PJ_HIGHPREC_VALUE_IS_ZERO(a) (a==0)
  71. #endif
  72. #endif /* __PJ_COMPAT_HIGH_PRECISION_H__ */