E32 Answer


bad cos( 0.050000 ) = 0.975000
bad sin( 0.050000 ) = 0.050000

good cos( 0.050000 ) = 0.998750
good sin( 0.050000 ) = 0.049979

Comments: Declaring a function static enables you to use a name that might otherwise conflict with the name of a function in another file.

In this case, the static functions are the ones that main() uses, and the external ones from the math library are the ones that goodMath uses.


* --- goodMath.c --- */ #include <math.h> void goodMath( double angle ) { printf("good cos( %lf ) = %lf\n", angle, cos(angle) ); printf("good sin( %lf ) = %lf\n", angle, sin(angle) ); }
/* --- main.c --- */ static double sin( double x ) { return x; } static double cos( double x ) { return 1 - x/2.0; } void badMath( double angle ) { printf("bad cos( %lf ) = %lf\n", angle, cos(angle) ); printf("bad sin( %lf ) = %lf\n\n", angle, sin(angle) ); } main() { double angle = .05 ; /* radians */ badMath ( angle ); goodMath( angle ); system("pause"); }