russotto@eng.umd.edu (Matthew T. Russotto) (11/07/89)
>Has anyone else seen the bug in the 68881 ANSI library that >causes the first two bytes after a float to be zeroed? >it does not occur in the standard library. >It is fully reproducable on my system with this program: > >static float setme; >unsigned long getstrashed = 0xFFFFFFFF; >char mystr[] = "1.0"; >main() >{ > printf("mystr %s, setme %f, getstrashed %08lX\n", mystr, setme, getstrashed); > sscanf(mystr, "%f", &setme); > printf("mystr %s, setme %f, getstrashed %08lX\n", mystr, setme, getstrashed); >} >Results with 68881 enabled, using ANSI-68881 library: >mystr 1.0, setme 0, getstrashed FFFFFFFF >mystr 1.0, setme 1, getstrashed 0000FFFF >Results with 68881 disabled, using ANSI library >mystr 1.0, setme 0, getstrashed FFFFFFFF >mystr 1.0, setme 1, getstrashed FFFFFFFF Well, I got no answer from the net, so I assume I have the 'honor' of finding it first... Fortunately, I also managed to find the solution. But first, a workaround: When using the 68881 ANSI library, don't use floats or short doubles. The problem: There is some conditionally compiled code in scanf.c that is only appropriate if there the 68881 is in use AND the variable in question is a double (a.k.a EXTENDED). There is no check to see if the variable is a double. The solution is to surround the section of code in dtof() that is conditionally compiled with an if statement: if (code == FFEXT) { /* code to convert 80 to 96 bit extended or vice versa */ } (if this has been discussed before, I apologize. But why didn't someone TELL me?) -- Matthew T. Russotto russotto@eng.umd.edu russotto@wam.umd.edu rrn: newsgroup "junk" full --- rerouting to news.groups