rpl 0.12.0 → 0.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +74 -0
- data/bin/rpl +8 -10
- data/lib/rpl/dictionary.rb +12 -12
- data/lib/rpl/interpreter.rb +4 -4
- data/lib/rpl/words/branch.rb +39 -39
- data/lib/rpl/words/display.rb +12 -12
- data/lib/rpl/words/filesystem.rb +25 -25
- data/lib/rpl/words/general.rb +32 -32
- data/lib/rpl/words/list.rb +34 -34
- data/lib/rpl/words/logarithm.rb +21 -21
- data/lib/rpl/words/mode.rb +24 -24
- data/lib/rpl/words/operations-complexes.rb +53 -53
- data/lib/rpl/words/operations-reals-complexes.rb +185 -185
- data/lib/rpl/words/operations-reals.rb +105 -105
- data/lib/rpl/words/program.rb +19 -19
- data/lib/rpl/words/repl.rb +65 -65
- data/lib/rpl/words/stack.rb +133 -133
- data/lib/rpl/words/store.rb +74 -74
- data/lib/rpl/words/string-list.rb +11 -11
- data/lib/rpl/words/string.rb +73 -73
- data/lib/rpl/words/test.rb +103 -103
- data/lib/rpl/words/time-date.rb +20 -20
- data/lib/rpl/words/trig.rb +47 -47
- data/lib/rpl.rb +3 -3
- metadata +6 -4
data/lib/rpl/words/logarithm.rb
CHANGED
@@ -10,105 +10,105 @@ module RplLang
|
|
10
10
|
|
11
11
|
category = 'Logs on reals and complexes'
|
12
12
|
|
13
|
-
@dictionary.add_word( ['ℇ', 'e'],
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
# @dictionary.add_word( ['ln'],
|
13
|
+
@dictionary.add_word!( ['ℇ', 'e'],
|
14
|
+
category,
|
15
|
+
'( … -- ℇ ) push ℇ',
|
16
|
+
proc do
|
17
|
+
@stack << Types.new_object( RplNumeric, BigMath.E( RplNumeric.precision ) )
|
18
|
+
end )
|
19
|
+
|
20
|
+
# @dictionary.add_word!( ['ln'],
|
21
21
|
# category,
|
22
22
|
# 'logarithm base e',
|
23
23
|
# proc do
|
24
24
|
|
25
25
|
# end )
|
26
26
|
|
27
|
-
# @dictionary.add_word( ['lnp1'],
|
27
|
+
# @dictionary.add_word!( ['lnp1'],
|
28
28
|
# category,
|
29
29
|
# 'ln(1+x) which is useful when x is close to 0',
|
30
30
|
# proc do
|
31
31
|
|
32
32
|
# end )
|
33
33
|
|
34
|
-
# @dictionary.add_word( ['exp'],
|
34
|
+
# @dictionary.add_word!( ['exp'],
|
35
35
|
# category,
|
36
36
|
# 'exponential',
|
37
37
|
# proc do
|
38
38
|
|
39
39
|
# end )
|
40
40
|
|
41
|
-
# @dictionary.add_word( ['expm'],
|
41
|
+
# @dictionary.add_word!( ['expm'],
|
42
42
|
# category,
|
43
43
|
# 'exp(x)-1 which is useful when x is close to 0',
|
44
44
|
# proc do
|
45
45
|
|
46
46
|
# end )
|
47
47
|
|
48
|
-
# @dictionary.add_word( ['log10'],
|
48
|
+
# @dictionary.add_word!( ['log10'],
|
49
49
|
# category,
|
50
50
|
# 'logarithm base 10',
|
51
51
|
# proc do
|
52
52
|
|
53
53
|
# end )
|
54
54
|
|
55
|
-
# @dictionary.add_word( ['alog10'],
|
55
|
+
# @dictionary.add_word!( ['alog10'],
|
56
56
|
# category,
|
57
57
|
# 'exponential base 10',
|
58
58
|
# proc do
|
59
59
|
|
60
60
|
# end )
|
61
61
|
|
62
|
-
# @dictionary.add_word( ['log2'],
|
62
|
+
# @dictionary.add_word!( ['log2'],
|
63
63
|
# category,
|
64
64
|
# 'logarithm base 2',
|
65
65
|
# proc do
|
66
66
|
|
67
67
|
# end )
|
68
68
|
|
69
|
-
# @dictionary.add_word( ['alog2'],
|
69
|
+
# @dictionary.add_word!( ['alog2'],
|
70
70
|
# category,
|
71
71
|
# 'exponential base 2',
|
72
72
|
# proc do
|
73
73
|
|
74
74
|
# end )
|
75
75
|
|
76
|
-
# @dictionary.add_word( ['sinh'],
|
76
|
+
# @dictionary.add_word!( ['sinh'],
|
77
77
|
# category,
|
78
78
|
# 'hyperbolic sine',
|
79
79
|
# proc do
|
80
80
|
|
81
81
|
# end )
|
82
82
|
|
83
|
-
# @dictionary.add_word( ['asinh'],
|
83
|
+
# @dictionary.add_word!( ['asinh'],
|
84
84
|
# category,
|
85
85
|
# 'inverse hyperbolic sine',
|
86
86
|
# proc do
|
87
87
|
|
88
88
|
# end )
|
89
89
|
|
90
|
-
# @dictionary.add_word( ['cosh'],
|
90
|
+
# @dictionary.add_word!( ['cosh'],
|
91
91
|
# category,
|
92
92
|
# 'hyperbolic cosine',
|
93
93
|
# proc do
|
94
94
|
|
95
95
|
# end )
|
96
96
|
|
97
|
-
# @dictionary.add_word( ['acosh'],
|
97
|
+
# @dictionary.add_word!( ['acosh'],
|
98
98
|
# category,
|
99
99
|
# 'inverse hyperbolic cosine',
|
100
100
|
# proc do
|
101
101
|
|
102
102
|
# end )
|
103
103
|
|
104
|
-
# @dictionary.add_word( ['tanh'],
|
104
|
+
# @dictionary.add_word!( ['tanh'],
|
105
105
|
# category,
|
106
106
|
# 'hyperbolic tangent',
|
107
107
|
# proc do
|
108
108
|
|
109
109
|
# end )
|
110
110
|
|
111
|
-
# @dictionary.add_word( ['atanh'],
|
111
|
+
# @dictionary.add_word!( ['atanh'],
|
112
112
|
# category,
|
113
113
|
# 'inverse hyperbolic tangent',
|
114
114
|
# proc do
|
data/lib/rpl/words/mode.rb
CHANGED
@@ -10,36 +10,36 @@ module RplLang
|
|
10
10
|
|
11
11
|
category = 'Mode'
|
12
12
|
|
13
|
-
@dictionary.add_word( ['prec'],
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
@dictionary.add_word!( ['prec'],
|
14
|
+
category,
|
15
|
+
'( a -- ) set precision to a',
|
16
|
+
proc do
|
17
|
+
args = stack_extract( [[RplNumeric]] )
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
@dictionary.add_word( ['default'],
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
@dictionary.add_word( ['type'],
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
19
|
+
RplNumeric.precision = args[0].value
|
20
|
+
end )
|
21
|
+
@dictionary.add_word!( ['default'],
|
22
|
+
category,
|
23
|
+
'( -- ) set default precision',
|
24
|
+
proc do
|
25
|
+
RplNumeric.default_precision
|
26
|
+
end )
|
27
|
+
@dictionary.add_word!( ['type'],
|
28
|
+
category,
|
29
|
+
'( a -- s ) type of a as a string',
|
30
|
+
proc do
|
31
|
+
args = stack_extract( [:any] )
|
32
32
|
|
33
|
-
|
34
|
-
|
33
|
+
@stack << Types.new_object( RplString, "\"#{args[0].class.to_s[10..]}\"" )
|
34
|
+
end )
|
35
35
|
|
36
|
-
# @dictionary.add_word( ['std'],
|
36
|
+
# @dictionary.add_word!( ['std'],
|
37
37
|
# proc { __todo } ) # standard floating numbers representation. ex: std
|
38
|
-
# @dictionary.add_word( ['fix'],
|
38
|
+
# @dictionary.add_word!( ['fix'],
|
39
39
|
# proc { __todo } ) # fixed point representation. ex: 6 fix
|
40
|
-
# @dictionary.add_word( ['sci'],
|
40
|
+
# @dictionary.add_word!( ['sci'],
|
41
41
|
# proc { __todo } ) # scientific floating point representation. ex: 20 sci
|
42
|
-
# @dictionary.add_word( ['round'],
|
42
|
+
# @dictionary.add_word!( ['round'],
|
43
43
|
# proc { __todo } ) # set float rounding mode. ex: ["nearest", "toward zero", "toward +inf", "toward -inf", "away from zero"] round
|
44
44
|
end
|
45
45
|
end
|
@@ -10,65 +10,65 @@ module RplLang
|
|
10
10
|
|
11
11
|
category = 'Operations on complexes'
|
12
12
|
|
13
|
-
@dictionary.add_word( ['re'],
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
@dictionary.add_word( ['im'],
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
@dictionary.add_word( ['conj'],
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
@dictionary.add_word( ['arg'],
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
@dictionary.add_word( ['c→r', 'c->r'],
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
@dictionary.add_word( ['r→c', 'r->c'],
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
# @dictionary.add_word( ['p→r', 'p->r'],
|
13
|
+
@dictionary.add_word!( ['re'],
|
14
|
+
category,
|
15
|
+
'( c -- n ) complex real part',
|
16
|
+
proc do
|
17
|
+
args = stack_extract( [[RplComplex]] )
|
18
|
+
|
19
|
+
@stack << RplNumeric.new( args[0].value.real )
|
20
|
+
end )
|
21
|
+
|
22
|
+
@dictionary.add_word!( ['im'],
|
23
|
+
category,
|
24
|
+
'( c -- n ) complex imaginary part',
|
25
|
+
proc do
|
26
|
+
args = stack_extract( [[RplComplex]] )
|
27
|
+
|
28
|
+
@stack << RplNumeric.new( args[0].value.imaginary )
|
29
|
+
end )
|
30
|
+
|
31
|
+
@dictionary.add_word!( ['conj'],
|
32
|
+
category,
|
33
|
+
'( c -- c ) complex conjugate',
|
34
|
+
proc do
|
35
|
+
args = stack_extract( [[RplComplex]] )
|
36
|
+
|
37
|
+
@stack << RplComplex.new( args[0].value.conjugate )
|
38
|
+
end )
|
39
|
+
|
40
|
+
@dictionary.add_word!( ['arg'],
|
41
|
+
category,
|
42
|
+
'( c -- n ) complex argument in radians',
|
43
|
+
proc do
|
44
|
+
args = stack_extract( [[RplComplex]] )
|
45
|
+
|
46
|
+
@stack << RplNumeric.new( args[0].value.arg )
|
47
|
+
end )
|
48
|
+
|
49
|
+
@dictionary.add_word!( ['c→r', 'c->r'],
|
50
|
+
category,
|
51
|
+
'( c -- n n ) transform a complex in 2 reals',
|
52
|
+
Types.new_object( RplProgram, '« dup re swap im »' ) )
|
53
|
+
|
54
|
+
@dictionary.add_word!( ['r→c', 'r->c'],
|
55
|
+
category,
|
56
|
+
'( n n -- c ) transform 2 reals in a complex',
|
57
|
+
proc do
|
58
|
+
args = stack_extract( [[RplNumeric], [RplNumeric]] )
|
59
|
+
|
60
|
+
complex_as_string = "(#{args[1].value}#{args[0].value.positive? ? '+' : ''}#{args[0].value}i)"
|
61
|
+
@stack << RplComplex.new( complex_as_string )
|
62
|
+
end )
|
63
|
+
|
64
|
+
# @dictionary.add_word!( ['p→r', 'p->r'],
|
65
65
|
# category,
|
66
66
|
# 'cartesian to polar',
|
67
67
|
# proc do
|
68
68
|
|
69
69
|
# end )
|
70
70
|
|
71
|
-
# @dictionary.add_word( ['r→p', 'r->p'],
|
71
|
+
# @dictionary.add_word!( ['r→p', 'r->p'],
|
72
72
|
# category,
|
73
73
|
# 'polar to cartesian',
|
74
74
|
# proc do
|