Bug in dlls/oleaut32/tests/vartype.c?
Alex Villacís Lasso
a_villacis at palosanto.com
Mon Oct 29 17:56:07 CDT 2007
Gerald Pfeifer escribió:
> On Mon, 15 Oct 2007, Gerald Pfeifer wrote:
>
>> 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 at 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.
>>
>
> 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)
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 at srv64 cpp]$ gcc -O2 -Wall test_underflow.c -o test_underflow
[alex at srv64 cpp]$ ./test_underflow
Value as float is -0.000000
Value as bytes is 00 00 00 80
[alex at srv64 cpp]$
What compiler are you using? Which version? What is the output of said
compiler on the test program?
--
perl -e '$x=2.4;print sprintf("%.0f + %.0f = %.0f\n",$x,$x,$x+$x);'
More information about the wine-devel
mailing list