Skip to main content

ops_mel/
f64.rs

1use melodium_core::*;
2use melodium_macro::{check, mel_function, mel_treatment};
3
4/// Elevates `base` from `exponent`
5#[mel_function]
6pub fn pow(base: f64, exponent: f64) -> f64 {
7    base.powf(exponent)
8}
9
10/// Computes cube root of `value`
11#[mel_function]
12pub fn cbrt(value: f64) -> f64 {
13    value.cbrt()
14}
15
16/// Computes natural logarithm of `value`
17#[mel_function]
18pub fn ln(value: f64) -> f64 {
19    value.ln()
20}
21
22/// Computes logarithm of `value` with `base`
23#[mel_function]
24pub fn log(value: f64, base: f64) -> f64 {
25    value.log(base)
26}
27
28/// Computes quare root of `value`
29#[mel_function]
30pub fn sqrt(value: f64) -> f64 {
31    value.sqrt()
32}
33
34/// Computes arccosine of `value` (in radians)
35#[mel_function]
36pub fn acos(value: f64) -> f64 {
37    value.acos()
38}
39
40/// Computes inverse hyperbolic cosine of `value`
41#[mel_function]
42pub fn acosh(value: f64) -> f64 {
43    value.acosh()
44}
45
46/// Computes arcsine of `value` (in radians)
47#[mel_function]
48pub fn asin(value: f64) -> f64 {
49    value.asin()
50}
51
52/// Computes inverse hyperbolic sine of `value`
53#[mel_function]
54pub fn asinh(value: f64) -> f64 {
55    value.asinh()
56}
57
58/// Computes arctangent of `value` (in radians)
59#[mel_function]
60pub fn atan(value: f64) -> f64 {
61    value.atan()
62}
63
64/// Computes inverse hyperbolic tangent of `value`
65#[mel_function]
66pub fn atanh(value: f64) -> f64 {
67    value.atanh()
68}
69
70/// Computes cosine of `value` (in radians)
71#[mel_function]
72pub fn cos(value: f64) -> f64 {
73    value.cos()
74}
75
76/// Computes hyperbolic cosine of `value`
77#[mel_function]
78pub fn cosh(value: f64) -> f64 {
79    value.cosh()
80}
81
82/// Computes sine of `value` (in radians)
83#[mel_function]
84pub fn sin(value: f64) -> f64 {
85    value.sin()
86}
87
88/// Computes hyperbolic sine of `value`
89#[mel_function]
90pub fn sinh(value: f64) -> f64 {
91    value.sinh()
92}
93
94/// Computes tangent of `value` (in radians)
95#[mel_function]
96pub fn tan(value: f64) -> f64 {
97    value.tan()
98}
99
100/// Computes hyperbolic tangent of `value`
101#[mel_function]
102pub fn tanh(value: f64) -> f64 {
103    value.tanh()
104}
105
106/// Elevates values from a stream of `f64` to the power of another one.
107///
108/// Values passed through `base` are elevated to the power of `exponent`.
109#[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/// Computes the cube roots from a stream of `f64`.
121#[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/// Computes the natural logarithms of a stream of `f64`.
135#[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/// Computes logarithms from a stream of `f64` with the base of another one.
149#[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/// Computes the square roots from a stream of `f64`.
161#[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/// Computes arccosine (in radians) of a stream of `f64`.
175///
176/// Gives values in the range [0, pi] or not-a-number if outside range [-1, 1].
177#[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/// Computes inverse hyperbolic cosine of a stream of `f64`.
191#[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/// Computes arcsine (in radians) of a stream of `f64`.
206///
207/// Gives values in the range [0, pi] or not-a-number if outside range [-1, 1].
208#[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/// Computes inverse hyperbolic sine of a stream of `f64`.
222#[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/// Computes arctangent (in radians) of a stream of `f64`.
237///
238/// Gives values in the range [-pi/2, pi/2].
239#[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/// Computes inverse hyperbolic tangent of a stream of  `f64`.
253#[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/// Computes cosine (in radians) of a stream of `f64`.
268#[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/// Computes hyberbolic cosine of a stream of `f64`.
282#[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/// Computes sine (in radians) of a stream of `f64`.
296#[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/// Computes hyberbolic sine of a stream of `f64`.
310#[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/// Computes tangent (in radians) of a stream of `f64`.
324#[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/// Computes hyberbolic tangent of a stream of `f64`.
338#[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/// Add `a` and `b`
352#[mel_function]
353pub fn add(a: f64, b: f64) -> f64 {
354    a + b
355}
356
357/// Divide `dividend` by `divisor`
358#[mel_function]
359pub fn div(dividend: f64, divisor: f64) -> f64 {
360    dividend / divisor
361}
362
363/// Multiply `a` by `b`
364#[mel_function]
365pub fn mult(a: f64, b: f64) -> f64 {
366    a * b
367}
368
369/// Get the remainder of `dividend` by `divisor`
370#[mel_function]
371pub fn rem(dividend: f64, divisor: f64) -> f64 {
372    dividend % divisor
373}
374
375/// Substract `b` from `a`
376#[mel_function]
377pub fn sub(a: f64, b: f64) -> f64 {
378    a - b
379}
380
381/// Tells whether `a` is strictly greater than `b`.
382#[mel_function]
383pub fn gt(a: f64, b: f64) -> bool {
384    a > b
385}
386
387/// Tells whether `a` is strictly lower than `b`.
388#[mel_function]
389pub fn lt(a: f64, b: f64) -> bool {
390    a < b
391}
392
393/// Compares and gives the minimum of two values.
394#[mel_function]
395pub fn min(a: f64, b: f64) -> f64 {
396    a.min(b)
397}
398
399/// Compares and gives the maximum of two values.
400#[mel_function]
401pub fn max(a: f64, b: f64) -> f64 {
402    a.max(b)
403}
404
405/// Add values from two streams of `f64`.
406///
407/// Values passed through `a` & `b` are added and send in sum.
408#[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/// Divide values from two streams of `f64`.
420///
421/// Every `a` number passed through the stream is divided by `b` counterpart.
422#[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/// Multiply values from two streams of `f64`.
434///
435/// Every `a` number passed through the stream is multiplied by `b` counterpart.
436#[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/// Give the remainder of the division from two streams of `f64`.
448///
449/// Every `a` number passed through the stream is divided by `b` and the remainder is outputted.
450#[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/// Substract values from two streams of `f64`.
462///
463/// Every `a` number passed through the stream get `b` substracted.
464#[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/// Compares and gives the minimum of two values.
476#[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/// Compares and gives the maximum of two values.
488#[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/// Determine whether `a` is strictly lower than `b`
500#[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/// Determine whether `a` is strictly greater than `b`
512#[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/// Get absolute value
524#[mel_function]
525pub fn abs(value: f64) -> f64 {
526    value.abs()
527}
528
529/// Get the absolute values from a stream of `f64`.
530#[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}