Comparing Java, C, and Fortran Values


In this section we'll compare the results generated by our user -defined logarithm and hyperbolic trigonometric math functions against values obtained using the intrinsic C and Fortran functions. The C++ math functions will mirror the results of C so we won't include them in the table. Neither C nor Fortran offers a gamma function as an intrinsic function, although the gamma function is available in one of the commercially available Fortran libraries (IMSL or NAG, for instance).

Table 17.1. Result Comparison

M ETHOD

J AVA

C

F ORTRAN

log10(4.3)

0.6334684555748

0.6334684555795

0.633468449

log3(4.3)

1.3276886102082

N/A

N/A

sinh(1.3)

1.6983824372926

1.6983824372926

1.69838238

cosh(1.3)

1.9709142303266

1.9709142303266

1.97091413

tanh(1.3)

0.8617231593133

0.8617231593133

0.861723125

The value "4.3" was passed to each of the Java, C, and Fortran logarithm methods and "1.3" was passed to the hyperbolic trig methods. The results from the various methods are shown in Table 17.1.

The Java and C results are very close. The values from our user-defined hyperbolic trigonometric methods match the C library function values exactly. The common logarithm values match to 11 decimal places. There is a slight difference in the C/Java and Fortran results, but this is something intrinsic to the way the functions are implemented in each language. Neither C nor Fortran offers an arbitrary base logarithm function as an intrinsic function.



Technical Java. Applications for Science and Engineering
Technical Java: Applications for Science and Engineering
ISBN: 0131018159
EAN: 2147483647
Year: 2003
Pages: 281
Authors: Grant Palmer

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net