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: // FUNCTION sl@0: // <>, <>---string to double or float sl@0: // INDEX sl@0: // atof sl@0: // INDEX sl@0: // atoff sl@0: // ANSI_SYNOPSIS sl@0: // sl@0: sl@0: // #include sl@0: // double atof(const char *<[s]>); sl@0: // float atoff(const char *<[s]>); sl@0: // TRAD_SYNOPSIS sl@0: // #include sl@0: // double atof(<[s]>) sl@0: // char *<[s]>; sl@0: // float atoff(<[s]>) sl@0: // char *<[s]>; sl@0: // <> converts the initial portion of a string to a <>. sl@0: // <> converts the initial portion of a string to a <>. sl@0: // The functions parse the character string <[s]>, sl@0: // locating a substring which can be converted to a floating point sl@0: // value. The substring must match the format: sl@0: // . [+|-]<[digits]>[.][<[digits]>][(e|E)[+|-]<[digits]>] sl@0: // The substring converted is the longest initial sl@0: // fragment of <[s]> that has the expected format, beginning with sl@0: // the first non-whitespace character. The substring sl@0: // is empty if <> is empty, consists entirely sl@0: // of whitespace, or if the first non-whitespace character is sl@0: // something other than <<+>>, <<->>, <<.>>, or a digit. sl@0: // <)>> is implemented as <, NULL)>>. sl@0: // <)>> is implemented as <, NULL)>>. sl@0: // RETURNS sl@0: // <> returns the converted substring value, if any, as a sl@0: // <>; or <<0.0>>, if no conversion could be performed. sl@0: // If the correct value is out of the range of representable values, plus sl@0: // or minus <> is returned, and <> is stored in sl@0: // <>. sl@0: // If the correct value would cause underflow, <<0.0>> is returned sl@0: // and <> is stored in <>. sl@0: // <> obeys the same rules as <>, except that it sl@0: // returns a <>. sl@0: // PORTABILITY sl@0: // <> is ANSI C. <>, <>, and <> are subsumed by <> sl@0: // and <>, but are used extensively in existing code. These functions are sl@0: // less reliable, but may be faster if the argument is verified to be in a valid sl@0: // range. sl@0: // Supporting OS subroutines required: <>, <>, <>, sl@0: // <>, <>, <>, <>. sl@0: // sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "../INC/ESTLIB.H" sl@0: extern "C" { sl@0: sl@0: /** sl@0: Convert string to double-precision floating-point value. sl@0: Parses string interpreting its content as a floating-point value sl@0: until a character that can not be interpreted is found, sl@0: and returns a double precision value. sl@0: @return The converted double value from the input string. sl@0: If an error occurs 0 is returned. sl@0: @param s String representing a floating point number. sl@0: @param tail Address of a pointer. sl@0: This is filled by the function with the address where scan has ended. sl@0: Serves to determine where there is the first non-numerical character in the string. sl@0: */ sl@0: EXPORT_C double strtod (const char *s, char** tail) __SOFTFP sl@0: { sl@0: TLex8 data=(unsigned char *)s; sl@0: TReal64 ret=0.0; sl@0: data.SkipSpace(); sl@0: TBool minus = data.Peek() == '-'; sl@0: TInt r=data.Val(ret); sl@0: if (r==KErrOverflow) sl@0: { sl@0: errno=ERANGE; sl@0: if (minus) sl@0: ret = -HUGE_VAL; sl@0: else sl@0: ret = HUGE_VAL; sl@0: } sl@0: else if (r==KErrUnderflow) sl@0: errno=ERANGE; sl@0: if (tail) sl@0: *tail=(char*)(s+data.Offset()); sl@0: return ret; sl@0: } sl@0: sl@0: /** sl@0: Convert string to double. sl@0: Parses string interpreting its content as a floating point number sl@0: and returns a value of type double. sl@0: @return The converted floating point value of the input string. sl@0: On overflow the result is undefined. sl@0: If an error occurs 0.0 is returned. sl@0: @param s String representing a floating point number. sl@0: */ sl@0: EXPORT_C double atof (const char *s) __SOFTFP sl@0: { sl@0: return strtod(s,NULL); sl@0: } sl@0: sl@0: } // extern "C"