31{
32 int caller_errno = errno;
33 float fresult;
34 char *myendptr;
35
36 errno = 0;
37 fresult = (strtof) (nptr, &myendptr);
38 if (endptr)
39 *endptr = myendptr;
40 if (errno)
41 {
42
43 return fresult;
44 }
45 else if ((myendptr == nptr) || isnan(fresult) ||
46 ((fresult >= FLT_MIN || fresult <= -FLT_MIN) && !isinf(fresult)))
47 {
48
49
50
51
52
53 errno = caller_errno;
54 return fresult;
55 }
56 else
57 {
58
59
60
61
62 double dresult = strtod(nptr, NULL);
63
64 if (errno)
65 {
66
67 return fresult;
68 }
69 else if ((dresult == 0.0 && fresult == 0.0) ||
70 (isinf(dresult) && isinf(fresult) && (fresult == dresult)))
71 {
72
73 errno = caller_errno;
74 return fresult;
75 }
76 else if ((dresult > 0 && dresult <= FLT_MIN && (float) dresult != 0.0) ||
77 (dresult < 0 && dresult >= -FLT_MIN && (float) dresult != 0.0))
78 {
79
80 errno = caller_errno;
81 return (float) dresult;
82 }
83 else
84 {
85 errno = ERANGE;
86 return fresult;
87 }
88 }
89}