home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / fortran / 4883 < prev    next >
Encoding:
Text File  |  1993-01-01  |  4.5 KB  |  92 lines

  1. Newsgroups: comp.lang.fortran
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!eff!world!dpbsmith
  3. From: dpbsmith@world.std.com (Daniel P. B. Smith)
  4. Subject: Re: SPECIFIC Question about Fortran  (vs. C)
  5. Message-ID: <C07JIL.9EJ@world.std.com>
  6. Organization: The World Public Access UNIX, Brookline, MA
  7. References: <C034uA.7qu@news.cso.uiuc.edu>
  8. Date: Sat, 2 Jan 1993 03:39:56 GMT
  9. Lines: 81
  10.  
  11. I don't think the FORTRAN standard addresses accuracy directly.
  12. Both FORTRAN and C put SOME constraints on the language.
  13. For example, the C standard requires that there be headers
  14. named limits.h and float.h that document various properties of
  15. the numeric environment and set minimum requirements.  
  16.  
  17. In C, for example, it is guaranteed that an int must be able
  18. to represent the range -32767 to +32767 (i.e. it's at least sixteen
  19. bits).  A float is guaranteed to have at least six decimal digits of
  20. precision, a double is guaranteed to have at least ten.  I'm afraid
  21. I don't have a handy FORTRAN reference so I can't tell you what the
  22. equivalent is.
  23.  
  24. Generally speaking, the relevant standard for numerical precision is
  25. probably not any of the language standards, but the ANSI/IEE standard
  26. 754 for binary floating-point arithmetic.
  27.  
  28. The difference between the languages lies not so much in what the
  29. standard says, but in the culture that surrounds them.  Because it's
  30. in the culture that FORTRAN is used for numerical work, you can have
  31. a much higher degree of confidence in the accuracy, efficiency, and
  32. correctness of the numerical libraries supplied with FORTRAN compilers
  33. than with other languages.  Gross bugs in floating-point libraries are
  34. by no means known; there was a famous egregious example in one of
  35. Microsoft's BASICs for the PC; I believe 1.0/10.0 printed out as 0.01
  36. or something like that.  
  37.  
  38. As recently as 1984, you could purchase commercial C compilers that
  39. did not support floats at all.
  40.  
  41. In practice, if you are using FORTRAN compilers and an IEEE-754
  42. environment (which includes current Intel coprocessors, the Apple SANE
  43. libraries, and many minicomputers) it is very likely that the compiler
  44. will implement reals as IEEE 32-bit and double precision as IEEE 64-bit.
  45. If so, it is quite likely that identical FORTRAN programs will give
  46. identical numerical results.
  47.  
  48. The culture also dictates that FORTRAN compilers are usually highly
  49. optimized.  In fact, the ORIGINAL IBM FORTRAN was a very daring and
  50. ambitious project because they did not believe it would succeed unless
  51. FORTRAN-generated code was nearly as efficient as handwritten assembly
  52. language, so it was a very tricky, highly optimized compiler.  One of
  53. the reasons why FORTRAN historically has been somewhat ugly is that 
  54. language features that make the language nicer to write are resisted if
  55. they make it hard to write optimizing compilers.  
  56.  
  57. What I'm trying to say is that, suppose you need to solve some
  58. frammistan Eigen-whoozis multi-correlate dual-elimination boundary
  59. integrommet problem.  First of all, if you hit the libraries and the
  60. journals, the chance of finding a ready-made solution written in 
  61. FORTRAN is much higher than the chance of finding one in C, if for 
  62. no other reason than that they've been publishing 'em since the fifties
  63. in FORTRAN.  Second, if you find solutions in both FORTRAN and C, 
  64. the chances are higher that the one in FORTRAN is correct -- because the
  65. one written in C is probably a translation of something written in
  66. FORTRAN in the first place.
  67.  
  68. And if you write the thing in C there's a small but nonzero probability
  69. that you'll expose some bug in the compiler and/or libraries you're using,
  70. because the vendor didn't think it was as important and didn't work as
  71. hard on it as they did on, say, making sure their pointer casts did the
  72. right thing.  And if you report it, they're more apt to respond with 
  73. a yawn, because for every customer that complains that the computer
  74. won't compute, there are a hundred asking about whether it will generate
  75. DLL's, or whether it comes with a full set of Windows 3.1 headers, or
  76. whatever.
  77.  
  78. C is the implementation language for UNIX.  Like all good languages it's
  79. been extended and does lots of things well, but chars and ints are
  80. structs and pointers are its reason for being, and floats are something
  81. else it also does.  FORTRAN was designed to do floating-point numerical
  82. calculations with efficiency comparing favorably with hand-coding.
  83. That's ITS reason for being, most customers have that expectation
  84. and most vendors meet that expectation.
  85.  
  86. Cheers,
  87.  
  88. --Dan Smith
  89. -- 
  90. Daniel P. B. Smith
  91. dpbsmith@world.std.com
  92.