|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // LMATH.CPP - Wrappers for Epoc32 Math functions |
|
15 // |
|
16 // |
|
17 |
|
18 |
|
19 #include <e32math.h> |
|
20 #include "FDLIBM.H" |
|
21 #include <errno.h> |
|
22 |
|
23 extern "C" { |
|
24 |
|
25 /** |
|
26 * Map the Symbian error value to the standard error number and put it into errno. |
|
27 * @internalComponent |
|
28 * @param aSymbianReturnValue the standard return value returned from the Symbian function. |
|
29 * @param aNan the result of Math::Nan |
|
30 */ |
|
31 void MapSymbianErrorCodeToErrno(int aSymbianReturnValue, int aNan) |
|
32 { |
|
33 |
|
34 switch(aSymbianReturnValue) |
|
35 { |
|
36 case (KErrNone): |
|
37 { |
|
38 //errno does not get set to 0 according to the standard. |
|
39 //The user must initialize it before calling the function. |
|
40 break; |
|
41 } |
|
42 case (KErrArgument): |
|
43 { |
|
44 if (aNan) |
|
45 errno = EDOM; |
|
46 else |
|
47 errno = EINVAL; |
|
48 break; |
|
49 } |
|
50 case (KErrOverflow): |
|
51 case (KErrUnderflow): |
|
52 case (KErrTotalLossOfPrecision): |
|
53 { |
|
54 errno = ERANGE; |
|
55 break; |
|
56 } |
|
57 } |
|
58 |
|
59 } |
|
60 |
|
61 /** |
|
62 Calculate arctangent. |
|
63 Performs the trigonometric arctangent operation on x and returns an angle in the range from -PI/2 to PI/2 expressed in radians. |
|
64 @return Arctangent of arg1. |
|
65 @param arg1 Value whose arctangent has to be calculated. |
|
66 */ |
|
67 EXPORT_C double atan (double arg1) __SOFTFP |
|
68 { |
|
69 double result; |
|
70 int returnValue; |
|
71 |
|
72 returnValue = Math::ATan(result, arg1); |
|
73 MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); |
|
74 |
|
75 return result; |
|
76 } |
|
77 |
|
78 /** |
|
79 Calculate cosine. |
|
80 Performs the trigonometric cosine operation on x returning a value between -1 and 1. |
|
81 @return Cosine of arg1. |
|
82 @param arg1 Angle expressed in radians (180 degrees = PI radians). |
|
83 */ |
|
84 EXPORT_C double cos (double arg1) __SOFTFP |
|
85 { |
|
86 double result; |
|
87 int returnValue; |
|
88 |
|
89 returnValue = Math::Cos(result, arg1); |
|
90 MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); |
|
91 |
|
92 return result; |
|
93 } |
|
94 |
|
95 /** |
|
96 Calculate sine. |
|
97 Performs the trigonometric sine operation on x returning a value between -1 and 1. |
|
98 @return Sine of arg1. |
|
99 @param arg1 Angle expressed in radians (180 degrees = PI radians). |
|
100 */ |
|
101 EXPORT_C double sin (double arg1) __SOFTFP |
|
102 { |
|
103 double result; |
|
104 int returnValue; |
|
105 |
|
106 returnValue = Math::Sin(result, arg1); |
|
107 MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); |
|
108 |
|
109 return result; |
|
110 } |
|
111 |
|
112 /** |
|
113 Calculate tangent. |
|
114 Performs the trigonometric tangent operation on arg1. |
|
115 @return Tangent of arg1. |
|
116 @param arg1 Angle expressed in radians (180 degrees = PI radians). |
|
117 */ |
|
118 EXPORT_C double tan (double arg1) __SOFTFP |
|
119 { |
|
120 double result; |
|
121 int returnValue; |
|
122 |
|
123 returnValue = Math::Tan(result, arg1); |
|
124 MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); |
|
125 |
|
126 return result; |
|
127 } |
|
128 |
|
129 /** |
|
130 Calculate arccosine. |
|
131 Performs the trigonometric arc cosine operation on x and returns an angle in the range from 0 to PI expressed in radians. |
|
132 @return Arc cosine of arg1. |
|
133 @param arg1 Value between -1 and 1 whose arc cosine has to be calculated. |
|
134 */ |
|
135 EXPORT_C double acos (double arg1) __SOFTFP |
|
136 { |
|
137 double result; |
|
138 int returnValue; |
|
139 |
|
140 returnValue = Math::ACos(result, arg1); |
|
141 MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); |
|
142 |
|
143 return result; |
|
144 } |
|
145 |
|
146 /** |
|
147 Calculate arcsine. |
|
148 Performs the trigonometric arc sine operation on x and returns an angle in the range from -PI/2 to PI/2 expressed in radians. |
|
149 @return Arc sine of arg1 |
|
150 @param arg1 Value between -1 and 1 whose arc sine has to be calculated. |
|
151 */ |
|
152 EXPORT_C double asin (double arg1) __SOFTFP |
|
153 { |
|
154 double result; |
|
155 int returnValue; |
|
156 |
|
157 returnValue = Math::ASin(result, arg1); |
|
158 MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); |
|
159 |
|
160 return result; |
|
161 } |
|
162 |
|
163 /** |
|
164 Calculate exponential. |
|
165 Returns the exponential value of parameter arg1. |
|
166 @return Exponential of arg1 |
|
167 @param arg1 Floating point value. |
|
168 */ |
|
169 EXPORT_C double exp (double arg1) __SOFTFP |
|
170 { |
|
171 double result; |
|
172 int returnValue; |
|
173 |
|
174 returnValue = Math::Exp(result, arg1); |
|
175 MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); |
|
176 |
|
177 return result; |
|
178 } |
|
179 |
|
180 /** |
|
181 Calculate natural logarithm. |
|
182 Returns the natural logarithm of parameter arg1 |
|
183 @return Logarithm of arg1. |
|
184 @param arg1 Floating point value. |
|
185 */ |
|
186 EXPORT_C double log (double arg1) __SOFTFP |
|
187 { |
|
188 double result; |
|
189 int returnValue; |
|
190 |
|
191 returnValue = Math::Ln(result, arg1); |
|
192 MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); |
|
193 |
|
194 return result; |
|
195 } |
|
196 |
|
197 /** |
|
198 Calculate logarithm base 10. |
|
199 Returns the logarithm base 10 of parameter arg1 |
|
200 @return Logarithm base 10 of arg1 |
|
201 @param arg1 Floating point value. |
|
202 */ |
|
203 EXPORT_C double log10 (double arg1) __SOFTFP |
|
204 { |
|
205 double result; |
|
206 int returnValue; |
|
207 |
|
208 returnValue = Math::Log(result, arg1); |
|
209 MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); |
|
210 |
|
211 return result; |
|
212 } |
|
213 |
|
214 /** |
|
215 Calculate square root. |
|
216 Returns the square root of parameter arg1. |
|
217 @return Square root of arg1 |
|
218 @param arg1 Non-negative floating point value. |
|
219 */ |
|
220 EXPORT_C double sqrt (double arg1) __SOFTFP |
|
221 { |
|
222 double result; |
|
223 int returnValue; |
|
224 |
|
225 returnValue = Math::Sqrt(result, arg1); |
|
226 MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); |
|
227 |
|
228 return result; |
|
229 } |
|
230 |
|
231 /** |
|
232 Calculate arctangent, 2 parameters. |
|
233 Performs the trigonometric arctangent operation on y/x and returns an angle in the range from -PI to PI expressed in radians, using the signs of the parameters to determine the quadrant. |
|
234 The result is valid even if arg2 is 0 (angle is PI/2 or -PI/2). |
|
235 In fact this function returns the angle of bidimensional vector (arg2,arg1). |
|
236 @return Arctangent of arg1/arg2. |
|
237 @param arg1 and arg2.Values from whose division has to be calculated the arctangent.i.e.: Coordinates for the vector whose angle is to be calculated. |
|
238 */ |
|
239 EXPORT_C double atan2 (double arg1, double arg2) __SOFTFP |
|
240 { |
|
241 double result; |
|
242 int returnValue; |
|
243 |
|
244 returnValue = Math::ATan(result, arg1, arg2); |
|
245 MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); |
|
246 |
|
247 return result; |
|
248 } |
|
249 |
|
250 /** |
|
251 Calculate numeric power. |
|
252 Returns arg1 raised to the power of arg2. |
|
253 @return arg1 raised to the power of arg2. |
|
254 @param arg1 - Base value. |
|
255 @param arg2 - Exponent value. |
|
256 */ |
|
257 EXPORT_C double pow (double arg1, double arg2) __SOFTFP |
|
258 { |
|
259 double result; |
|
260 int returnValue; |
|
261 |
|
262 returnValue = Math::Pow(result, arg1, arg2); |
|
263 MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); |
|
264 |
|
265 return result; |
|
266 } |
|
267 |
|
268 /** |
|
269 Return remainder of floating point division. |
|
270 Performs division arg1/arg2 and returns the remainder of the operation. |
|
271 @return Remainder of arg1/arg2. |
|
272 @param arg1 and arg2 - Floating point values |
|
273 */ |
|
274 EXPORT_C double fmod (double arg1, double arg2) __SOFTFP |
|
275 { |
|
276 double result; |
|
277 int returnValue; |
|
278 |
|
279 returnValue = Math::Mod(result, arg1, arg2); |
|
280 MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); |
|
281 |
|
282 return result; |
|
283 } |
|
284 |
|
285 /** |
|
286 Round to integral value in floating-point format |
|
287 @return the integral value (represented as a double precision number) nearest to arg1 according to the prevailing rounding mode. |
|
288 @param arg1 floating point value to round. |
|
289 */ |
|
290 EXPORT_C double rint (double arg1) __SOFTFP |
|
291 { |
|
292 double result; |
|
293 int returnValue; |
|
294 |
|
295 returnValue = Math::Round(result, arg1, 0); |
|
296 MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); |
|
297 |
|
298 return result; |
|
299 } |
|
300 |
|
301 /** |
|
302 tests whether d is NaN |
|
303 @return non-zero if d is NaN. Otherwise, 0 is returned. |
|
304 @param d floating point value. |
|
305 */ |
|
306 EXPORT_C int isnan (double d) __SOFTFP |
|
307 { |
|
308 return Math::IsNaN(d); |
|
309 } |
|
310 |
|
311 /** |
|
312 test for infinity or not-a-number |
|
313 @return 1 if the number d is Infinity, otherwise 0. |
|
314 @param d floating point value to test. |
|
315 */ |
|
316 EXPORT_C int isinf (double d) __SOFTFP |
|
317 { |
|
318 return Math::IsInfinite(d); |
|
319 } |
|
320 |
|
321 /** |
|
322 Test for finity. |
|
323 @return a nonzero value if the x parameter is a finite number; |
|
324 that is, if d is not +-, INF, NaNQ, or NaNS. |
|
325 @param d floating point value to test. |
|
326 */ |
|
327 EXPORT_C int finite (double d) __SOFTFP |
|
328 { |
|
329 return Math::IsFinite(d); |
|
330 } |
|
331 |
|
332 } // end of extern "C" |
|
333 |
|
334 |
|
335 |