A simple program which prints the value of isnormal(4.9406564584124654417657e-324) shows 1 (also if that value is assigned to a variable declared "double" and that variable is tested):
#include <stdio.h>
#include <math.h>
int main(void) {
double x = 4.9406564584124654417657e-324;
printf("Normal? %d\n" isnormal(x));
printf("Normal? %d\n" isnormal(4.9406564584124654417657e-324));
}
The program should show "Normal? 0" twice. The denormalised number has been taken from the ATF tests for fpclassify/isnormal from the NetBSD source tree.
More denormalised numbers from that test suite:
1.1125369292536006915451e-308
-5.5626846462680034577256e-309
4.9406564584124654417657e-324
This has been reported for MingW as well, and hasn't been fixed there yet either: http://sourceforge.net/p/mingw/bugs/1927/
I tested your testcase on linux using glibc (libm), and it produces same result as we do on mingw-w64's trunk.
In both cases isnormal is 0 (as to be expected).
IMHO is testcase invalid.
So, found the issue. It affects 32-bit only.
For 32-bits result is 1, for 64-bit result is 0. So the bug seems to be on 32-bit side.
The 32-bit code, for double, is in effect the following:
It might make sense to use (when available) GCC's type-generic
__builtin_fpclassify(https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html) instead of the current__fpclassifyin mingw-w64.With my 32-bit mingw-w64 port of gcc-8.1.0, I still experience this issue iff optimization is enabled.
There's no problem with the 64-bit port.
Here's the demo :
When built without optimization it correctly outputs:
ok
4400
4400
But when built with O1 (or higher) optimization it outputs:
wtf
400
400
Cheers,
Rob