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_dtor.cpp
20 const TInt KMaxScanDigits = 19; // maximum number of decimal digits guaranteed not to overflow TUint64
22 void TLex8::Scndig(TInt& aSig, TInt& aExp, TUint64& aDl)
24 // Scans a decimal digit field and accumulates the value to a TUint64 at aDl
25 // Used before decimal point - do not drop trailing zeros.
37 if (aSig<KMaxScanDigits)
39 aDl *= 10; // Multiply accumulator by 10
40 aDl+=((TUint)c)-'0'; // Add current digit
48 void TLex8::ScndigAfterPoint(TInt& aSig, TUint64& aDl)
50 // Scans a decimal digit field and accumulates the value to a TUint64 at aDl
51 // Used after decimal point - drops trailing zeros.
53 // Could be improved with change to header file!!
55 TInt trailing=0; // no of trailing zeros
56 TInt leading=0; // no of leading zeros
72 if (aDl!=0) // possible trailing zeros
74 else // if aDl==0 multiplying by 10 and adding 0 has no effect
77 aSig++; // leading zeros have significance
80 else if ((aSig<KMaxScanDigits+leading && !trailing) || (trailing && aSig+trailing+1<KMaxScanDigits))
82 // first multiply, taking account of preceeding zeros
83 for (n=trailing; n>=0; n--)
85 aDl *= 10; // Multiply accumulator by 10
87 // now add current digit
89 // now update significant digits used
97 void TLex16::Scndig(TInt& aSig, TInt& aExp, TUint64& aDl)
99 // Scans a decimal digit field and accumulates the value to a TUint64 at aDl
110 if (aSig<KMaxScanDigits)
112 aDl *= 10; // Multiply accumulator by 10
113 aDl+=((TUint)c)-'0'; // Add current digit
121 EXPORT_C TInt TLex8::Val(TReal32& aVal)
123 // Convert a 32 bit real.
133 EXPORT_C TInt TLex8::Val(TReal32& aVal, TChar aPoint)
135 // Convert a 32 bit real.
139 TInt r=Val(x,aPoint);
145 EXPORT_C TInt TLex8::Val(TReal64& aVal)
147 // Convert a 64 bit real.
157 EXPORT_C TInt TLex8::Val(TReal64& aVal, TChar aPoint)
159 // Convert a 64 bit real.
163 TInt r=Val(x,aPoint);
169 TInt TLex8::Val(TRealX& aVal)
171 // Convert an extended real. Use the locale decimal point.
175 return(Val(aVal,locale.DecimalSeparator()));
178 TInt TLex8::Val(TRealX& aVal, TChar aPoint)
180 // Convert an extended real.
184 TLexMark8 start(iNext);
194 else if (Peek()=='+')
196 TInt digflg=Peek().IsDigit();
197 while (Peek()=='0') // Skip leading zeros
201 Scndig(nsig,nskip,n);
208 digflg=Peek().IsDigit();
209 ScndigAfterPoint(nsig,n); // skip trailing zeros
215 return(KErrGeneral); // Not a number
219 if (Peek()=='E' || Peek()=='e')
221 TLexMark8 rollback(iNext);
228 aVal.SetInfinite(minus);
233 //it wasn't a number after the 'e', so rollback to the 'e'
234 UnGetToMark(rollback);
245 // Clear msb and if it was set then add 2^63 to aVal as a TRealX
246 // as TRealX can only be set from a TInt64.
247 TUint32 nh = I64HIGH(n);
248 n <<= 1; // Clear the msb of n (64 bit number so this is most efficient method).
251 if (nh & 0x80000000u)
254 nhx.iExp = (TUint16)(nhx.iExp + 63);
259 nexp += nskip - nfract;
260 r=Math::MultPow10X(aVal,nexp);
264 EXPORT_C TInt TLex16::Val(TReal32& aVal)
266 // Convert a 32 bit real.
276 EXPORT_C TInt TLex16::Val(TReal32& aVal, TChar aPoint)
278 // Convert a 32 bit real.
282 TInt r=Val(x,aPoint);
288 EXPORT_C TInt TLex16::Val(TReal64& aVal)
290 // Convert a 64 bit real.
300 EXPORT_C TInt TLex16::Val(TReal64& aVal, TChar aPoint)
302 // Convert a 64 bit real.
306 TInt r=Val(x,aPoint);
312 TInt TLex16::Val(TRealX& aVal)
314 // Convert an extended real. Use the locale decimal point.
318 return(Val(aVal,locale.DecimalSeparator()));
321 TInt TLex16::Val(TRealX& aVal, TChar aPoint)
323 // Convert a 64 bit real
327 HBufC8 *temp=HBufC8::New(iEnd-iNext);
329 return(KErrNoMemory);
330 TPtr8 tdes(temp->Des());
332 for (const TText* p = (TText*)iNext; p < (TText*)iEnd; p++)
341 tdes.Append((TUint8)c);
347 TInt r=lex.Val(aVal,aPoint);
350 Inc(lex.TokenLength());