This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Floating P oint subno rmal numbe rs under C 99 with GC C 4.7â
- From: Argentinator RincÃn MatemÃtico <argentinator at outlook dot com>
- To: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Sun, 27 Jan 2013 20:02:14 -0300
- Subject: Floating P oint subno rmal numbe rs under C 99 with GC C 4.7â
- References: <SNT002-W17556D20B2E245E18029565D8190@phx.gbl>
Hi, dear friends.
I am testing floating-points macros in C language, under the standard C99.
My compiler is GCC 4.6.1. (with 4.7.1, I have the same result).
I have two computers:
My system (1) is Windows XP SP2 32bit, in an "Intel (R) Celeron (R) 420" @ 1.60 GHz.
My system (2) is Windows 7 Ultimate SP1 64bit, in an "AMD Turion II X2 dual-core mobile M520 ( 2,3 ghz 1MB L2 Cache )"
(The result was the same in both systems.)
I am interested in testing subnormal numbers for the types float, double and long double.
I've tried the following line:
printf(" Float: %x\n Double: %x\n Long Double: %x\n",fpclassify(FLT_MIN / 4.F), fpclassify(DBL_MIN / 4.), fpclassify(LDBL_MIN / 4.L ));
I've compiled with the options -std=c99 and -pedantic (also without -pedantic).
Compilation goes well, however the program shows me this:
ÂFloat: 400
ÂDouble: 400
ÂLong Double: 4400
(0x400 == FP_NORMAL, 0x4400 == FP_SUBNORMAL)
I think that the right result must be 0x4400 in all cases.
When I tested the constant sizes, I have obtained they are of the right type.
For example, I have obtained:
sizeof(float) == 4
sizeof(double) == 8
sizeof(long double) == 12
Also:
sizeof(FLT_MIN / 4.F) == 4
sizeof(DBL_MIN / 4.) == 8
sizeof(LDBL_MIN / 4.L) == 12
This means that FLT_MIN / 4.F only can be a float, and so on.
Moreover, FLT_MIN / 4.F must be a subnormal float number.
However, it seems like the fpclassify() macro behave as if any argument were a long double number.
Just in case, I have recompiled the program by putting the constants at hand:
printf(" Float: %x\n", fpclassify(0x1p-128F));
The result was the same.
Am I missunderstanding the C99 rules? Or the fpclassify() macro has a bug in the GCC compiler?
(in the same way, the isnormal() macro "returns" 1 for float and double, but 0 for long double).
I quote the C99 standard paragraph that explains the behaviour of fpclassify macro:
First, an argument represented in a format wider than its semantic type is converted to its semantic type.
Then classiïcation is based on the type of the argument.
Thanks.
Sincerely, yours.
Argentinator