This code computes sin using three ways. FIRST: cordic algorithm sin(a+b) = sin(a) cos(b) + cos(a) sin (b) cos(a+b) = cos(a) cos(b) - sin(a) sin(b) SECOND: Truncated Maclaurin polynomial of order 6 sin(x) = x - (x^3)/6 + x^5/120 THIRD: C-library sin function ================================================= ================ The three ways ================= ---------------- cordic algorithm --------------- 1. Convert float to binary as (unsigned int) example: x = .25 ----> bin = 2 base10 its binary representation (0000 0000 0000 0000 0000 0000 0000 0010) base2 x = .125 ----> bin = 4 base10 its binary representation (0000 0000 0000 0000 0000 0000 0000 0100) base2 2. calculate sin of the binary number recursivly sin(a+b) = sin(a) cos(b) + cos(a) sin(b) cos(a+b) = cos(a) cos(b) - sin(a) sin(b) where sin(a), and cos(a) are retrieved from a table of pre-calculated sines and cosines cos(b), and sin(b) are called recursivly example: sin(0.1101) = sin(0.1 + 0.0101) = sin(0.1) cos(0.0101) + cos(0.1) sin(0.0101) = sins[1] cosRec(0.0101) + coss[1] sinRec(0.0101) and so on.... where sins and coss are arrays of pre-calculated sines and cosines of values sin(1/2^i) where 1 <= i <= 32 ---------------- Maclaurin Polynomial ----------- By simply applaying this function sin(x) = x - (x^3)/6 + x^5/120 --------------- C-library ----------------------- Using the sin() function from math.h ================================================= ================ INPUT ========================= Float numbers. Any number that is out of range is going to stop the program RANGE (0 <= x < 1) to stop the program, just enter any number that is out of range for example (1). ================================================= ================ OUTPUT ========================= interpreting output: "x-value CORDIC Maclaurin c-library Duration for CORDIC" x cordicSin(x) macSin(x) sin(x) ##.###### seconds ---------------- Sample input/output ----------- terminal command: Haytham_HW_09 < in > out ++++++++++++++++ in +++++++++++++++++++ 0.5 0.25 0.125 0.1 0.01 0.001 0.04 0.03 +++++++++++++++++++++++++++++++++++++++ ++++++++++++++++ out ++++++++++++++++++ x-value CORDIC Maclaurin c-library Duration for CORDIC 0.5 0.479425 0.479427 0.479426 1.90735e-06 seconds 0.25 0.247404 0.247404 0.247404 4.05312e-06 seconds 0.125 0.124675 0.124675 0.124675 2.14577e-06 seconds 0.1 0.0998334 0.0998334 0.0998334 0.000983 seconds 0.01 0.00999983 0.00999983 0.00999983 0.00048399 seconds 0.001 0.001 0.001 0.001 0.000133038 seconds 0.04 0.0399893 0.0399893 0.0399893 0.000442028 seconds 0.03 0.0299955 0.0299955 0.0299955 0.00190592 seconds +++++++++++++++++++++++++++++++++++++++ -------------------------------------------------- ==================================================