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 most
6 CPUs implement these operations - even the trig functions,
7 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))
28 b = reinterpret(Float64, popPS())
29 a = reinterpret(Float64, popPS())
30 pushPS(reinterpret(Int64, a/b))
34 b = reinterpret(Float64, popPS())
35 a = reinterpret(Float64, popPS())
36 pushPS(reinterpret(Int64, a^b))
40 b = reinterpret(Float64, popPS())
41 a = reinterpret(Float64, popPS())
50 b = reinterpret(Float64, popPS())
51 a = reinterpret(Float64, popPS())
60 b = reinterpret(Float64, popPS())
61 a = reinterpret(Float64, popPS())
76 b = reinterpret(Float64, popPS())
77 a = reinterpret(Float64, popPS())
78 pushPS(reinterpret(Int64, a%b))
82 a = reinterpret(Float64, popPS())
83 pushPS(reinterpret(Int64, log(a)))
87 a = reinterpret(Float64, popPS())
88 pushPS(reinterpret(Int64, exp(a)))
92 a = reinterpret(Float64, popPS())
101 a = reinterpret(Float64, popPS())
110 pushPS(reinterpret(Int64, Float64(popPS())))
114 a = reinterpret(Float64, popPS())
115 pushPS(Int64(round(a)))
128 [ -1 i->f ] literal ;
131 [ 10 i->f ] literal ;
134 flog [ 10 i->f flog ] literal f/ ;
146 dup 1.0 fmod dup 0.0 <> if
158 : ftail ( float prec -- )
159 dup 0<= if 2drop exit then
167 1.0 fmod dup 0.0 f> if
177 : f.plain ( float -- )
193 precision @ over flog10 floor f->i -
197 : f.scientific ( float -- )
208 dup flog10 floor dup -rot
209 10.0 swap f^ f/ f.plain
214 dup fabs dup 1000000 i->f f>= swap 1 i->f 10000 i->f f/ f< or if