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