home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.linux
- Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!rpi!batcomputer!eos.acm.rpi.edu!kutcha
- From: kutcha@eos.acm.rpi.edu (Phillip Rzewski)
- Subject: Not quite bug in math stuff
- Message-ID: <1992Dec13.032953.4975@tc.cornell.edu>
- Sender: news@tc.cornell.edu
- Nntp-Posting-Host: eos.acm.rpi.edu
- Organization: The Voice of Fate
- Date: Sun, 13 Dec 1992 03:29:53 GMT
- Lines: 48
-
-
- I don't do much stuff with math under Linux, so I never ran into this
- before. I'm sure someone else has come across this, it's probably quite
- documented somewhere. But it took me rather by surprise.
-
- Consider the program:
-
- #include <stdio.h>
- #include <math.h>
-
- int main(void)
- {
- double d;
- long l;
-
- d = pow(2.0, 1.0);
- printf("%1.32f\n", d);
- l = (long) d;
- printf("%d\n", l);
-
- return 0;
- }
-
- And of course the output:
-
- 1.99999999999999977795539507496869
- 1
-
- Now, I understand how keen it is that math software speeds things up
- by using logarithms, giving us results like this. However, I know that there
- are systems out there where one doesn't notice it quite so much. The
- program I was originally working with on Linux (not like the one above :) )
- was originally something I wrote under VAX C on a VMS system, and I got
- just what I thought in the long (in other words, 2).
-
- Of course, I was able to fix this by simply adding 0.5 to the double
- and then casting it to long. It just seems kinda icky to have to do it that
- way. I mean, this means that every person who tries to do something like I
- did above (which I would think is quite a few) would have to have this same
- weird thing happen to them and learn how to correct it.
-
- I'm not one to make demands or anything, but the math people might
- consider fixing this?
-
- --
- Phillip Andrew Rzewski Internet: kutcha@acm.rpi.edu
- "Don't wait; while you're waiting, you're dying."
- --- Peter Hammill
-