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