1 |
/* |
2 |
* 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 |
/** @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 |
#ifndef ASC_ROUNDED_H |
38 |
#define ASC_ROUNDED_H |
39 |
|
40 |
extern double DIPow(register double d, long int n); |
41 |
/**< |
42 |
* <!-- double DIPow(d,n) --> |
43 |
* <!-- double d; --> |
44 |
* <!-- long n; --> |
45 |
* Return d^n rounded downward. |
46 |
*/ |
47 |
|
48 |
extern double UIPow(register double d, long int n); |
49 |
/**< |
50 |
* <!-- double UIPow(d,n) --> |
51 |
* <!-- double d; --> |
52 |
* <!-- long n; --> |
53 |
* Return d^n rounded upward. |
54 |
*/ |
55 |
|
56 |
#ifndef SLOPPY |
57 |
extern double DPow(register double d1, register double d2); |
58 |
/**< |
59 |
* <!-- double DPow(d1,d2) --> |
60 |
* <!-- double d1,d2; --> |
61 |
* Return the downward rounded result of d1^d2(d1 raised to the power d2). |
62 |
*/ |
63 |
|
64 |
extern double UPow(register double d1, register double d2); |
65 |
/**< |
66 |
* <!-- double UPow(d1,d2) --> |
67 |
* <!-- double d1,d2; --> |
68 |
* Return the downward rounded result of d1^d2(d1 raised to the power d2). |
69 |
*/ |
70 |
|
71 |
extern double DPlus(register double d1, register double d2); |
72 |
/**< |
73 |
* <!-- double DPlus(d1,d2) --> |
74 |
* <!-- double d1,d2; --> |
75 |
* Return the downward rounded addition of d1 and d2. |
76 |
*/ |
77 |
|
78 |
extern double UPlus(register double d1, register double d2); |
79 |
/**< |
80 |
* <!-- double UPlus(d1,d2) --> |
81 |
* <!-- double d1,d2; --> |
82 |
* Return the upward rounded addition of d1 and d2. |
83 |
*/ |
84 |
|
85 |
extern double DMinus(register double d1, register double d2); |
86 |
/**< |
87 |
* <!-- double DMinus(d1,d2) --> |
88 |
* <!-- double d1,d2; --> |
89 |
* Return d1-d2 with downward rounding. |
90 |
*/ |
91 |
|
92 |
extern double UMinus(register double d1, register double d2); |
93 |
/**< |
94 |
* <!-- double UMinus(d1,d2) --> |
95 |
* <!-- double d1,d2; --> |
96 |
* Return d1-d2 with upward rounding. |
97 |
*/ |
98 |
|
99 |
extern double DTimes(register double d1, register double d2); |
100 |
/**< |
101 |
* <!-- double DTimes(d1,d2) --> |
102 |
* <!-- double d1,d2; --> |
103 |
* Return d1*d2 with downward rounding. |
104 |
*/ |
105 |
|
106 |
extern double UTimes(register double d1, register double d2); |
107 |
/**< |
108 |
* <!-- double UTimes(d1,d2) --> |
109 |
* <!-- double d1,d2; --> |
110 |
* Return d1*d2 with upward rounding. |
111 |
*/ |
112 |
|
113 |
extern double DDivide(register double d1, register double d2); |
114 |
/**< |
115 |
* <!-- double DDivide(d1,d2); --> |
116 |
* <!-- double d1,d2; --> |
117 |
* Return d1/d2 with downward rounding. |
118 |
*/ |
119 |
|
120 |
extern double UDivide(register double d1, register double d2); |
121 |
/**< |
122 |
* <!-- double UDivide(d1,d2); --> |
123 |
* <!-- double d1,d2; --> |
124 |
* Return d1/d2 with upward rounding. |
125 |
*/ |
126 |
|
127 |
extern double DSqr(register double d); |
128 |
/**< |
129 |
* <!-- double DSqr(d) --> |
130 |
* <!-- double d; --> |
131 |
* Return sqr(d) with downward rounding. |
132 |
*/ |
133 |
|
134 |
extern double USqr(register double d); |
135 |
/**< |
136 |
* <!-- double USqr(d) --> |
137 |
* <!-- double d; --> |
138 |
* Return sqr(d) with upward rounding. |
139 |
*/ |
140 |
|
141 |
extern double DSqrt(register double d); |
142 |
/**< |
143 |
* <!-- double DSqrt(d); --> |
144 |
* <!-- double d; --> |
145 |
* Return sqrt(d) with downward rounding. |
146 |
*/ |
147 |
|
148 |
extern double USqrt(register double d); |
149 |
/**< |
150 |
* <!-- double USqrt(d) --> |
151 |
* <!-- double d; --> |
152 |
* Return sqrt(d) with upward rounding. |
153 |
*/ |
154 |
|
155 |
extern double DExp(register double d); |
156 |
/**< |
157 |
* <!-- double DExp(d) --> |
158 |
* <!-- double d; --> |
159 |
* Return exp(d) with downward rounding. |
160 |
*/ |
161 |
|
162 |
extern double UExp(register double d); |
163 |
/**< |
164 |
* <!-- double UExp(d) --> |
165 |
* <!-- double d; --> |
166 |
* Return exp(d) with upward rounding. |
167 |
*/ |
168 |
|
169 |
extern double DLog(register double d); |
170 |
/**< |
171 |
* <!-- double DLog(d) --> |
172 |
* <!-- double d; --> |
173 |
* Return log base 10 of d rounded down. |
174 |
*/ |
175 |
|
176 |
extern double ULog(register double d); |
177 |
/**< |
178 |
* <!-- double ULog(d) --> |
179 |
* <!-- double d; --> |
180 |
* Return the log base 10 of d. |
181 |
*/ |
182 |
|
183 |
extern double DLn(register double d); |
184 |
/**< |
185 |
* <!-- double DLn(d) --> |
186 |
* <!-- double d; --> |
187 |
* Return ln(d) (log base e) with downward rounding. |
188 |
*/ |
189 |
|
190 |
extern double ULn(register double d); |
191 |
/**< |
192 |
* <!-- double ULn(d) --> |
193 |
* <!-- double d; --> |
194 |
* Return ln(d) with upward rounding. |
195 |
*/ |
196 |
|
197 |
#ifdef HAVE_ERF |
198 |
extern double DErf(register double d); |
199 |
/**< |
200 |
* <!-- double DErf(d) --> |
201 |
* <!-- double d; --> |
202 |
* Return erf(d) with downward rounding. |
203 |
*/ |
204 |
|
205 |
extern double UErf(register double d); |
206 |
/**< |
207 |
* <!-- double UErf(d) --> |
208 |
* <!-- double d; --> |
209 |
* Return erf(d) with upward rounding. |
210 |
*/ |
211 |
#endif /* HAVE_ERF */ |
212 |
|
213 |
extern double Dltod(long int l); |
214 |
/**< |
215 |
* <!-- double Dltod(l) --> |
216 |
* <!-- long l; --> |
217 |
* Convert long to double with downward rounding. |
218 |
*/ |
219 |
|
220 |
extern double Ultod(long int l); |
221 |
/**< |
222 |
* <!-- double Ultod(l); --> |
223 |
* <!-- long l --> |
224 |
* Convert long to double with upward rounding. |
225 |
*/ |
226 |
|
227 |
#else /* SLOPPY */ |
228 |
#define Dltod(l) ((double)l) |
229 |
#define Ultod(l) ((double)l) |
230 |
#define DPlus(d1,d2) ((d1)+(d2)) |
231 |
#define UPlus(d1,d2) ((d1)+(d2)) |
232 |
#define DMinus(d1,d2) ((d1)-(d2)) |
233 |
#define UMinus(d1,d2) ((d1)-(d2)) |
234 |
#define DTimes(d1,d2) ((d1)*(d2)) |
235 |
#define UTimes(d1,d2) ((d1)*(d2)) |
236 |
#define DDivide(d1,d2) ((d1)/(d2)) |
237 |
#define UDivide(d1,d2) ((d1)/(d2)) |
238 |
#define DSqr(d) ((d)*(d)) |
239 |
#define USqr(d) ((d)*(d)) |
240 |
#define DSqrt(d) (sqrt(d)) |
241 |
#define USqrt(d) (sqrt(d)) |
242 |
#define DExp(d) (exp(d)) |
243 |
#define UExp(d) (exp(d)) |
244 |
#define DLn(d) (log(d)) |
245 |
#define ULn(d) (log(d)) |
246 |
#define DLog(d) (log10(d)) |
247 |
#define ULog(d) (log10(d)) |
248 |
#ifdef HAVE_ERF |
249 |
#define DErf(d) (erf(d)) |
250 |
#define UErf(d) (erf(d)) |
251 |
#endif /* HAVE_ERF */ |
252 |
#define DPow(d1,d2) (pow(d1,d2)) |
253 |
#define UPow(d1,d2) (pow(d1,d2)) |
254 |
#endif /* SLOPPY */ |
255 |
|
256 |
#endif /* ASC_ROUNDED_H */ |
257 |
|