# # canola - canon canola 1614p emulator # Copyright (C) 2011 Peter Miller # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License, version 3, as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License along # with this program. If not, see . # # ---------- Card-Pocket-Begin ------------------------------------------- # Title: MS-1: sin(x) # Conditions: # -10**16 < x < 10**16 # x: Degree # Accuracy: 10 digits # Style: blank # ---------- Card-Pocket-End --------------------------------------------- ; ; ; This uses a Taylor series expansion of sin(x) ; See http://en.wikipedia.org/wiki/Trigonometric_functions#Series_definitions ; for more information. ; ; x**3 x**5 x**7 ; sin(x) = x - ---- + ---- - ---- + ... ; 3! 5! 7! ; ; initial X in degress is in the X register ; M14 contains the series sum ; M13 contains the (2n+1)! being constructed ; M12 contains the x**2 ; ; Rather than convert into the -pi..pi range, it converts into the ; 0..2*pi range, so it is going to converge slightly more slowly for ; values > pi. ; SFJ $201 / ; first we must turn degrees into radians 360 * SM14 1 FLOOR 0 ; this modifies the following += to truncate to integer -= ; negatively, so that we subtract it from RM14 ; the unbounded angle += ; now we have a value in the range 0..<1 * 6.28318530718 ; and convert to radians [first source of inaccuracy] += ; in the range 0..<2*pi SM14 ; M14 = x 2 SM13 ; M13 = 2 RM14 * -= SM12 ; M12 = -x ** 2 FJ $200 RV * RM12 / RM13 += 1 M13 RV / RM13 += M14 1 M13 RV * .1 += MJ $200 ; only stop when it's zero CS MJ $200 RM14 ; recall series sum SRJ