sl@0: // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // LMATH.CPP - Wrappers for Epoc32 Math functions sl@0: // sl@0: // sl@0: sl@0: sl@0: #include sl@0: #include "FDLIBM.H" sl@0: #include sl@0: sl@0: extern "C" { sl@0: sl@0: /** sl@0: * Map the Symbian error value to the standard error number and put it into errno. sl@0: * @internalComponent sl@0: * @param aSymbianReturnValue the standard return value returned from the Symbian function. sl@0: * @param aNan the result of Math::Nan sl@0: */ sl@0: void MapSymbianErrorCodeToErrno(int aSymbianReturnValue, int aNan) sl@0: { sl@0: sl@0: switch(aSymbianReturnValue) sl@0: { sl@0: case (KErrNone): sl@0: { sl@0: //errno does not get set to 0 according to the standard. sl@0: //The user must initialize it before calling the function. sl@0: break; sl@0: } sl@0: case (KErrArgument): sl@0: { sl@0: if (aNan) sl@0: errno = EDOM; sl@0: else sl@0: errno = EINVAL; sl@0: break; sl@0: } sl@0: case (KErrOverflow): sl@0: case (KErrUnderflow): sl@0: case (KErrTotalLossOfPrecision): sl@0: { sl@0: errno = ERANGE; sl@0: break; sl@0: } sl@0: } sl@0: sl@0: } sl@0: sl@0: /** sl@0: Calculate arctangent. sl@0: 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: @return Arctangent of arg1. sl@0: @param arg1 Value whose arctangent has to be calculated. sl@0: */ sl@0: EXPORT_C double atan (double arg1) __SOFTFP sl@0: { sl@0: double result; sl@0: int returnValue; sl@0: sl@0: returnValue = Math::ATan(result, arg1); sl@0: MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Calculate cosine. sl@0: Performs the trigonometric cosine operation on x returning a value between -1 and 1. sl@0: @return Cosine of arg1. sl@0: @param arg1 Angle expressed in radians (180 degrees = PI radians). sl@0: */ sl@0: EXPORT_C double cos (double arg1) __SOFTFP sl@0: { sl@0: double result; sl@0: int returnValue; sl@0: sl@0: returnValue = Math::Cos(result, arg1); sl@0: MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Calculate sine. sl@0: Performs the trigonometric sine operation on x returning a value between -1 and 1. sl@0: @return Sine of arg1. sl@0: @param arg1 Angle expressed in radians (180 degrees = PI radians). sl@0: */ sl@0: EXPORT_C double sin (double arg1) __SOFTFP sl@0: { sl@0: double result; sl@0: int returnValue; sl@0: sl@0: returnValue = Math::Sin(result, arg1); sl@0: MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Calculate tangent. sl@0: Performs the trigonometric tangent operation on arg1. sl@0: @return Tangent of arg1. sl@0: @param arg1 Angle expressed in radians (180 degrees = PI radians). sl@0: */ sl@0: EXPORT_C double tan (double arg1) __SOFTFP sl@0: { sl@0: double result; sl@0: int returnValue; sl@0: sl@0: returnValue = Math::Tan(result, arg1); sl@0: MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Calculate arccosine. sl@0: Performs the trigonometric arc cosine operation on x and returns an angle in the range from 0 to PI expressed in radians. sl@0: @return Arc cosine of arg1. sl@0: @param arg1 Value between -1 and 1 whose arc cosine has to be calculated. sl@0: */ sl@0: EXPORT_C double acos (double arg1) __SOFTFP sl@0: { sl@0: double result; sl@0: int returnValue; sl@0: sl@0: returnValue = Math::ACos(result, arg1); sl@0: MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Calculate arcsine. sl@0: 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: @return Arc sine of arg1 sl@0: @param arg1 Value between -1 and 1 whose arc sine has to be calculated. sl@0: */ sl@0: EXPORT_C double asin (double arg1) __SOFTFP sl@0: { sl@0: double result; sl@0: int returnValue; sl@0: sl@0: returnValue = Math::ASin(result, arg1); sl@0: MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Calculate exponential. sl@0: Returns the exponential value of parameter arg1. sl@0: @return Exponential of arg1 sl@0: @param arg1 Floating point value. sl@0: */ sl@0: EXPORT_C double exp (double arg1) __SOFTFP sl@0: { sl@0: double result; sl@0: int returnValue; sl@0: sl@0: returnValue = Math::Exp(result, arg1); sl@0: MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Calculate natural logarithm. sl@0: Returns the natural logarithm of parameter arg1 sl@0: @return Logarithm of arg1. sl@0: @param arg1 Floating point value. sl@0: */ sl@0: EXPORT_C double log (double arg1) __SOFTFP sl@0: { sl@0: double result; sl@0: int returnValue; sl@0: sl@0: returnValue = Math::Ln(result, arg1); sl@0: MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Calculate logarithm base 10. sl@0: Returns the logarithm base 10 of parameter arg1 sl@0: @return Logarithm base 10 of arg1 sl@0: @param arg1 Floating point value. sl@0: */ sl@0: EXPORT_C double log10 (double arg1) __SOFTFP sl@0: { sl@0: double result; sl@0: int returnValue; sl@0: sl@0: returnValue = Math::Log(result, arg1); sl@0: MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Calculate square root. sl@0: Returns the square root of parameter arg1. sl@0: @return Square root of arg1 sl@0: @param arg1 Non-negative floating point value. sl@0: */ sl@0: EXPORT_C double sqrt (double arg1) __SOFTFP sl@0: { sl@0: double result; sl@0: int returnValue; sl@0: sl@0: returnValue = Math::Sqrt(result, arg1); sl@0: MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Calculate arctangent, 2 parameters. sl@0: 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: The result is valid even if arg2 is 0 (angle is PI/2 or -PI/2). sl@0: In fact this function returns the angle of bidimensional vector (arg2,arg1). sl@0: @return Arctangent of arg1/arg2. sl@0: @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: */ sl@0: EXPORT_C double atan2 (double arg1, double arg2) __SOFTFP sl@0: { sl@0: double result; sl@0: int returnValue; sl@0: sl@0: returnValue = Math::ATan(result, arg1, arg2); sl@0: MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Calculate numeric power. sl@0: Returns arg1 raised to the power of arg2. sl@0: @return arg1 raised to the power of arg2. sl@0: @param arg1 - Base value. sl@0: @param arg2 - Exponent value. sl@0: */ sl@0: EXPORT_C double pow (double arg1, double arg2) __SOFTFP sl@0: { sl@0: double result; sl@0: int returnValue; sl@0: sl@0: returnValue = Math::Pow(result, arg1, arg2); sl@0: MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Return remainder of floating point division. sl@0: Performs division arg1/arg2 and returns the remainder of the operation. sl@0: @return Remainder of arg1/arg2. sl@0: @param arg1 and arg2 - Floating point values sl@0: */ sl@0: EXPORT_C double fmod (double arg1, double arg2) __SOFTFP sl@0: { sl@0: double result; sl@0: int returnValue; sl@0: sl@0: returnValue = Math::Mod(result, arg1, arg2); sl@0: MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Round to integral value in floating-point format sl@0: @return the integral value (represented as a double precision number) nearest to arg1 according to the prevailing rounding mode. sl@0: @param arg1 floating point value to round. sl@0: */ sl@0: EXPORT_C double rint (double arg1) __SOFTFP sl@0: { sl@0: double result; sl@0: int returnValue; sl@0: sl@0: returnValue = Math::Round(result, arg1, 0); sl@0: MapSymbianErrorCodeToErrno(returnValue, Math::IsNaN(result)); sl@0: sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: tests whether d is NaN sl@0: @return non-zero if d is NaN. Otherwise, 0 is returned. sl@0: @param d floating point value. sl@0: */ sl@0: EXPORT_C int isnan (double d) __SOFTFP sl@0: { sl@0: return Math::IsNaN(d); sl@0: } sl@0: sl@0: /** sl@0: test for infinity or not-a-number sl@0: @return 1 if the number d is Infinity, otherwise 0. sl@0: @param d floating point value to test. sl@0: */ sl@0: EXPORT_C int isinf (double d) __SOFTFP sl@0: { sl@0: return Math::IsInfinite(d); sl@0: } sl@0: sl@0: /** sl@0: Test for finity. sl@0: @return a nonzero value if the x parameter is a finite number; sl@0: that is, if d is not +-, INF, NaNQ, or NaNS. sl@0: @param d floating point value to test. sl@0: */ sl@0: EXPORT_C int finite (double d) __SOFTFP sl@0: { sl@0: return Math::IsFinite(d); sl@0: } sl@0: sl@0: } // end of extern "C" sl@0: sl@0: sl@0: