summaryrefslogtreecommitdiffstats
path: root/private/crt32/convert/atof.c
blob: debc9635c721bdfd27c1eeea378237e08269ddae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/***
*atof.c - convert char string to floating point number
*
*	Copyright (c) 1985-1992, Microsoft Corporation. All rights reserved.
*
*Purpose:
*	Converts a character string into a floating point number.
*
*Revision History:
*	09-09-87  RKW	written
*	04-13-87  JCR	added const to declaration
*	11-09-87  BCM	different interface under ifdef MTHREAD
*	12-11-87  JCR	Added "_LOAD_DS" to declaration
*	05-24-88  PHG	Merged DLL and normal versions
*	08-18-88  PHG	now calls isspace to process all kinds of whitespce
*	10-04-88  JCR	386: Removed 'far' keyword
*	11-20-89  JCR	atof() is always _cdecl in 386 (not pascal)
*	03-05-90  GJF	Fixed calling type, added #include <cruntime.h>,
*			removed #include <register.h>, removed some redundant
*			prototypes, removed some leftover 16-bit support and
*			fixed the copyright. Also, cleaned up the formatting
*			a bit.
*	07-20-90  SBM	Compiles cleanly with -W3 (added/removed appropriate
*			#includes)
*	08-01-90  SBM	Renamed <struct.h> to <fltintrn.h>
*	09-27-90  GJF	New-style function declarator.
*	10-21-92  GJF	Made char-to-int conversion unsigned.
*
*******************************************************************************/

#include <stdlib.h>
#include <math.h>
#include <cruntime.h>
#include <fltintrn.h>
#include <string.h>
#include <ctype.h>

/***
*double atof(nptr) - convert string to floating point number
*
*Purpose:
*	atof recognizes an optional string of whitespace, then
*	an optional sign, then a string of digits optionally
*	containing a decimal point, then an optional e or E followed
*	by an optionally signed integer, and converts all this to
*	to a floating point number.  The first unrecognized
*	character ends the string.
*
*Entry:
*	nptr - pointer to string to convert
*
*Exit:
*	returns floating point value of character representation
*
*Exceptions:
*
*******************************************************************************/

double _CRTAPI1 atof(
	REG1 const char *nptr
	)
{

#ifdef	MTHREAD
	struct _flt fltstruct;	    /* temporary structure */
#endif

	/* scan past leading space/tab characters */

	while ( isspace((int)(unsigned char)*nptr) )
		nptr++;

	/* let _fltin routine do the rest of the work */

#ifdef	MTHREAD
	return( *(double *)&(_fltin2( &fltstruct, nptr, strlen(nptr), 0, 0 )->
	dval) );
#else
	return( *(double *)&(_fltin( nptr, strlen(nptr), 0, 0 )->dval) );
#endif
}