1 # coding: utf-8
2 # frozen_string_literal: true
3
4
5
6 module Umu
7
8 module Value
9
10 module Core
11
12 class Math < Top
13 define_class_method(
14 :meth_make_pi,
15 :pi, [],
16 [], VCAN::Float
17 )
18 def self.meth_make_pi(_loc, _env, _event)
19 VC.make_float ::Math::PI
20 end
21
22
23 define_class_method(
24 :meth_make_e,
25 :e, [],
26 [], VCAN::Float
27 )
28 def self.meth_make_e(_loc, _env, _event)
29 VC.make_float ::Math::E
30 end
31
32
33 define_class_method(
34 :meth_sin,
35 :sin, [],
36 [VCAN::Float], VCAN::Float
37 )
38 def self.meth_sin(_loc, _env, _event, this)
39 ASSERT.kind_of this, VCAN::Float
40
41 VC.make_float ::Math.sin(this.val)
42 end
43
44
45 define_class_method(
46 :meth_cos,
47 :cos, [],
48 [VCAN::Float], VCAN::Float
49 )
50 def self.meth_cos(_loc, _env, _event, this)
51 ASSERT.kind_of this, VCAN::Float
52
53 VC.make_float ::Math.cos(this.val)
54 end
55
56
57 define_class_method(
58 :meth_tan,
59 :tan, [],
60 [VCAN::Float], VCAN::Float
61 )
62 def self.meth_tan(_loc, _env, _event, this)
63 ASSERT.kind_of this, VCAN::Float
64
65 VC.make_float ::Math.tan(this.val)
66 end
67
68
69 define_class_method(
70 :meth_asin,
71 :asin, [],
72 [VCAN::Float], VCAN::Float
73 )
74 def self.meth_asin(_loc, _env, _event, this)
75 ASSERT.kind_of this, VCAN::Float
76
77 VC.make_float ::Math.asin(this.val)
78 end
79
80
81 define_class_method(
82 :meth_acos,
83 :acos, [],
84 [VCAN::Float], VCAN::Float
85 )
86 def self.meth_acos(_loc, _env, _event, this)
87 ASSERT.kind_of this, VCAN::Float
88
89 VC.make_float ::Math.acos(this.val)
90 end
91
92
93 define_class_method(
94 :meth_atan,
95 :atan, [],
96 [VCAN::Float], VCAN::Float
97 )
98 def self.meth_atan(_loc, _env, _event, this)
99 ASSERT.kind_of this, VCAN::Float
100
101 VC.make_float ::Math.atan(this.val)
102 end
103
104
105 define_class_method(
106 :meth_atan2,
107 :'atan2-y:x:', [],
108 [VCAN::Float, VCAN::Float], VCAN::Float
109 )
110 def self.meth_atan2(_loc, _env, _event, y, x)
111 ASSERT.kind_of y, VCAN::Float
112 ASSERT.kind_of x, VCAN::Float
113
114 VC.make_float ::Math.atan2(y.val, x.val)
115 end
116
117
118 define_class_method(
119 :meth_sinh,
120 :sinh, [],
121 [VCAN::Float], VCAN::Float
122 )
123 def self.meth_sinh(_loc, _env, _event, this)
124 ASSERT.kind_of this, VCAN::Float
125
126 VC.make_float ::Math.sinh(this.val)
127 end
128
129
130 define_class_method(
131 :meth_cosh,
132 :cosh, [],
133 [VCAN::Float], VCAN::Float
134 )
135 def self.meth_cosh(_loc, _env, _event, this)
136 ASSERT.kind_of this, VCAN::Float
137
138 VC.make_float ::Math.cosh(this.val)
139 end
140
141
142 define_class_method(
143 :meth_tanh,
144 :tanh, [],
145 [VCAN::Float], VCAN::Float
146 )
147 def self.meth_tanh(_loc, _env, _event, this)
148 ASSERT.kind_of this, VCAN::Float
149
150 VC.make_float ::Math.tanh(this.val)
151 end
152
153
154 define_class_method(
155 :meth_exp,
156 :exp, [],
157 [VCAN::Float], VCAN::Float
158 )
159 def self.meth_exp(_loc, _env, _event, this)
160 ASSERT.kind_of this, VCAN::Float
161
162 VC.make_float ::Math.exp(this.val)
163 end
164
165
166 define_class_method(
167 :meth_log,
168 :log, [],
169 [VCAN::Float], VCAN::Float
170 )
171 def self.meth_log(_loc, _env, _event, this)
172 ASSERT.kind_of this, VCAN::Float
173
174 VC.make_float ::Math.log(this.val)
175 end
176
177
178 define_class_method(
179 :meth_log10,
180 :log10, [],
181 [VCAN::Float], VCAN::Float
182 )
183 def self.meth_log10(_loc, _env, _event, this)
184 ASSERT.kind_of this, VCAN::Float
185
186 VC.make_float ::Math.log10(this.val)
187 end
188
189
190 define_class_method(
191 :meth_sqrt,
192 :sqrt, [],
193 [VCAN::Float], VCAN::Float
194 )
195 def self.meth_sqrt(_loc, _env, _event, this)
196 ASSERT.kind_of this, VCAN::Float
197
198 VC.make_float ::Math.sqrt(this.val)
199 end
200
201
202 define_class_method(
203 :meth_ldexp,
204 :ldexp, [],
205 [VCAN::Float, VCAN::Int], VCAN::Float
206 )
207 def self.meth_ldexp(_loc, _env, _event, this, other)
208 ASSERT.kind_of this, VCAN::Float
209 ASSERT.kind_of other, VCAN::Int
210
211 VC.make_float ::Math.ldexp(this.val, other.val)
212 end
213
214
215 define_class_method(
216 :meth_frexp,
217 :frexp, [],
218 [VCAN::Float], VCP::Tuple
219 )
220 def self.meth_frexp(_loc, _env, _event, this)
221 ASSERT.kind_of this, VCAN::Float
222
223 fract, expon = ::Math.frexp this.val
224
225 VC.make_tuple(
226 VC.make_float(fract.to_f),
227 VC.make_integer(expon.to_i)
228 )
229 end
230
231
232 define_class_method(
233 :meth_divmod,
234 :divmod, [],
235 [VCAN::Float, VCAN::Float], VCP::Tuple
236 )
237 def self.meth_divmod(_loc, _env, _event, this, other)
238 ASSERT.kind_of this, VCAN::Float
239 ASSERT.kind_of other, VCAN::Float
240
241 fract, integ = this.val.divmod other.val
242
243 VC.make_tuple(
244 VC.make_float(fract.to_f),
245 VC.make_float(integ.to_f)
246 )
247 end
248
249
250 end
251 Math.freeze
252
253
254 module_function
255
256 def make_pi
257 PI
258 end
259
260
261 def make_e
262 E
263 end
264
265 end # Umu::Value::Core
266
267 end # Umu::Value
268
269 end # Umu