Challenge program.

Greg F. Shay gfs at abvax.UUCP
Sat May 14 00:20:52 AEST 1988


I had a need for a subroutine that I found a bit of an interesting challenge.

 ------>	Write sin(x) using integer math only. No lookup tables!

short sin(x)
	short x;
{}

Some further detail, I used a 16 bit fixed point format for input and output:

short x;   
	S IIIIIIII.FFFFFFF
	|   Integer   Fraction
	sign bit	

I used 32 bit integer for intermediate computations.
The interesting result is that the accuracy of the result is as good as the
accuracy of the number representation (that is the error is no larger than
the error due to the limited 7 bit fraction representation (1/128)).

Hint #1:  Justify the number of terms in the power series you use.
Hint #2:  My solution uses 2 intermediate integers and exactly 5 integer 
	  multiplies.
	
Have fun!  I'll post my solution for comparison later.
		
		Greg Shay
	mandrill |
	decvax   |..!abvax!gfs
	pyramid  |



More information about the Comp.lang.c mailing list