Hi, I have a very simple program: 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; } This works as expected on both i386 and amd64. But if I take the compiled binary from the i386 system and run it on the amd64 system thenit says they are not equal! I thought this was a library problem, but it even happens if I compile to a static binary, which would preseumably mean the same code is running on both systems. I am using 6.3-PRERELEASE here -pete.
> From: Pete French <petefrench@ticketswitch.com> > > Hi, I have a very simple program: > > > 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; > } > > > This works as expected on both i386 and amd64. But if I take the compiled > binary from the i386 system and run it on the amd64 system thenit says they > are not equal! I thought this was a library problem, but it even happens if > I compile to a static binary, which would preseumably mean the same code is > running on both systems. > > I am using 6.3-PRERELEASE hereUnfortunately, I didn't have the luck of having it reproduced here. Maybe because my i386 is on 7.0, different compiler (although the amd64 is still on RELENG_6). Since you've rulled out everything else by building a static binary, did you try using the new C99 functions in fenv.h related to the floating-point environment? Miguel Ramos Lisboa, Portugal
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