1 |
jds |
54 |
/* |
2 |
aw0a |
1 |
* Rounded Arithmetic Routines |
3 |
|
|
* by Tom Epperly |
4 |
|
|
* Version: $Revision: 1.6 $ |
5 |
|
|
* Version control file: $RCSfile: rounded.h,v $ |
6 |
|
|
* Date last modified: $Date: 1997/07/30 12:16:59 $ |
7 |
|
|
* Last modified by: $Author: mthomas $ |
8 |
|
|
* 6/28/89 |
9 |
|
|
* |
10 |
|
|
* This file is part of the Ascend Language Interpreter. |
11 |
|
|
* |
12 |
|
|
* Copyright (C) 1990, 1993, 1994 Thomas Guthrie Epperly |
13 |
|
|
* |
14 |
|
|
* The Ascend Language Interpreter is free software; you can redistribute |
15 |
|
|
* it and/or modify it under the terms of the GNU General Public License as |
16 |
|
|
* published by the Free Software Foundation; either version 2 of the |
17 |
|
|
* License, or (at your option) any later version. |
18 |
|
|
* |
19 |
|
|
* The Ascend Language Interpreter is distributed in hope that it will be |
20 |
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
21 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
22 |
|
|
* General Public License for more details. |
23 |
|
|
* |
24 |
|
|
* You should have received a copy of the GNU General Public License along |
25 |
|
|
* with the program; if not, write to the Free Software Foundation, Inc., 675 |
26 |
|
|
* Mass Ave, Cambridge, MA 02139 USA. Check the file named COPYING. |
27 |
|
|
*/ |
28 |
|
|
|
29 |
jds |
54 |
/** @file |
30 |
|
|
* Rounded Arithmetic Routines. |
31 |
|
|
* <pre> |
32 |
|
|
* When #including rounded.h, make sure these files are #included first: |
33 |
|
|
* #include "utilities/ascConfig.h" |
34 |
|
|
* </pre> |
35 |
|
|
*/ |
36 |
|
|
|
37 |
johnpye |
385 |
#ifndef ASC_ROUNDED_H |
38 |
|
|
#define ASC_ROUNDED_H |
39 |
aw0a |
1 |
|
40 |
johnpye |
1066 |
/** addtogroup compiler Compiler |
41 |
|
|
@{ |
42 |
|
|
*/ |
43 |
|
|
|
44 |
aw0a |
1 |
extern double DIPow(register double d, long int n); |
45 |
ben.allan |
33 |
/**< |
46 |
jds |
54 |
* <!-- double DIPow(d,n) --> |
47 |
|
|
* <!-- double d; --> |
48 |
|
|
* <!-- long n; --> |
49 |
aw0a |
1 |
* Return d^n rounded downward. |
50 |
|
|
*/ |
51 |
|
|
|
52 |
|
|
extern double UIPow(register double d, long int n); |
53 |
ben.allan |
33 |
/**< |
54 |
jds |
54 |
* <!-- double UIPow(d,n) --> |
55 |
|
|
* <!-- double d; --> |
56 |
|
|
* <!-- long n; --> |
57 |
aw0a |
1 |
* Return d^n rounded upward. |
58 |
|
|
*/ |
59 |
|
|
|
60 |
|
|
#ifndef SLOPPY |
61 |
|
|
extern double DPow(register double d1, register double d2); |
62 |
ben.allan |
33 |
/**< |
63 |
jds |
54 |
* <!-- double DPow(d1,d2) --> |
64 |
|
|
* <!-- double d1,d2; --> |
65 |
aw0a |
1 |
* Return the downward rounded result of d1^d2(d1 raised to the power d2). |
66 |
|
|
*/ |
67 |
|
|
|
68 |
|
|
extern double UPow(register double d1, register double d2); |
69 |
ben.allan |
33 |
/**< |
70 |
jds |
54 |
* <!-- double UPow(d1,d2) --> |
71 |
|
|
* <!-- double d1,d2; --> |
72 |
aw0a |
1 |
* Return the downward rounded result of d1^d2(d1 raised to the power d2). |
73 |
|
|
*/ |
74 |
|
|
|
75 |
|
|
extern double DPlus(register double d1, register double d2); |
76 |
ben.allan |
33 |
/**< |
77 |
jds |
54 |
* <!-- double DPlus(d1,d2) --> |
78 |
|
|
* <!-- double d1,d2; --> |
79 |
aw0a |
1 |
* Return the downward rounded addition of d1 and d2. |
80 |
|
|
*/ |
81 |
|
|
|
82 |
|
|
extern double UPlus(register double d1, register double d2); |
83 |
ben.allan |
33 |
/**< |
84 |
jds |
54 |
* <!-- double UPlus(d1,d2) --> |
85 |
|
|
* <!-- double d1,d2; --> |
86 |
aw0a |
1 |
* Return the upward rounded addition of d1 and d2. |
87 |
|
|
*/ |
88 |
|
|
|
89 |
|
|
extern double DMinus(register double d1, register double d2); |
90 |
ben.allan |
33 |
/**< |
91 |
jds |
54 |
* <!-- double DMinus(d1,d2) --> |
92 |
|
|
* <!-- double d1,d2; --> |
93 |
aw0a |
1 |
* Return d1-d2 with downward rounding. |
94 |
|
|
*/ |
95 |
|
|
|
96 |
|
|
extern double UMinus(register double d1, register double d2); |
97 |
ben.allan |
33 |
/**< |
98 |
jds |
54 |
* <!-- double UMinus(d1,d2) --> |
99 |
|
|
* <!-- double d1,d2; --> |
100 |
aw0a |
1 |
* Return d1-d2 with upward rounding. |
101 |
|
|
*/ |
102 |
|
|
|
103 |
|
|
extern double DTimes(register double d1, register double d2); |
104 |
ben.allan |
33 |
/**< |
105 |
jds |
54 |
* <!-- double DTimes(d1,d2) --> |
106 |
|
|
* <!-- double d1,d2; --> |
107 |
|
|
* Return d1*d2 with downward rounding. |
108 |
aw0a |
1 |
*/ |
109 |
|
|
|
110 |
|
|
extern double UTimes(register double d1, register double d2); |
111 |
ben.allan |
33 |
/**< |
112 |
jds |
54 |
* <!-- double UTimes(d1,d2) --> |
113 |
|
|
* <!-- double d1,d2; --> |
114 |
|
|
* Return d1*d2 with upward rounding. |
115 |
aw0a |
1 |
*/ |
116 |
|
|
|
117 |
|
|
extern double DDivide(register double d1, register double d2); |
118 |
ben.allan |
33 |
/**< |
119 |
jds |
54 |
* <!-- double DDivide(d1,d2); --> |
120 |
|
|
* <!-- double d1,d2; --> |
121 |
|
|
* Return d1/d2 with downward rounding. |
122 |
aw0a |
1 |
*/ |
123 |
|
|
|
124 |
|
|
extern double UDivide(register double d1, register double d2); |
125 |
ben.allan |
33 |
/**< |
126 |
jds |
54 |
* <!-- double UDivide(d1,d2); --> |
127 |
|
|
* <!-- double d1,d2; --> |
128 |
|
|
* Return d1/d2 with upward rounding. |
129 |
aw0a |
1 |
*/ |
130 |
|
|
|
131 |
|
|
extern double DSqr(register double d); |
132 |
ben.allan |
33 |
/**< |
133 |
jds |
54 |
* <!-- double DSqr(d) --> |
134 |
|
|
* <!-- double d; --> |
135 |
|
|
* Return sqr(d) with downward rounding. |
136 |
aw0a |
1 |
*/ |
137 |
|
|
|
138 |
|
|
extern double USqr(register double d); |
139 |
ben.allan |
33 |
/**< |
140 |
jds |
54 |
* <!-- double USqr(d) --> |
141 |
|
|
* <!-- double d; --> |
142 |
|
|
* Return sqr(d) with upward rounding. |
143 |
aw0a |
1 |
*/ |
144 |
|
|
|
145 |
|
|
extern double DSqrt(register double d); |
146 |
ben.allan |
33 |
/**< |
147 |
jds |
54 |
* <!-- double DSqrt(d); --> |
148 |
|
|
* <!-- double d; --> |
149 |
|
|
* Return sqrt(d) with downward rounding. |
150 |
aw0a |
1 |
*/ |
151 |
|
|
|
152 |
|
|
extern double USqrt(register double d); |
153 |
ben.allan |
33 |
/**< |
154 |
jds |
54 |
* <!-- double USqrt(d) --> |
155 |
|
|
* <!-- double d; --> |
156 |
|
|
* Return sqrt(d) with upward rounding. |
157 |
aw0a |
1 |
*/ |
158 |
|
|
|
159 |
|
|
extern double DExp(register double d); |
160 |
ben.allan |
33 |
/**< |
161 |
jds |
54 |
* <!-- double DExp(d) --> |
162 |
|
|
* <!-- double d; --> |
163 |
|
|
* Return exp(d) with downward rounding. |
164 |
aw0a |
1 |
*/ |
165 |
|
|
|
166 |
|
|
extern double UExp(register double d); |
167 |
ben.allan |
33 |
/**< |
168 |
jds |
54 |
* <!-- double UExp(d) --> |
169 |
|
|
* <!-- double d; --> |
170 |
|
|
* Return exp(d) with upward rounding. |
171 |
aw0a |
1 |
*/ |
172 |
|
|
|
173 |
|
|
extern double DLog(register double d); |
174 |
ben.allan |
33 |
/**< |
175 |
jds |
54 |
* <!-- double DLog(d) --> |
176 |
|
|
* <!-- double d; --> |
177 |
|
|
* Return log base 10 of d rounded down. |
178 |
aw0a |
1 |
*/ |
179 |
|
|
|
180 |
|
|
extern double ULog(register double d); |
181 |
ben.allan |
33 |
/**< |
182 |
jds |
54 |
* <!-- double ULog(d) --> |
183 |
|
|
* <!-- double d; --> |
184 |
|
|
* Return the log base 10 of d. |
185 |
aw0a |
1 |
*/ |
186 |
|
|
|
187 |
|
|
extern double DLn(register double d); |
188 |
ben.allan |
33 |
/**< |
189 |
jds |
54 |
* <!-- double DLn(d) --> |
190 |
|
|
* <!-- double d; --> |
191 |
|
|
* Return ln(d) (log base e) with downward rounding. |
192 |
aw0a |
1 |
*/ |
193 |
|
|
|
194 |
|
|
extern double ULn(register double d); |
195 |
ben.allan |
33 |
/**< |
196 |
jds |
54 |
* <!-- double ULn(d) --> |
197 |
|
|
* <!-- double d; --> |
198 |
|
|
* Return ln(d) with upward rounding. |
199 |
aw0a |
1 |
*/ |
200 |
|
|
|
201 |
|
|
#ifdef HAVE_ERF |
202 |
|
|
extern double DErf(register double d); |
203 |
ben.allan |
33 |
/**< |
204 |
jds |
54 |
* <!-- double DErf(d) --> |
205 |
|
|
* <!-- double d; --> |
206 |
|
|
* Return erf(d) with downward rounding. |
207 |
aw0a |
1 |
*/ |
208 |
|
|
|
209 |
|
|
extern double UErf(register double d); |
210 |
ben.allan |
33 |
/**< |
211 |
jds |
54 |
* <!-- double UErf(d) --> |
212 |
|
|
* <!-- double d; --> |
213 |
|
|
* Return erf(d) with upward rounding. |
214 |
aw0a |
1 |
*/ |
215 |
jds |
54 |
#endif /* HAVE_ERF */ |
216 |
aw0a |
1 |
|
217 |
|
|
extern double Dltod(long int l); |
218 |
ben.allan |
33 |
/**< |
219 |
jds |
54 |
* <!-- double Dltod(l) --> |
220 |
|
|
* <!-- long l; --> |
221 |
|
|
* Convert long to double with downward rounding. |
222 |
aw0a |
1 |
*/ |
223 |
|
|
|
224 |
|
|
extern double Ultod(long int l); |
225 |
jds |
54 |
/**< |
226 |
|
|
* <!-- double Ultod(l); --> |
227 |
|
|
* <!-- long l --> |
228 |
|
|
* Convert long to double with upward rounding. |
229 |
aw0a |
1 |
*/ |
230 |
jds |
54 |
|
231 |
|
|
#else /* SLOPPY */ |
232 |
aw0a |
1 |
#define Dltod(l) ((double)l) |
233 |
|
|
#define Ultod(l) ((double)l) |
234 |
|
|
#define DPlus(d1,d2) ((d1)+(d2)) |
235 |
|
|
#define UPlus(d1,d2) ((d1)+(d2)) |
236 |
|
|
#define DMinus(d1,d2) ((d1)-(d2)) |
237 |
|
|
#define UMinus(d1,d2) ((d1)-(d2)) |
238 |
|
|
#define DTimes(d1,d2) ((d1)*(d2)) |
239 |
|
|
#define UTimes(d1,d2) ((d1)*(d2)) |
240 |
|
|
#define DDivide(d1,d2) ((d1)/(d2)) |
241 |
|
|
#define UDivide(d1,d2) ((d1)/(d2)) |
242 |
|
|
#define DSqr(d) ((d)*(d)) |
243 |
|
|
#define USqr(d) ((d)*(d)) |
244 |
|
|
#define DSqrt(d) (sqrt(d)) |
245 |
|
|
#define USqrt(d) (sqrt(d)) |
246 |
|
|
#define DExp(d) (exp(d)) |
247 |
|
|
#define UExp(d) (exp(d)) |
248 |
|
|
#define DLn(d) (log(d)) |
249 |
|
|
#define ULn(d) (log(d)) |
250 |
|
|
#define DLog(d) (log10(d)) |
251 |
|
|
#define ULog(d) (log10(d)) |
252 |
|
|
#ifdef HAVE_ERF |
253 |
|
|
#define DErf(d) (erf(d)) |
254 |
|
|
#define UErf(d) (erf(d)) |
255 |
jds |
54 |
#endif /* HAVE_ERF */ |
256 |
aw0a |
1 |
#define DPow(d1,d2) (pow(d1,d2)) |
257 |
|
|
#define UPow(d1,d2) (pow(d1,d2)) |
258 |
jds |
54 |
#endif /* SLOPPY */ |
259 |
aw0a |
1 |
|
260 |
johnpye |
1066 |
/* @} */ |
261 |
|
|
|
262 |
johnpye |
385 |
#endif /* ASC_ROUNDED_H */ |
263 |
jds |
54 |
|