home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / linux / 20125 < prev    next >
Encoding:
Text File  |  1992-12-12  |  1.9 KB  |  60 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!cs.utexas.edu!zaphod.mps.ohio-state.edu!rpi!batcomputer!eos.acm.rpi.edu!kutcha
  3. From: kutcha@eos.acm.rpi.edu (Phillip Rzewski)
  4. Subject: Not quite bug in math stuff
  5. Message-ID: <1992Dec13.032953.4975@tc.cornell.edu>
  6. Sender: news@tc.cornell.edu
  7. Nntp-Posting-Host: eos.acm.rpi.edu
  8. Organization: The Voice of Fate
  9. Date: Sun, 13 Dec 1992 03:29:53 GMT
  10. Lines: 48
  11.  
  12.  
  13.     I don't do much stuff with math under Linux, so I never ran into this
  14. before. I'm sure someone else has come across this, it's probably quite
  15. documented somewhere. But it took me rather by surprise.
  16.  
  17.     Consider the program:
  18.  
  19. #include <stdio.h>
  20. #include <math.h>
  21.  
  22. int main(void)
  23. {
  24.   double d;
  25.   long l;
  26.  
  27.   d = pow(2.0, 1.0);
  28.   printf("%1.32f\n", d);
  29.   l = (long) d;
  30.   printf("%d\n", l);
  31.  
  32.   return 0;
  33. }
  34.  
  35.     And of course the output:
  36.  
  37. 1.99999999999999977795539507496869
  38. 1
  39.  
  40.     Now, I understand how keen it is that math software speeds things up
  41. by using logarithms, giving us results like this. However, I know that there
  42. are systems out there where one doesn't notice it quite so much. The
  43. program I was originally working with on Linux (not like the one above :) )
  44. was originally something I wrote under VAX C on a VMS system, and I got
  45. just what I thought in the long (in other words, 2).
  46.  
  47.     Of course, I was able to fix this by simply adding 0.5 to the double
  48. and then casting it to long. It just seems kinda icky to have to do it that
  49. way. I mean, this means that every person who tries to do something like I
  50. did above (which I would think is quite a few) would have to have this same
  51. weird thing happen to them and learn how to correct it.
  52.  
  53.     I'm not one to make demands or anything, but the math people might
  54. consider fixing this?
  55.  
  56. --
  57.   Phillip Andrew Rzewski                      Internet: kutcha@acm.rpi.edu
  58.              "Don't wait; while you're waiting, you're dying."
  59.                           --- Peter Hammill
  60.