#
# 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-12: ln(x)
; Color: green
; Style: blank
; ---------- Card-Pocket-End ---------------------------------------------
;
SFJ $212
SQRT ; the series converses faster if x is closer to 1
SQRT
SQRT
SQRT
;
; http://en.wikipedia.org/wiki/Natural_logarithm
;
; ln(x) = ln((1+y)/(1-y))
; = 2y (1 + (y**2)/3 + (y**4)/5 + (y**6)/7 + (y**8)/9 + ... )
; = 2 (y + (y**3)/3 + (y**5)/5 + (y**7)/7 + (y**9)/9 + ... )
;
; where y = (x - 1) / (x + 1)
;
; M14 => odd denominator
; M13 => series term numerator
; M12 => series sum
; M11 => y**2
;
SM13 ; x (temporarily)
1
SM14
M13 ; m13 = x + 1
-= ; x - 1
/
RM13 ; x + 1
+= ; "y" = (x - 1) / (x + 1)
SM13 ; first term numerator
SM12 ; series sum
*
+=
SM11 ; y**2
FJ $309
2
M14
RM13
*
RM11
/
SM13
RM14
+=
M12
MJ $309
CS
MJ $309
RM12
*
32
+=
SRJ