First public contribution.
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_mod.cpp
15 // Writes the remainder of aSrc/aModulus to aTrg
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 EXPORT_C TInt Math::Mod(TReal &aTrg,const TReal &aSrc,const TReal &aModulus)
29 Calculates the modulo remainder.
31 This is the value of p mod q, the modulo remainder when dividing p by q.
32 The result is given by p - q int (p/q):
33 it has the same sign as p:
34 thus, 5 mod 3 = 2, -5 mod 3 = -2.
35 No error is raised if non-integer arguments are passed.
37 @param aTrg A reference containing the result.
38 @param aSrc The p argument to the mod function.
39 @param aModulus The q argument to the mod function.
41 @return KErrNone if successful, otherwise another of
42 the system-wide error codes.
45 // Floating point modulo arithmetic.
57 if (r==KErrArgument || f2.IsZero())
67 if ((TInt(f1.iExp)-TInt(f2.iExp))>KMantissaBits)
70 return KErrTotalLossOfPrecision;
73 return f1.GetTReal(aTrg);
76 #else // __USE_VFP_MATH
78 // definitions come from RVCT math library
79 extern "C" TReal fmod(TReal,TReal);
81 EXPORT_C TInt Math::Mod(TReal& aTrg, const TReal& aSrc, const TReal &aModulus)
83 SReal64 *pSrc=(SReal64 *)&aSrc;
84 SReal64 *pModulus=(SReal64 *)&aModulus;
86 if (pSrc->exp==0 || pModulus->exp==0 || pSrc->exp==KSpecialExponent || pModulus->exp==KSpecialExponent)
96 if (r==KErrArgument || f2.IsZero())
106 if ((TInt(f1.iExp)-TInt(f2.iExp))>KMantissaBits)
109 return KErrTotalLossOfPrecision;
112 else if ((pSrc->exp - pModulus->exp) > KMantissaBits)
115 return KErrTotalLossOfPrecision;
118 aTrg = fmod(aSrc,aModulus);