dlls/oleaut32/tests/vartype.c has the following snippet of code:
+ f = -1e-400; /* deliberately cause underflow */ + hres = pVarBstrFromR4(f, lcid, 0, &bstr); + ok(hres == S_OK, "got hres 0x%08lx\n", hres); + if (bstr) + { + todo_wine ok(memcmp(bstr, szZero, sizeof(szZero)) == 0, "negative zero (got %s)\n", wtoascii(bstr)); + }
which was added in
revision 1.27 Alex Villacís Lasso a_villacis@palosanto.com Test for behavior of negative underflow formatting.
This doesn't seem to work as intended, because it is a floating point *constant* which current versions of GCC simply truncate to 0.0.
Gerald
On Mon, 15 Oct 2007, Gerald Pfeifer wrote:
The following patch tries to address this.
Gerald
ChangeLog: Avoid truncation of floating point calculation at compile-time. Index: dlls/oleaut32/tests/vartype.c =================================================================== RCS file: /home/wine/wine/dlls/oleaut32/tests/vartype.c,v retrieving revision 1.51 diff -u -3 -p -r1.51 vartype.c --- dlls/oleaut32/tests/vartype.c 20 Aug 2007 12:43:49 -0000 1.51 +++ dlls/oleaut32/tests/vartype.c 29 Oct 2007 22:40:24 -0000 @@ -4727,6 +4727,7 @@ static void test_VarBstrFromR4(void) HRESULT hres; BSTR bstr = NULL;
+ const float flarge=1e20; float f;
CHECKPTR(VarBstrFromR4); @@ -4747,7 +4748,7 @@ static void test_VarBstrFromR4(void) } }
- f = -1e-400; /* deliberately cause underflow */ + f = (-1 / flarge ) / flarge; /* deliberately cause underflow */ hres = pVarBstrFromR4(f, lcid, 0, &bstr); ok(hres == S_OK, "got hres 0x%08x\n", hres); if (bstr)
Gerald Pfeifer escribió:
Sorry to object, but which version of exactly which compiler optimizes away the negative sign?
Consider the following program:
#include <stdio.h> #include <stdlib.h>
union x { float f; unsigned char b[4]; };
int main(void) { union x u;
u.f = -1e-400; printf("Value as float is %f\n", u.f); printf("Value as bytes is %02x %02x %02x %02x\n", u.b[0], u.b[1], u.b[2], u.b[3]);
return 0; }
On my machine (i386 architecture, Fedora 7, gcc 4.1.2 20070925 (Red Hat 4.1.2-27)), the output is as follows:
[alex@srv64 cpp]$ gcc -O2 -Wall test_underflow.c -o test_underflow [alex@srv64 cpp]$ ./test_underflow Value as float is -0.000000 Value as bytes is 00 00 00 80 [alex@srv64 cpp]$
What compiler are you using? Which version? What is the output of said compiler on the test program?
[ Updated patch at the end, Alexandre. ]
On Mon, 29 Oct 2007, Alex Villacís Lasso wrote:
Sorry to object, but which version of exactly which compiler optimizes away the negative sign?
You're right, I misread this, sorry. My original patch wasn't wrong, but the explanation was, and there seems in fact a better patch.
Consider the following program:
That's a very fair test, and I enhanced it as follows:
#include <stdio.h> #include <stdlib.h>
void print(const float f) {
union x { float f; unsigned char b[4]; } u;
u.f = f;
printf("Value as float is %f\n", u.f); printf("as bytes %02x %02x %02x %02x\n\n",u.b[0],u.b[1],u.b[2],u.b[3]); }
int main() { print(-1e-400); print(-0.0); }
Both GCC 3.4 and GCC 4.2 snapshot give 00 00 00 80 in both cases. (All the original warning referred to actually did was to indicate that the compiler actually made this change automatically; that was added with GCC 4.3 it seems.)
Gerald
ChangeLog: Use -0.0 directly in test_VarBstrFromR4().
Index: vartype.c =================================================================== RCS file: /home/wine/wine/dlls/oleaut32/tests/vartype.c,v retrieving revision 1.51 diff -u -3 -p -r1.51 vartype.c --- vartype.c 20 Aug 2007 12:43:49 -0000 1.51 +++ vartype.c 1 Nov 2007 13:42:48 -0000 @@ -4747,7 +4747,7 @@ static void test_VarBstrFromR4(void) } }
- f = -1e-400; /* deliberately cause underflow */ + f = -0.0; hres = pVarBstrFromR4(f, lcid, 0, &bstr); ok(hres == S_OK, "got hres 0x%08x\n", hres); if (bstr)