Float problen running i386 inary on amd64

Peter Jeremy peterjeremy at optushome.com.au
Wed Nov 14 22:20:07 PST 2007


On Fri, Nov 02, 2007 at 10:04:48PM +0000, Pete French wrote:
>	int
>	main(int argc, char *argv[])
>	{
>        	if(atof("3.2") == atof("3.200"))
>                	puts("They are equal");
>        	else
>                	puts("They are NOT equal!");
>        	return 0;
>	}

Since the program as defined above does not include any prototype for
atof(), its return value is assumed to be int.  The i386 code for the
comparison is therefore:

        movl    $.LC0, (%esp)
        call    atof
        movl    $.LC1, (%esp)
        movl    %eax, %ebx
        call    atof
        cmpl    %eax, %ebx
        je      .L7

Note that this is comparing the %eax returned by each atof().  Since
atof() actually returns a double in %st(0) and %eax is a scratch
register, the results are completely undefined.  Unfortunately, I
can't explain why an i386 would be different to an amd64 in i386 mode.

-- 
Peter Jeremy
Please excuse any delays as the result of my ISP's inability to implement
an MTA that is either RFC2821-compliant or matches their claimed behaviour.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 187 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-stable/attachments/20071115/a5ed61b2/attachment-0001.pgp


More information about the freebsd-stable mailing list