diff -r c55016431358 -r 0a7b44b10206 symport/e32/euser/maths/um_ln.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/symport/e32/euser/maths/um_ln.cpp Thu Jun 25 15:59:54 2009 +0100 @@ -0,0 +1,143 @@ +// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Symbian Foundation License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// e32\euser\maths\um_ln.cpp +// Natural log. +// +// + +#include "um_std.h" + +#if defined(__USE_VFP_MATH) && !defined(__CPU_HAS_VFP) +#error __USE_VFP_MATH was defined but not __CPU_HAS_VFP - impossible combination, check variant.mmh +#endif + + +#ifndef __USE_VFP_MATH + +LOCAL_D const TUint32 ArtanhCoeffs[] = + { + 0x5C17F0BC,0xB8AA3B29,0x80010000, // polynomial approximation to (4/ln2)artanh(x) + 0xD02489EE,0xF6384EE1,0x7FFF0000, // for |x| <= (sqr2-1)/(sqr2+1) + 0x7008CA5F,0x93BB6287,0x7FFF0000, + 0xE32D1D6B,0xD30BB16D,0x7FFE0000, + 0x461D071E,0xA4257CE2,0x7FFE0000, + 0xC3B0EC87,0x8650D459,0x7FFE0000, + 0x53BEC0CD,0xE23137E3,0x7FFD0000, + 0xC523F21B,0xDAF79221,0x7FFD0000 + }; + +LOCAL_D const TUint32 Ln2By2data[] = {0xD1CF79AC,0xB17217F7,0x7FFD0000}; // (ln2)/2 +LOCAL_D const TUint32 Sqr2data[] = {0xF9DE6484,0xB504F333,0x7FFF0000}; // sqr2 +LOCAL_D const TUint32 Sqr2Invdata[] = {0xF9DE6484,0xB504F333,0x7FFE0000}; // 1/sqr2 +LOCAL_D const TUint32 Onedata[] = {0x00000000,0x80000000,0x7FFF0000}; // 1.0 + + + + +EXPORT_C TInt Math::Ln(TReal& aTrg, const TReal& aSrc) +/** +Calculates the natural logarithm of a number. + +@param aTrg A reference containing the result. +@param aSrc The number whose natural logarithm is required. + +@return KErrNone if successful, otherwise another of + the system-wide error codes. +*/ + { + // Calculate ln(aSrc) and write to aTrg + // Algorithm: + // Calculate log2(aSrc) and multiply by ln2 + // log2(aSrc)=log2(2^e.m) e=exponent of aSrc, m=mantissa 1<=m<2 + // log2(aSrc)=e+log2(m) + // If e=-1 (0.5<=aSrc<1), let x=aSrc else let x=mantissa(aSrc) + // If x>Sqr2, replace x with x/Sqr2 + // If xSqr2) + { + x*=Sqr2Inv; + n++; + } + } + else + { + n=0; + x.iExp=0x7FFE; + if (x