-
Notifications
You must be signed in to change notification settings - Fork 2
/
const_ratio.asm
151 lines (139 loc) · 3.33 KB
/
const_ratio.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Copyright Jacques Deschênes 2019,2020,2021
;; This file is part of stm32_eforth
;;
;; stm8_eforth is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; stm32_eforth 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 stm32_eforth. If not, see <http:;;www.gnu.org/licenses/>.
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;--------------------------------------------------------------------
; Irrationals constants
; expressed as 2 integers ratio
; aproximation. These are to be used with scaling operators */ and */MOD
; REF: https://www.forth.com/starting-forth/5-fixed-point-arithmetic/
;---------------------------------------------------------------------
; PI ( -- 355 113 )
; precision 8.5e-8
; usage example to compute circle area
; : CAREA DUP * PI */ ;
;
.word LINK
LINK=.
.byte 2
.ascii "PI"
PII:
subw x,#2*CELLL
ldw y,#355
ldw (2,x),y
ldw y,#113
ldw (x),y
ret
; SQRT2 ( -- 19601 13860 )
; precision: 1.5e-9
; usage example to compute Voltage peek to peek from Vrms
; : VPP SQRT2 */ 2 * ;
;
.word LINK
LINK=.
.byte 5
.ascii "SQRT2"
SQRT2:
subw x,#2*CELLL
ldw y,#19601
ldw (2,x),y
ldw y,#13860
ldw (x),y
ret
; SQRT3 ( -- 18817 10864 )
; precision: 1.1e-9
;
.word LINK
LINK=.
.byte 5
.ascii "SQRT3"
SQRT3:
subw x,#2*CELLL
ldw y,#18817
ldw (2,x),y
ldw y,#10864
ldw (x),y
ret
; E ( -- 28667 10546 )
; precision: 5.5e-9
; natural log base
.word LINK
LINK=.
.byte 1
.ascii "E"
ENEPER:
subw x,#2*CELLL
ldw y,#28667
ldw (2,x),y
ldw y,#10546
ldw (x),y
ret
; SQRT10 ( -- 22936 7253 )
; precision: 5.7e-9
.word LINK
LINK=.
.byte 6
.ascii "SQRT10"
SQRT10:
subw x,#2*CELLL
ldw y,#22936
ldw (2,x),y
ldw y,#7253
ldw (x),y
ret
; 12RT2 ( -- 26797 25293 )
; precision: 1.0e-9
; used in music to compute well tempered scale
.word LINK
LINK=.
.byte 5
.ascii "12RT2"
RT12_2:
subw x,#2*CELLL
ldw y,#26797
ldw (2,x),y
ldw y,#25293
ldw (x),y
ret
; LOG2s ( -- 2040 11103 )
; log(2)/1.6384
; precision: 1.1e-8
.word LINK
LINK=.
.byte 5
.ascii "LOG2S"
LOG2S:
subw x,#2*CELLL
ldw y,#2040
ldw (2,x),y
ldw y,#11103
ldw (x),y
ret
; LN2 ( -- 485 11464 )
; ln(2)/16.384
; precision: 1.0e-7
.word LINK
LINK=.
.byte 4
.ascii "LN2S"
LN2S:
subw x,#2*CELLL
ldw y,#485
ldw (2,x),y
ldw y,#11464
ldw (x),y
ret