blob: b854cb286062bfd4961420b2d3f595e95dff0335 [file] [log] [blame]
Benny Prijono5dcb38d2005-11-21 01:55:47 +00001/* $Id$ */
2/*
3 * Copyright (C)2003-2006 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
22
23#if defined(PJ_HAS_FLOATING_POINT) && PJ_HAS_FLOATING_POINT != 0
24 /*
25 * The first choice for high precision math is to use double.
26 */
27# include <math.h>
28 typedef double pj_highprec_t;
29
30# define PJ_HIGHPREC_VALUE_IS_ZERO(a) (a==0)
31# define pj_highprec_mod(a,b) (a=fmod(a,b))
32
33#elif defined(PJ_LINUX_KERNEL) && PJ_LINUX_KERNEL != 0
34
35# include <asm/div64.h>
36
37 typedef pj_int64_t pj_highprec_t;
38
39# define pj_highprec_div(a1,a2) do_div(a1,a2)
40# define pj_highprec_mod(a1,a2) (a1=do_mod(a1, a2))
41
42 PJ_INLINE(pj_int64_t) do_mod( pj_int64_t a1, pj_int64_t a2)
43 {
44 return do_div(a1,a2);
45 }
46
47
48#elif defined(PJ_HAS_INT64) && PJ_HAS_INT64 != 0
49 /*
50 * Next choice is to use 64-bit arithmatics.
51 */
52 typedef pj_int64_t pj_highprec_t;
53
54#else
55# warning "High precision math is not available"
56
57 /*
58 * Last, fallback to 32-bit arithmetics.
59 */
60 typedef pj_int32_t pj_highprec_t;
61
62#endif
63
64/**
65 * @def pj_highprec_mul
66 * pj_highprec_mul(a1, a2) - High Precision Multiplication
67 * Multiply a1 and a2, and store the result in a1.
68 */
69#ifndef pj_highprec_mul
70# define pj_highprec_mul(a1,a2) (a1 = a1 * a2)
71#endif
72
73/**
74 * @def pj_highprec_div
75 * pj_highprec_div(a1, a2) - High Precision Division
76 * Divide a2 from a1, and store the result in a1.
77 */
78#ifndef pj_highprec_div
79# define pj_highprec_div(a1,a2) (a1 = a1 / a2)
80#endif
81
82/**
83 * @def pj_highprec_mod
84 * pj_highprec_mod(a1, a2) - High Precision Modulus
85 * Get the modulus a2 from a1, and store the result in a1.
86 */
87#ifndef pj_highprec_mod
88# define pj_highprec_mod(a1,a2) (a1 = a1 % a2)
89#endif
90
91
92/**
93 * @def PJ_HIGHPREC_VALUE_IS_ZERO(a)
94 * Test if the specified high precision value is zero.
95 */
96#ifndef PJ_HIGHPREC_VALUE_IS_ZERO
97# define PJ_HIGHPREC_VALUE_IS_ZERO(a) (a==0)
98#endif
99
100
101#endif /* __PJ_COMPAT_HIGH_PRECISION_H__ */
102