1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LMATH/LMATH.CPP Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,335 @@
1.4 +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +// LMATH.CPP - Wrappers for Epoc32 Math functions
1.18 +//
1.19 +//
1.20 +
1.21 +
1.22 +#include <e32math.h>
1.23 +#include "FDLIBM.H"
1.24 +#include <errno.h>
1.25 +
1.26 +extern "C" {
1.27 +
1.28 +/**
1.29 + * Map the Symbian error value to the standard error number and put it into errno.
1.30 + * @internalComponent
1.31 + * @param aSymbianReturnValue the standard return value returned from the Symbian function.
1.32 + * @param aNan the result of Math::Nan
1.33 + */
1.34 +void MapSymbianErrorCodeToErrno(int aSymbianReturnValue, int aNan)
1.35 +{
1.36 +
1.37 + switch(aSymbianReturnValue)
1.38 + {
1.39 + case (KErrNone):
1.40 + {
1.41 + //errno does not get set to 0 according to the standard.
1.42 + //The user must initialize it before calling the function.
1.43 + break;
1.44 + }
1.45 + case (KErrArgument):
1.46 + {
1.47 + if (aNan)
1.48 + errno = EDOM;
1.49 + else
1.50 + errno = EINVAL;
1.51 + break;
1.52 + }
1.53 + case (KErrOverflow):
1.54 + case (KErrUnderflow):
1.55 + case (KErrTotalLossOfPrecision):
1.56 + {
1.57 + errno = ERANGE;
1.58 + break;
1.59 + }
1.60 + }
1.61 +
1.62 +}
1.63 +
1.64 +/**
1.65 +Calculate arctangent.
1.66 +Performs the trigonometric arctangent operation on x and returns an angle in the range from -PI/2 to PI/2 expressed in radians.
1.67 +@return Arctangent of arg1.
1.68 +@param arg1 Value whose arctangent has to be calculated.
1.69 +*/
1.70 +EXPORT_C double atan (double arg1) __SOFTFP
1.71 + {
1.72 + double result;
1.73 + int returnValue;
1.74 +
1.75 + returnValue = Math::ATan(result, arg1);
1.76 + MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result));
1.77 +
1.78 + return result;
1.79 + }
1.80 +
1.81 +/**
1.82 +Calculate cosine.
1.83 +Performs the trigonometric cosine operation on x returning a value between -1 and 1.
1.84 +@return Cosine of arg1.
1.85 +@param arg1 Angle expressed in radians (180 degrees = PI radians).
1.86 +*/
1.87 +EXPORT_C double cos (double arg1) __SOFTFP
1.88 + {
1.89 + double result;
1.90 + int returnValue;
1.91 +
1.92 + returnValue = Math::Cos(result, arg1);
1.93 + MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result));
1.94 +
1.95 + return result;
1.96 + }
1.97 +
1.98 +/**
1.99 +Calculate sine.
1.100 +Performs the trigonometric sine operation on x returning a value between -1 and 1.
1.101 +@return Sine of arg1.
1.102 +@param arg1 Angle expressed in radians (180 degrees = PI radians).
1.103 +*/
1.104 +EXPORT_C double sin (double arg1) __SOFTFP
1.105 + {
1.106 + double result;
1.107 + int returnValue;
1.108 +
1.109 + returnValue = Math::Sin(result, arg1);
1.110 + MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result));
1.111 +
1.112 + return result;
1.113 + }
1.114 +
1.115 +/**
1.116 +Calculate tangent.
1.117 +Performs the trigonometric tangent operation on arg1.
1.118 +@return Tangent of arg1.
1.119 +@param arg1 Angle expressed in radians (180 degrees = PI radians).
1.120 +*/
1.121 +EXPORT_C double tan (double arg1) __SOFTFP
1.122 + {
1.123 + double result;
1.124 + int returnValue;
1.125 +
1.126 + returnValue = Math::Tan(result, arg1);
1.127 + MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result));
1.128 +
1.129 + return result;
1.130 + }
1.131 +
1.132 +/**
1.133 +Calculate arccosine.
1.134 +Performs the trigonometric arc cosine operation on x and returns an angle in the range from 0 to PI expressed in radians.
1.135 +@return Arc cosine of arg1.
1.136 +@param arg1 Value between -1 and 1 whose arc cosine has to be calculated.
1.137 +*/
1.138 +EXPORT_C double acos (double arg1) __SOFTFP
1.139 + {
1.140 + double result;
1.141 + int returnValue;
1.142 +
1.143 + returnValue = Math::ACos(result, arg1);
1.144 + MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result));
1.145 +
1.146 + return result;
1.147 + }
1.148 +
1.149 +/**
1.150 +Calculate arcsine.
1.151 +Performs the trigonometric arc sine operation on x and returns an angle in the range from -PI/2 to PI/2 expressed in radians.
1.152 +@return Arc sine of arg1
1.153 +@param arg1 Value between -1 and 1 whose arc sine has to be calculated.
1.154 +*/
1.155 +EXPORT_C double asin (double arg1) __SOFTFP
1.156 + {
1.157 + double result;
1.158 + int returnValue;
1.159 +
1.160 + returnValue = Math::ASin(result, arg1);
1.161 + MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result));
1.162 +
1.163 + return result;
1.164 + }
1.165 +
1.166 +/**
1.167 +Calculate exponential.
1.168 +Returns the exponential value of parameter arg1.
1.169 +@return Exponential of arg1
1.170 +@param arg1 Floating point value.
1.171 +*/
1.172 +EXPORT_C double exp (double arg1) __SOFTFP
1.173 + {
1.174 + double result;
1.175 + int returnValue;
1.176 +
1.177 + returnValue = Math::Exp(result, arg1);
1.178 + MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result));
1.179 +
1.180 + return result;
1.181 + }
1.182 +
1.183 +/**
1.184 +Calculate natural logarithm.
1.185 +Returns the natural logarithm of parameter arg1
1.186 +@return Logarithm of arg1.
1.187 +@param arg1 Floating point value.
1.188 +*/
1.189 +EXPORT_C double log (double arg1) __SOFTFP
1.190 + {
1.191 + double result;
1.192 + int returnValue;
1.193 +
1.194 + returnValue = Math::Ln(result, arg1);
1.195 + MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result));
1.196 +
1.197 + return result;
1.198 + }
1.199 +
1.200 +/**
1.201 +Calculate logarithm base 10.
1.202 +Returns the logarithm base 10 of parameter arg1
1.203 +@return Logarithm base 10 of arg1
1.204 +@param arg1 Floating point value.
1.205 +*/
1.206 +EXPORT_C double log10 (double arg1) __SOFTFP
1.207 + {
1.208 + double result;
1.209 + int returnValue;
1.210 +
1.211 + returnValue = Math::Log(result, arg1);
1.212 + MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result));
1.213 +
1.214 + return result;
1.215 + }
1.216 +
1.217 +/**
1.218 +Calculate square root.
1.219 +Returns the square root of parameter arg1.
1.220 +@return Square root of arg1
1.221 +@param arg1 Non-negative floating point value.
1.222 +*/
1.223 +EXPORT_C double sqrt (double arg1) __SOFTFP
1.224 + {
1.225 + double result;
1.226 + int returnValue;
1.227 +
1.228 + returnValue = Math::Sqrt(result, arg1);
1.229 + MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result));
1.230 +
1.231 + return result;
1.232 + }
1.233 +
1.234 +/**
1.235 +Calculate arctangent, 2 parameters.
1.236 +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.
1.237 +The result is valid even if arg2 is 0 (angle is PI/2 or -PI/2).
1.238 +In fact this function returns the angle of bidimensional vector (arg2,arg1).
1.239 +@return Arctangent of arg1/arg2.
1.240 +@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.
1.241 +*/
1.242 +EXPORT_C double atan2 (double arg1, double arg2) __SOFTFP
1.243 + {
1.244 + double result;
1.245 + int returnValue;
1.246 +
1.247 + returnValue = Math::ATan(result, arg1, arg2);
1.248 + MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result));
1.249 +
1.250 + return result;
1.251 + }
1.252 +
1.253 +/**
1.254 +Calculate numeric power.
1.255 +Returns arg1 raised to the power of arg2.
1.256 +@return arg1 raised to the power of arg2.
1.257 +@param arg1 - Base value.
1.258 +@param arg2 - Exponent value.
1.259 +*/
1.260 +EXPORT_C double pow (double arg1, double arg2) __SOFTFP
1.261 + {
1.262 + double result;
1.263 + int returnValue;
1.264 +
1.265 + returnValue = Math::Pow(result, arg1, arg2);
1.266 + MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result));
1.267 +
1.268 + return result;
1.269 + }
1.270 +
1.271 +/**
1.272 +Return remainder of floating point division.
1.273 +Performs division arg1/arg2 and returns the remainder of the operation.
1.274 +@return Remainder of arg1/arg2.
1.275 +@param arg1 and arg2 - Floating point values
1.276 +*/
1.277 +EXPORT_C double fmod (double arg1, double arg2) __SOFTFP
1.278 + {
1.279 + double result;
1.280 + int returnValue;
1.281 +
1.282 + returnValue = Math::Mod(result, arg1, arg2);
1.283 + MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result));
1.284 +
1.285 + return result;
1.286 + }
1.287 +
1.288 +/**
1.289 +Round to integral value in floating-point format
1.290 +@return the integral value (represented as a double precision number) nearest to arg1 according to the prevailing rounding mode.
1.291 +@param arg1 floating point value to round.
1.292 +*/
1.293 +EXPORT_C double rint (double arg1) __SOFTFP
1.294 + {
1.295 + double result;
1.296 + int returnValue;
1.297 +
1.298 + returnValue = Math::Round(result, arg1, 0);
1.299 + MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result));
1.300 +
1.301 + return result;
1.302 + }
1.303 +
1.304 +/**
1.305 +tests whether d is NaN
1.306 +@return non-zero if d is NaN. Otherwise, 0 is returned.
1.307 +@param d floating point value.
1.308 +*/
1.309 +EXPORT_C int isnan (double d) __SOFTFP
1.310 + {
1.311 + return Math::IsNaN(d);
1.312 + }
1.313 +
1.314 +/**
1.315 +test for infinity or not-a-number
1.316 +@return 1 if the number d is Infinity, otherwise 0.
1.317 +@param d floating point value to test.
1.318 +*/
1.319 +EXPORT_C int isinf (double d) __SOFTFP
1.320 + {
1.321 + return Math::IsInfinite(d);
1.322 + }
1.323 +
1.324 +/**
1.325 +Test for finity.
1.326 +@return a nonzero value if the x parameter is a finite number;
1.327 +that is, if d is not +-, INF, NaNQ, or NaNS.
1.328 +@param d floating point value to test.
1.329 +*/
1.330 +EXPORT_C int finite (double d) __SOFTFP
1.331 + {
1.332 + return Math::IsFinite(d);
1.333 + }
1.334 +
1.335 +} // end of extern "C"
1.336 +
1.337 +
1.338 +