On 1/27/2013 6:02 PM, Argentinator Rincón Matemático wrote:
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 classification is based on the type of the argument.
Thanks.
Sincerely, yours.
Argentinator
This looks more like a topic for gcc-help.
Even if you had quoted gcc -v it would not reveal conclusively where
your <float.h> or fpclassify() came from, although it would give some
important clues. There are at least 3 different implementations of gcc
for Windows (not counting 32- vs. 64-bit), although not all are commonly
available for gcc-4.6 or 4.7. The specific version of gcc would make
less difference than which implementation it is.
I guess, from your finding that sizeof(long double) == 12, you are
running a 32-bit compiler even on the 64-bit Windows.
The 32-bit gcc I have installed on my 64-bit Windows evaluates
expressions in long double unless -mfpmath=sse is set (as one would
normally do). This may affect the results returned by fpclassify.
64-bit gcc defaults to -mfpmath=sse.
--
Tim Prince