Xref: utzoo comp.lang.fortran:4208 comp.lang.c:34355 Path: utzoo!utgpu!watserv1!watmath!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!wuarchive!uunet!validgh!dgh From: dgh@validgh.com (David G. Hough on validgh) Newsgroups: comp.lang.fortran,comp.lang.c Subject: Fortran vs C Message-ID: <219@validgh.com> Date: 29 Nov 90 14:06:06 GMT Followup-To: poster Organization: validgh, PO Box 20370, San Jose, CA 95160 Lines: 26 There have been recent statements that functions like sqrt() are equivalent in Fortran and C. This is incorrect. In C, sqrt() is simply a function invocation. It has no known semantics unless #include has been seen, in which case ANSI-C knows that it is a double-precision function of a double-precision argument. Thanks to the default conversions, you can use sqrt on float arguments with correct results, but they may take twice as long to compute as necessary if you really meant sqrtf(). sqrt() won't work on long double arguments unless long double == double. In Fortran, sqrt() is a generic intrinsic function, really an operator like +. Its semantics are known to the compiler. The precision of the sqrt operation can match that of the operand. As mentioned by others, ANSI-C defines exception handling for the sqrt() function and not for operators. On high-performance implementations, error checking, involving a conditional test and branch, can take as long as the sqrt operation itself, even if performed inline. System V implementations are worse, requiring an external call to matherr(), although this will be removed in a future version of SVID. -- David Hough dgh@validgh.com uunet!validgh!dgh na.hough@na-net.stanford.edu