PostgreSQL Source Code  git master
strtof.c File Reference
#include "c.h"
#include <float.h>
#include <math.h>
Include dependency graph for strtof.c:

Go to the source code of this file.

Functions

float strtof (const char *nptr, char **endptr)
 

Function Documentation

◆ strtof()

float strtof ( const char *  nptr,
char **  endptr 
)

Definition at line 28 of file strtof.c.

References isinf().

Referenced by float4in().

29 {
30  int caller_errno = errno;
31  double dresult;
32  float fresult;
33 
34  errno = 0;
35  dresult = strtod(nptr, endptr);
36  fresult = (float) dresult;
37 
38  if (errno == 0)
39  {
40  /*
41  * Value might be in-range for double but not float.
42  */
43  if (dresult != 0 && fresult == 0)
44  caller_errno = ERANGE; /* underflow */
45  if (!isinf(dresult) && isinf(fresult))
46  caller_errno = ERANGE; /* overflow */
47  }
48  else
49  caller_errno = errno;
50 
51  errno = caller_errno;
52  return fresult;
53 }
int isinf(double x)