Update contrib.
1 // Copyright (c) 1995-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 the License "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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\euser\maths\um_exp.cpp
15 // Floating point exponentiation
21 #if defined(__USE_VFP_MATH) && !defined(__CPU_HAS_VFP)
22 #error __USE_VFP_MATH was defined but not __CPU_HAS_VFP - impossible combination, check variant.mmh
25 #ifndef __USE_VFP_MATH
27 LOCAL_D const TUint32 ExpCoeffs[] =
29 0x00000000,0x80000000,0x7FFF0000, // polynomial approximation to 2^(x/8)
30 0xD1CF79AC,0xB17217F7,0x7FFB0000, // for 0<=x<=1
31 0x1591EF2B,0xF5FDEFFC,0x7FF60000,
32 0x23B940A9,0xE35846B9,0x7FF10000,
33 0xDD73C23F,0x9D955ADE,0x7FEC0000,
34 0x8728EBE7,0xAEC4616C,0x7FE60000,
35 0xAF177130,0xA1646F7D,0x7FE00000,
36 0xC44EAC22,0x8542C46E,0x7FDA0000
39 LOCAL_D const TUint32 TwoToNover8[] =
41 0xEA8BD6E7,0x8B95C1E3,0x7FFF0000, // 2^0.125
42 0x8DB8A96F,0x9837F051,0x7FFF0000, // 2^0.250
43 0xB15138EA,0xA5FED6A9,0x7FFF0000, // 2^0.375
44 0xF9DE6484,0xB504F333,0x7FFF0000, // 2^0.500
45 0x5506DADD,0xC5672A11,0x7FFF0000, // 2^0.625
46 0xD69D6AF4,0xD744FCCA,0x7FFF0000, // 2^0.750
47 0xDD24392F,0xEAC0C6E7,0x7FFF0000 // 2^0.875
50 LOCAL_D const TUint32 EightLog2edata[] = {0x5C17F0BC,0xB8AA3B29,0x80020000}; // 8/ln2
55 EXPORT_C TInt Math::Exp(TReal& aTrg, const TReal& aSrc)
57 Calculates the value of e to the power of x.
59 @param aTrg A reference containing the result.
60 @param aSrc The power to which e is to be raised.
62 @return KErrNone if successful, otherwise another of
63 the system-wide error codes.
66 // Calculate exp(aSrc) and write result to aTrg
68 // Let x=aSrc/ln2 and calculate 2^x
69 // 2^x = 2^int(x).2^frac(x)
70 // 2^int(x) just adds int(x) to the final result exponent
71 // Reduce frac(x) to the range [0,0.125] (modulo 0.125)
72 // Use polynomial to calculate 2^x for 0<=x<=0.125
73 // Multiply by 2^(n/8) for n=0,1,2,3,4,5,6,7 to give 2^frac(x)
75 const TRealX& EightLog2e=*(const TRealX*)EightLog2edata;
84 if (n<16384 && n>-16384)
89 PolyX(y,x,7,(const TRealX*)ExpCoeffs);
90 y.iExp=TUint16(TInt(y.iExp)+(n>>3));
93 y*= (*(const TRealX*)(TwoToNover8+3*n-3));
94 return y.GetTReal(aTrg);
131 #else // __USE_VFP_MATH
133 // definitions come from RVCT math library
134 extern "C" TReal exp(TReal);
136 EXPORT_C TInt Math::Exp(TReal& aTrg, const TReal& aSrc)
139 if (Math::IsZero(aTrg))
140 return KErrUnderflow;
141 if (Math::IsFinite(aTrg))
143 if (Math::IsInfinite(aTrg))