home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / sys / sgi / 13006 < prev    next >
Encoding:
Text File  |  1992-08-29  |  2.8 KB  |  76 lines

  1. Newsgroups: comp.sys.sgi
  2. Path: sparky!uunet!pipex!warwick!dcs.warwick.ac.uk!maths.warwick.ac.uk!steve
  3. From: steve@maths.warwick.ac.uk (Steve Rumsby)
  4. Subject: Re: gcc2.2.2 on Iris Crimson (HELP!)
  5. Message-ID: <1992Aug28.124816.12065@dcs.warwick.ac.uk>
  6. Sender: news@dcs.warwick.ac.uk (Network News)
  7. Nntp-Posting-Host: severn
  8. Organization: Geometry Group, Maths Institute, Warwick University, UK.
  9. References: <TOTSUKA.92Aug27145458@avaia.av.crl.sony.co.jp> <TOTSUKA.92Aug28082940@avaia.av.crl.sony.co.jp>
  10. Distribution: comp
  11. Date: Fri, 28 Aug 1992 12:48:16 GMT
  12. Lines: 62
  13.  
  14. In article <TOTSUKA.92Aug28082940@avaia.av.crl.sony.co.jp>, totsuka@av.crl.sony.co.jp (Takashi Totsuka) writes:
  15. >  |Same things happens on a R3000 Indigo too. I finally trace the problem
  16. >  |to the hypot function in the C library (SGI's library, not glibc) which
  17. >  |was returning bizarre results, but only after printing a double on cout!
  18. >  |I couldn't see any way that these two functions could interfere with
  19. >  |each other, so I gave up at that point. If anybody has any ideas about
  20. >  |what might be going on, I'd love to hear them.
  21. >  |
  22. >  |As above, this is all compiling libg++-2.2.2 with gcc-2.2.2.
  23. >     I also played aound with Complex::sqrt() and noticed funny return
  24. >     value of hypot() in SGI libm.a. 
  25. >
  26. Yes, I meant libm, not libc. Slip of the keyboard...
  27.  
  28. >    However, when I check hypot() alone
  29. >     with a simple test program, it just works fine (with native cc and
  30. >     gcc, with -g and -O).  On the other hand, it is true that replacing
  31. >     hypot() with its definition (sqrt(x*x + y*y)) fixes the problem.
  32. >     I suspect G++ is doing some unnecessary conversion or it has
  33. >     some problem in procedure call/return...
  34. >
  35. No, I don't think so. As I said above, I constructed a C++ program that
  36. called hypot lots of times, and always got the right answer, *until* I
  37. put a double on cout, and then hypot always produced the wrong answer.
  38. Calling printf (also in libg++) with a double is fine and doesn't break
  39. anything. Try compiling and running this (gcc-2.2.2, libg++-2.2, Irix 4.0.2):
  40.  
  41. #include <stdio.h>
  42. #include <iostream.h>
  43. #include <math.h>
  44.  
  45. main()
  46. {
  47.     double    x1, x2, x3;
  48.  
  49.     x1 = hypot(1, 0);
  50.     printf("Here's a double from printf %f\n", 4.2);
  51.     x2 = hypot(1, 0);
  52.     cout << "Here's a double via iostream " << 4.2 << "\n";
  53.     x3 = hypot(1, 0);
  54.  
  55.     printf("x1 = %f, x2 = %f, x3 = %f\n", x1, x2, x3);
  56. }
  57.  
  58. The results I get are:
  59.  
  60. Here's a double from printf 4.200000
  61. Here's a double via iostream 4.2
  62. x1 = 1.000000, x2 = 1.000000, x3 = 4503599627370497.000000
  63.  
  64. That value for x3 looks a little suspicious:-)
  65.  
  66. Can somebody with the source to SGI's hypot (like somebody in SGI maybe:-)
  67. have a look and see if there's anything an external function can do that
  68. will break hypot. This is all very strange...
  69.  
  70. Steve.
  71. -- 
  72. UUCP:     ...!uknet!warwick!steve    Internet: steve@maths.warwick.ac.uk
  73. JANET:     steve@uk.ac.warwick.maths    PHONE:     +44 203 524657
  74.