diff -r 000000000000 -r bde4ae8d615e os/ossrv/genericopenlibs/cstdlib/LSTDLIB/ATOF.CPP --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/os/ossrv/genericopenlibs/cstdlib/LSTDLIB/ATOF.CPP Fri Jun 15 03:10:57 2012 +0200 @@ -0,0 +1,120 @@ +// Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// FUNCTION +// <>, <>---string to double or float +// INDEX +// atof +// INDEX +// atoff +// ANSI_SYNOPSIS +// + +// #include +// double atof(const char *<[s]>); +// float atoff(const char *<[s]>); +// TRAD_SYNOPSIS +// #include +// double atof(<[s]>) +// char *<[s]>; +// float atoff(<[s]>) +// char *<[s]>; +// <> converts the initial portion of a string to a <>. +// <> converts the initial portion of a string to a <>. +// The functions parse the character string <[s]>, +// locating a substring which can be converted to a floating point +// value. The substring must match the format: +// . [+|-]<[digits]>[.][<[digits]>][(e|E)[+|-]<[digits]>] +// The substring converted is the longest initial +// fragment of <[s]> that has the expected format, beginning with +// the first non-whitespace character. The substring +// is empty if <> is empty, consists entirely +// of whitespace, or if the first non-whitespace character is +// something other than <<+>>, <<->>, <<.>>, or a digit. +// <)>> is implemented as <, NULL)>>. +// <)>> is implemented as <, NULL)>>. +// RETURNS +// <> returns the converted substring value, if any, as a +// <>; or <<0.0>>, if no conversion could be performed. +// If the correct value is out of the range of representable values, plus +// or minus <> is returned, and <> is stored in +// <>. +// If the correct value would cause underflow, <<0.0>> is returned +// and <> is stored in <>. +// <> obeys the same rules as <>, except that it +// returns a <>. +// PORTABILITY +// <> is ANSI C. <>, <>, and <> are subsumed by <> +// and <>, but are used extensively in existing code. These functions are +// less reliable, but may be faster if the argument is verified to be in a valid +// range. +// Supporting OS subroutines required: <>, <>, <>, +// <>, <>, <>, <>. +// + +#include +#include +#include +#include +#include "../INC/ESTLIB.H" +extern "C" { + +/** +Convert string to double-precision floating-point value. +Parses string interpreting its content as a floating-point value +until a character that can not be interpreted is found, +and returns a double precision value. +@return The converted double value from the input string. +If an error occurs 0 is returned. +@param s String representing a floating point number. +@param tail Address of a pointer. +This is filled by the function with the address where scan has ended. +Serves to determine where there is the first non-numerical character in the string. +*/ +EXPORT_C double strtod (const char *s, char** tail) __SOFTFP + { + TLex8 data=(unsigned char *)s; + TReal64 ret=0.0; + data.SkipSpace(); + TBool minus = data.Peek() == '-'; + TInt r=data.Val(ret); + if (r==KErrOverflow) + { + errno=ERANGE; + if (minus) + ret = -HUGE_VAL; + else + ret = HUGE_VAL; + } + else if (r==KErrUnderflow) + errno=ERANGE; + if (tail) + *tail=(char*)(s+data.Offset()); + return ret; + } + +/** +Convert string to double. +Parses string interpreting its content as a floating point number +and returns a value of type double. +@return The converted floating point value of the input string. + On overflow the result is undefined. + If an error occurs 0.0 is returned. +@param s String representing a floating point number. +*/ +EXPORT_C double atof (const char *s) __SOFTFP + { + return strtod(s,NULL); + } + +} // extern "C"