1use melodium_core::*;
2use melodium_macro::{check, mel_function, mel_treatment};
3
4#[mel_function]
6pub fn pow(base: f64, exponent: f64) -> f64 {
7 base.powf(exponent)
8}
9
10#[mel_function]
12pub fn cbrt(value: f64) -> f64 {
13 value.cbrt()
14}
15
16#[mel_function]
18pub fn ln(value: f64) -> f64 {
19 value.ln()
20}
21
22#[mel_function]
24pub fn log(value: f64, base: f64) -> f64 {
25 value.log(base)
26}
27
28#[mel_function]
30pub fn sqrt(value: f64) -> f64 {
31 value.sqrt()
32}
33
34#[mel_function]
36pub fn acos(value: f64) -> f64 {
37 value.acos()
38}
39
40#[mel_function]
42pub fn acosh(value: f64) -> f64 {
43 value.acosh()
44}
45
46#[mel_function]
48pub fn asin(value: f64) -> f64 {
49 value.asin()
50}
51
52#[mel_function]
54pub fn asinh(value: f64) -> f64 {
55 value.asinh()
56}
57
58#[mel_function]
60pub fn atan(value: f64) -> f64 {
61 value.atan()
62}
63
64#[mel_function]
66pub fn atanh(value: f64) -> f64 {
67 value.atanh()
68}
69
70#[mel_function]
72pub fn cos(value: f64) -> f64 {
73 value.cos()
74}
75
76#[mel_function]
78pub fn cosh(value: f64) -> f64 {
79 value.cosh()
80}
81
82#[mel_function]
84pub fn sin(value: f64) -> f64 {
85 value.sin()
86}
87
88#[mel_function]
90pub fn sinh(value: f64) -> f64 {
91 value.sinh()
92}
93
94#[mel_function]
96pub fn tan(value: f64) -> f64 {
97 value.tan()
98}
99
100#[mel_function]
102pub fn tanh(value: f64) -> f64 {
103 value.tanh()
104}
105
106#[mel_treatment(
110 input base Stream<f64>
111 input exponent Stream<f64>
112 output power Stream<f64>
113)]
114pub async fn pow() {
115 while let (Ok(base), Ok(exp)) = (base.recv_one_f64().await, exponent.recv_one_f64().await) {
116 check!(power.send_one_f64(base.powf(exp)).await)
117 }
118}
119
120#[mel_treatment(
122 input value Stream<f64>
123 output root Stream<f64>
124)]
125pub async fn cbrt() {
126 while let Ok(values) = value.recv_f64().await {
127 check!(
128 root.send_f64(values.into_iter().map(|v| v.cbrt()).collect())
129 .await
130 )
131 }
132}
133
134#[mel_treatment(
136 input value Stream<f64>
137 output log Stream<f64>
138)]
139pub async fn ln() {
140 while let Ok(values) = value.recv_f64().await {
141 check!(
142 log.send_f64(values.into_iter().map(|v| v.ln()).collect())
143 .await
144 )
145 }
146}
147
148#[mel_treatment(
150 input base Stream<f64>
151 input value Stream<f64>
152 output log Stream<f64>
153)]
154pub async fn log() {
155 while let (Ok(base), Ok(value)) = (base.recv_one_f64().await, value.recv_one_f64().await) {
156 check!(log.send_one_f64(value.log(base)).await)
157 }
158}
159
160#[mel_treatment(
162 input value Stream<f64>
163 output root Stream<f64>
164)]
165pub async fn sqrt() {
166 while let Ok(values) = value.recv_f64().await {
167 check!(
168 root.send_f64(values.into_iter().map(|v| v.sqrt()).collect())
169 .await
170 )
171 }
172}
173
174#[mel_treatment(
178 input value Stream<f64>
179 output acos Stream<f64>
180)]
181pub async fn acos() {
182 while let Ok(values) = value.recv_f64().await {
183 check!(
184 acos.send_f64(values.into_iter().map(|v| v.acos()).collect())
185 .await
186 )
187 }
188}
189
190#[mel_treatment(
192 input value Stream<f64>
193 output acosh Stream<f64>
194)]
195pub async fn acosh() {
196 while let Ok(values) = value.recv_f64().await {
197 check!(
198 acosh
199 .send_f64(values.into_iter().map(|v| v.acosh()).collect())
200 .await
201 )
202 }
203}
204
205#[mel_treatment(
209 input value Stream<f64>
210 output asin Stream<f64>
211)]
212pub async fn asin() {
213 while let Ok(values) = value.recv_f64().await {
214 check!(
215 asin.send_f64(values.into_iter().map(|v| v.asin()).collect())
216 .await
217 )
218 }
219}
220
221#[mel_treatment(
223 input value Stream<f64>
224 output asinh Stream<f64>
225)]
226pub async fn asinh() {
227 while let Ok(values) = value.recv_f64().await {
228 check!(
229 asinh
230 .send_f64(values.into_iter().map(|v| v.asinh()).collect())
231 .await
232 )
233 }
234}
235
236#[mel_treatment(
240 input value Stream<f64>
241 output atan Stream<f64>
242)]
243pub async fn atan() {
244 while let Ok(values) = value.recv_f64().await {
245 check!(
246 atan.send_f64(values.into_iter().map(|v| v.atan()).collect())
247 .await
248 )
249 }
250}
251
252#[mel_treatment(
254 input value Stream<f64>
255 output atanh Stream<f64>
256)]
257pub async fn atanh() {
258 while let Ok(values) = value.recv_f64().await {
259 check!(
260 atanh
261 .send_f64(values.into_iter().map(|v| v.atanh()).collect())
262 .await
263 )
264 }
265}
266
267#[mel_treatment(
269 input value Stream<f64>
270 output cos Stream<f64>
271)]
272pub async fn cos() {
273 while let Ok(values) = value.recv_f64().await {
274 check!(
275 cos.send_f64(values.into_iter().map(|v| v.cos()).collect())
276 .await
277 )
278 }
279}
280
281#[mel_treatment(
283 input value Stream<f64>
284 output cosh Stream<f64>
285)]
286pub async fn cosh() {
287 while let Ok(values) = value.recv_f64().await {
288 check!(
289 cosh.send_f64(values.into_iter().map(|v| v.cosh()).collect())
290 .await
291 )
292 }
293}
294
295#[mel_treatment(
297 input value Stream<f64>
298 output sin Stream<f64>
299)]
300pub async fn sin() {
301 while let Ok(values) = value.recv_f64().await {
302 check!(
303 sin.send_f64(values.into_iter().map(|v| v.sin()).collect())
304 .await
305 )
306 }
307}
308
309#[mel_treatment(
311 input value Stream<f64>
312 output sinh Stream<f64>
313)]
314pub async fn sinh() {
315 while let Ok(values) = value.recv_f64().await {
316 check!(
317 sinh.send_f64(values.into_iter().map(|v| v.sinh()).collect())
318 .await
319 )
320 }
321}
322
323#[mel_treatment(
325 input value Stream<f64>
326 output tan Stream<f64>
327)]
328pub async fn tan() {
329 while let Ok(values) = value.recv_f64().await {
330 check!(
331 tan.send_f64(values.into_iter().map(|v| v.tan()).collect())
332 .await
333 )
334 }
335}
336
337#[mel_treatment(
339 input value Stream<f64>
340 output tanh Stream<f64>
341)]
342pub async fn tanh() {
343 while let Ok(values) = value.recv_f64().await {
344 check!(
345 tanh.send_f64(values.into_iter().map(|v| v.tanh()).collect())
346 .await
347 )
348 }
349}
350
351#[mel_function]
353pub fn add(a: f64, b: f64) -> f64 {
354 a + b
355}
356
357#[mel_function]
359pub fn div(dividend: f64, divisor: f64) -> f64 {
360 dividend / divisor
361}
362
363#[mel_function]
365pub fn mult(a: f64, b: f64) -> f64 {
366 a * b
367}
368
369#[mel_function]
371pub fn rem(dividend: f64, divisor: f64) -> f64 {
372 dividend % divisor
373}
374
375#[mel_function]
377pub fn sub(a: f64, b: f64) -> f64 {
378 a - b
379}
380
381#[mel_function]
383pub fn gt(a: f64, b: f64) -> bool {
384 a > b
385}
386
387#[mel_function]
389pub fn lt(a: f64, b: f64) -> bool {
390 a < b
391}
392
393#[mel_function]
395pub fn min(a: f64, b: f64) -> f64 {
396 a.min(b)
397}
398
399#[mel_function]
401pub fn max(a: f64, b: f64) -> f64 {
402 a.max(b)
403}
404
405#[mel_treatment(
409 input a Stream<f64>
410 input b Stream<f64>
411 output sum Stream<f64>
412)]
413pub async fn add() {
414 while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
415 check!(sum.send_one_f64(a + b).await)
416 }
417}
418
419#[mel_treatment(
423 input a Stream<f64>
424 input b Stream<f64>
425 output quotient Stream<f64>
426)]
427pub async fn div() {
428 while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
429 check!(quotient.send_one_f64(a / b).await)
430 }
431}
432
433#[mel_treatment(
437 input a Stream<f64>
438 input b Stream<f64>
439 output product Stream<f64>
440)]
441pub async fn mult() {
442 while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
443 check!(product.send_one_f64(a * b).await)
444 }
445}
446
447#[mel_treatment(
451 input a Stream<f64>
452 input b Stream<f64>
453 output remainder Stream<f64>
454)]
455pub async fn rem() {
456 while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
457 check!(remainder.send_one_f64(a % b).await)
458 }
459}
460
461#[mel_treatment(
465 input a Stream<f64>
466 input b Stream<f64>
467 output diff Stream<f64>
468)]
469pub async fn sub() {
470 while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
471 check!(diff.send_one_f64(a - b).await)
472 }
473}
474
475#[mel_treatment(
477 input a Stream<f64>
478 input b Stream<f64>
479 output min Stream<f64>
480)]
481pub async fn min() {
482 while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
483 check!(min.send_one_f64(a.min(b)).await)
484 }
485}
486
487#[mel_treatment(
489 input a Stream<f64>
490 input b Stream<f64>
491 output max Stream<f64>
492)]
493pub async fn max() {
494 while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
495 check!(max.send_one_f64(a.max(b)).await)
496 }
497}
498
499#[mel_treatment(
501 input a Stream<f64>
502 input b Stream<f64>
503 output is Stream<bool>
504)]
505pub async fn lower_than() {
506 while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
507 check!(is.send_one_bool(a < b).await)
508 }
509}
510
511#[mel_treatment(
513 input a Stream<f64>
514 input b Stream<f64>
515 output is Stream<bool>
516)]
517pub async fn greater_than() {
518 while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
519 check!(is.send_one_bool(a > b).await)
520 }
521}
522
523#[mel_function]
525pub fn abs(value: f64) -> f64 {
526 value.abs()
527}
528
529#[mel_treatment(
531 input value Stream<f64>
532 output abs Stream<f64>
533)]
534pub async fn abs() {
535 while let Ok(values) = value.recv_f64().await {
536 check!(
537 abs.send_f64(values.into_iter().map(|v| v.abs()).collect())
538 .await
539 )
540 }
541}