1 /*-------------------------------------------------------------------------
5 * Portions Copyright (c) 2019-2025, PostgreSQL Global Development Group
11 *-------------------------------------------------------------------------
21 * Cygwin has a strtof() which is literally just (float)strtod(), which means
22 * we can't avoid the double-rounding problem; but using this wrapper does get
23 * us proper over/underflow checks. (Also, if they fix their strtof(), the
24 * wrapper doesn't break anything.)
26 * Test results on Mingw suggest that it has the same problem, though looking
27 * at the code I can't figure out why.
30 pg_strtof(const char *nptr
, char **endptr
)
32 int caller_errno
= errno
;
36 fresult
= (strtof
) (nptr
, endptr
);
39 /* On error, just return the error to the caller. */
42 else if ((*endptr
== nptr
) || isnan(fresult
) ||
43 ((fresult
>= FLT_MIN
|| fresult
<= -FLT_MIN
) && !isinf(fresult
)))
46 * If we got nothing parseable, or if we got a non-0 non-subnormal
47 * finite value (or NaN) without error, then return that to the caller
56 * Try again. errno is already 0 here.
58 double dresult
= strtod(nptr
, NULL
);
62 /* On error, just return the error */
65 else if ((dresult
== 0.0 && fresult
== 0.0) ||
66 (isinf(dresult
) && isinf(fresult
) && (fresult
== dresult
)))
68 /* both values are 0 or infinities of the same sign */
72 else if ((dresult
> 0 && dresult
<= FLT_MIN
&& (float) dresult
!= 0.0) ||
73 (dresult
< 0 && dresult
>= -FLT_MIN
&& (float) dresult
!= 0.0))
75 /* subnormal but nonzero value */
77 return (float) dresult
;