1 \ Floating point arithmetic
3 ( Cheating for now by using forth.jl CODE/END-CODE to
4 access Julia's floating point support. This isn't
5 at all portable. That said, the year is 2016 and
6 I've only cheated for words that have corresponding
7 x87 FPU instructions, so I don't feel too bad! )
10 b = reinterpret(Float64, popPS())
11 a = reinterpret(Float64, popPS())
12 pushPS(reinterpret(Int64, a+b))
16 b = reinterpret(Float64, popPS())
17 a = reinterpret(Float64, popPS())
18 pushPS(reinterpret(Int64, a-b))
22 b = reinterpret(Float64, popPS())
23 a = reinterpret(Float64, popPS())
24 pushPS(reinterpret(Int64, a*b + 0.0))
28 b = reinterpret(Float64, popPS())
29 a = reinterpret(Float64, popPS())
30 pushPS(reinterpret(Int64, a/b + 0.0))
34 b = reinterpret(Float64, popPS())
35 a = reinterpret(Float64, popPS())
36 pushPS(reinterpret(Int64, a^b + 0.0))
40 a = reinterpret(Float64, popPS())
41 pushPS(reinterpret(Int64, sqrt(a)))
45 b = reinterpret(Float64, popPS())
46 a = reinterpret(Float64, popPS())
55 b = reinterpret(Float64, popPS())
56 a = reinterpret(Float64, popPS())
65 b = reinterpret(Float64, popPS())
66 a = reinterpret(Float64, popPS())
81 b = reinterpret(Float64, popPS())
82 a = reinterpret(Float64, popPS())
83 pushPS(reinterpret(Int64, a%b + 0.0))
87 a = reinterpret(Float64, popPS())
88 pushPS(reinterpret(Int64, log(a)))
92 a = reinterpret(Float64, popPS())
93 pushPS(reinterpret(Int64, exp(a)))
97 a = reinterpret(Float64, popPS())
98 pushPS(reinterpret(Int64, sin(a)))
102 a = reinterpret(Float64, popPS())
103 pushPS(reinterpret(Int64, cos(a)))
107 a = reinterpret(Float64, popPS())
108 pushPS(reinterpret(Int64, tan(a)))
112 a = reinterpret(Float64, popPS())
113 pushPS(reinterpret(Int64, atan(a)))
117 a = reinterpret(Float64, popPS())
126 a = reinterpret(Float64, popPS())
135 pushPS(reinterpret(Int64, Float64(popPS())))
139 a = reinterpret(Float64, popPS())
140 pushPS(Int64(round(a)))
144 a = reinterpret(Float64, popPS())
145 pushPS(reinterpret(Int64, abs(a)))
149 a = reinterpret(Float64, popPS())
150 pushPS(reinterpret(Int64, round(a)))
163 [ -1 i->f ] literal ;
166 [ 10 i->f ] literal ;
169 flog [ 10 i->f flog ] literal f/ ;
178 dup 1.0 fmod dup 0.0 <> if
188 dup 1.0 fmod dup 0.0 <> if
198 : fasin ( float -- res )
200 dup f* 1.0 swap f- fsqrt
206 : facos ( float -- res )
207 dup f* 1.0 swap f/ 1.0 f- fsqrt
215 : ftail ( float prec -- )
216 dup 0<= if 2drop exit then
224 1.0 fmod dup 0.0 f> if
234 : f.plain ( float -- )
250 precision @ over flog10 floor f->i -
254 : f.scientific ( float -- )
265 dup flog10 floor dup -rot
266 10.0 swap f^ f/ f.plain
270 : f.nospace ( float -- )
271 dup fabs dup 1000000 i->f f>= swap 1 i->f 10000 i->f f/ f< or if