* Copyright (c) 1990 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* the Systems Programming Group of the University of Utah Computer
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* PATCHES MAGIC LEVEL PATCH THAT GOT US HERE
* -------------------- ----- ----------------------
* CURRENT PATCH LEVEL: 2 00108
* -------------------- ----- ----------------------
* 27 Feb 93 Joerg Wunsch Implement strtod, fix atof.
* 28 Mar 93 Jordan Hubbard Fix stdtod bug with endp, remove warnings.
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid
[] = "@(#)atof.c 5.2 (Berkeley) 4/12/91";
#endif /* LIBC_SCCS and not lint */
* simple atof() for IEEE 754 architectures
#include <machine/endian.h>
static double twoemax
= 9007199254740992.; /*2^53*/
/* attempt to be as exact as possible */
#if BYTE_ORDER == BIG_ENDIAN
{ 0x40140000, 0x00000000 }, /* 5 */
{ 0x40390000, 0x00000000 }, /* 25 */
{ 0x40838800, 0x00000000 }, /* 625 */
{ 0x4117d784, 0x00000000 }, /* 390625 */
{ 0x4241c379, 0x37e08000 }, /* 152587890625 */
{ 0x4493b8b5, 0xb5056e17 }, /* 2.3283064365387e+022 */
{ 0x49384f03, 0xe93ff9f5 }, /* 5.42101086242753e+044 */
{ 0x52827748, 0xf9301d32 }, /* 2.93873587705572e+089 */
{ 0x65154fdd, 0x7f73bf3b } /* 8.63616855509445e+178 */
#else /* BYTE_ORDER == LITTLE_ENDIAN */
{ 0x00000000, 0x40140000 }, /* 5 */
{ 0x00000000, 0x40390000 }, /* 25 */
{ 0x00000000, 0x40838800 }, /* 625 */
{ 0x00000000, 0x4117d784 }, /* 390625 */
{ 0x37e08000, 0x4241c379 }, /* 152587890625 */
{ 0xb5056e17, 0x4493b8b5 }, /* 2.3283064365387e+022 */
{ 0xe93ff9f5, 0x49384f03 }, /* 5.42101086242753e+044 */
{ 0xf9301d32, 0x52827748 }, /* 2.93873587705572e+089 */
{ 0x7f73bf3b, 0x65154fdd } /* 8.63616855509445e+178 */
while ((c
= *p
++) && isdigit(c
))
while ((c
= *p
++) && isdigit(c
))
if (c
== 'E' || c
== 'e') {
while ((c
= *p
++) && isdigit(c
))
eexp
= 10 * eexp
+ (c
-'0');
for (c
= 0; exp
&& c
< sizeof exp5
/ sizeof exp5
[0]; ++c
) {
flexp
*= *(double *)&exp5
[c
];
/* according to ANSI, check for over-/underflow */
return neg
< 0? -HUGE_VAL
: HUGE_VAL
;
return neg
< 0 ? -fl
: fl
;
return strtod(p
, (char **)NULL
);