glibc strtof() of FLT_MIN with 9 digits sets errno but shouldn't

Bug #1900247 reported by Alex Maslin
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Raspbian
New
Undecided
Unassigned

Bug Description

Compile this with gcc:

#include <stdlib.h>
#include <stdio.h>
#include <float.h>
#include <errno.h>
#include <math.h>

int main(int argc, char **argv)
{
  errno = 0;
  float result = strtof(argv[1], NULL);
  printf("result==FLT_MIN %d\n", result==FLT_MIN);
  printf("errno==ERANGE %d\n", errno==ERANGE);
  printf("%.9g\n", result);
  return 0;
}

Then running it with:

> ./a.out 1.17549435e-38 # this number is FLT_MIN represented with 9 digits

gives this output:

result==FLT_MIN 1
errno==ERANGE 1
1.17549435e-38

I.e. strtof() is returning the correct result of FLT_MIN, BUT it is setting errno to ERANGE, which it should not do, errno should still be zero.

On OS X 10.15.3 / clang and on a fresh Arch Linux install / gcc, I get the correct result:

result==FLT_MIN 1
errno==ERANGE 0
1.17549435e-38

Also, back to the raspberry pi, it works with FLT_MIN rounded to 8 digits:

> ./a.out 1.1754944e-38
result==FLT_MIN 1
errno==ERANGE 0
1.17549435e-38

For information, on my raspberry pi:
> uname -a
Linux raspberrypi 5.4.51+ #1333 Mon Aug 10 16:38:02 BST 2020 armv6l GNU/Linux
> dpkg -s libc6 | grep ^Version
Version: 2.28-10+rpi1
> gcc --version
gcc (Raspbian 8.3.0-6+rpi1) 8.3.0
> cat /proc/device-tree/model
Raspberry Pi Model B Rev 12012

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.