Path: utzoo!attcan!uunet!husc6!mailrus!tut.cis.ohio-state.edu!mandrill!abvax!gfs From: gfs@abvax.UUCP (Greg F. Shay) Newsgroups: comp.graphics Subject: Challenge program. Keywords: Write sin(x) using integer math. Message-ID: <327@abvax.UUCP> Date: 13 May 88 14:56:13 GMT Organization: Allen-Bradley Company, Inc; Industrial Computer Division, Highland Heights, OH Lines: 32 In writing a graphics rotation routine for a stand alone, ROM demo, 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 |