#
# 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-15: tanh(x)
; Color: green
; Style: blank
; ---------- Card-Pocket-End ---------------------------------------------
;
; http://en.wikipedia.org/wiki/Hyperbolic_function
;
; M10 => sign of result
; M11 => x
; M12 => series sum
; M13 => previous term
; M14 => factorial denominator
;
SFJ $301
MJ $312
SM11 ; x
1
UJ $313
FJ $312
CS
SM11
1
CS
FJ $313
SM10 ; sign of result
RM11
13
-=
MJ $314
1 ; if (x >= 13) result => 1
UJ $400
FJ $314
RM11
/
2
+=
;
; at this point we calculate exp(x)
;
SM11 ; x
SM12 ; series sum
SM13 ; previous term
1
SM14
M12 ; add to series sum
fj $401 ; missing, does it go here?
1
M14
RM13 ; previous term
*
RM11
/
RM14
+=
SM13 ; save previous term
M12 ; add to series sum
MJ $401
CS
MJ $401
RM12 ; exp(x/2)
*
+= ; = exp(x) ...this accounts for the x/2 at the start
*
+= ; = exp(2*x)
1
+=
/
2
RV
-=
1
+= ; 1 - 2/(1 + exp(2x))
FJ $400
*
RM10
+=
SRJ