paddlec 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,955 @@
1
+ /* Copyright (C) 2019 Théotime Bollengier <theotime.bollengier@gmail.com>
2
+ *
3
+ * This file is part of PaddleC
4
+ *
5
+ * PaddleC is free software: you can redistribute it and/or modify
6
+ * it under the terms of the GNU General Public License as published by
7
+ * the Free Software Foundation, either version 3 of the License, or
8
+ * (at your option) any later version.
9
+ *
10
+ * PaddleC is distributed in the hope that it will be useful,
11
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ * GNU General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with PaddleC. If not, see <https://www.gnu.org/licenses/>.
17
+ */
18
+
19
+ #include <stdlib.h>
20
+ #include <math.h>
21
+ #include "libpaddlec.h"
22
+
23
+ #ifndef NAN
24
+ #define NAN nanf("")
25
+ #endif
26
+
27
+ /* Min Max */
28
+
29
+ float pdlc_buffer_max_of_self(const pdlc_buffer_t *fbuf)
30
+ {
31
+ size_t i;
32
+ float m = NAN;
33
+
34
+ for (i = 0; i < fbuf->length; i++)
35
+ m = fmaxf(m, fbuf->data[i]);
36
+
37
+ return m;
38
+ }
39
+
40
+
41
+ float pdlc_buffer_min_of_self(const pdlc_buffer_t *fbuf)
42
+ {
43
+ size_t i;
44
+ float m = NAN;
45
+
46
+ for (i = 0; i < fbuf->length; i++)
47
+ m = fminf(m, fbuf->data[i]);
48
+
49
+ return m;
50
+ }
51
+
52
+
53
+ void pdlc_buffer_minmax_of_self(const pdlc_buffer_t *fbuf, float *mi, float *ma)
54
+ {
55
+ size_t i;
56
+ float lmi = NAN;
57
+ float lma = NAN;
58
+
59
+ for (i = 0; i < fbuf->length; i++) {
60
+ lmi = fminf(lmi, fbuf->data[i]);
61
+ lma = fmaxf(lma, fbuf->data[i]);
62
+ }
63
+
64
+ *mi = lmi;
65
+ *ma = lma;
66
+ }
67
+
68
+
69
+ pdlc_complex_t pdlc_complex_buffer_max_of_self(const pdlc_complex_buffer_t *cbuf)
70
+ {
71
+ size_t i;
72
+ pdlc_complex_t m;
73
+ m.real = NAN;
74
+ m.imag = NAN;
75
+
76
+ for (i = 0; i < cbuf->length; i++) {
77
+ m.real = fmaxf(m.real, cbuf->data[i].real);
78
+ m.imag = fmaxf(m.imag, cbuf->data[i].imag);
79
+ }
80
+
81
+ return m;
82
+ }
83
+
84
+
85
+ pdlc_complex_t pdlc_complex_buffer_min_of_self(const pdlc_complex_buffer_t *cbuf)
86
+ {
87
+ size_t i;
88
+ pdlc_complex_t m;
89
+ m.real = NAN;
90
+ m.imag = NAN;
91
+
92
+ for (i = 0; i < cbuf->length; i++) {
93
+ m.real = fminf(m.real, cbuf->data[i].real);
94
+ m.imag = fminf(m.imag, cbuf->data[i].imag);
95
+ }
96
+
97
+ return m;
98
+ }
99
+
100
+
101
+ void pdlc_complex_buffer_minmax_of_self(const pdlc_complex_buffer_t *cbuf, pdlc_complex_t *mi, pdlc_complex_t *ma)
102
+ {
103
+ size_t i;
104
+ pdlc_complex_t lmi, lma;
105
+ lmi.real = NAN;
106
+ lmi.imag = NAN;
107
+ lma.real = NAN;
108
+ lma.imag = NAN;
109
+
110
+ for (i = 0; i < cbuf->length; i++) {
111
+ lmi.real = fminf(lmi.real, cbuf->data[i].real);
112
+ lmi.imag = fminf(lmi.imag, cbuf->data[i].imag);
113
+ lma.real = fmaxf(lma.real, cbuf->data[i].real);
114
+ lma.imag = fmaxf(lma.imag, cbuf->data[i].imag);
115
+ }
116
+
117
+ *mi = lmi;
118
+ *ma = lma;
119
+ }
120
+
121
+
122
+ pdlc_buffer_t* pdlc_fb_fb_min(const pdlc_buffer_t *lhs, const pdlc_buffer_t *rhs, pdlc_buffer_t *res)
123
+ {
124
+ size_t i;
125
+ size_t len = lhs->length;
126
+
127
+ if (len > rhs->length)
128
+ len = rhs->length;
129
+
130
+ if (!res)
131
+ res = pdlc_buffer_new(len);
132
+ else
133
+ pdlc_buffer_resize(res, len, 0);
134
+
135
+ for (i = 0; i < len; i++)
136
+ res->data[i] = fminf(lhs->data[i], rhs->data[i]);
137
+
138
+ return res;
139
+ }
140
+
141
+
142
+ pdlc_buffer_t* pdlc_fb_fb_min_inplace(pdlc_buffer_t *lhs, const pdlc_buffer_t *rhs)
143
+ {
144
+ size_t i;
145
+ size_t len = lhs->length;
146
+
147
+ if (len > rhs->length)
148
+ len = rhs->length;
149
+
150
+ for (i = 0; i < len; i++)
151
+ lhs->data[i] = fminf(lhs->data[i], rhs->data[i]);
152
+
153
+ return lhs;
154
+ }
155
+
156
+
157
+ pdlc_buffer_t* pdlc_fb_fs_min(const pdlc_buffer_t *lhs, float rhs, pdlc_buffer_t *res)
158
+ {
159
+ size_t i;
160
+ const size_t len = lhs->length;
161
+
162
+ if (!res)
163
+ res = pdlc_buffer_new(len);
164
+ else
165
+ pdlc_buffer_resize(res, len, 0);
166
+
167
+ for (i = 0; i < len; i++)
168
+ res->data[i] = fminf(lhs->data[i], rhs);
169
+
170
+ return res;
171
+ }
172
+
173
+
174
+ pdlc_buffer_t* pdlc_fb_fs_min_inplace(pdlc_buffer_t *lhs, float rhs)
175
+ {
176
+ size_t i;
177
+ const size_t len = lhs->length;
178
+
179
+ for (i = 0; i < len; i++)
180
+ lhs->data[i] = fminf(lhs->data[i], rhs);
181
+
182
+ return lhs;
183
+ }
184
+
185
+
186
+ pdlc_complex_buffer_t* pdlc_cb_cb_min(const pdlc_complex_buffer_t *lhs, const pdlc_complex_buffer_t *rhs, pdlc_complex_buffer_t *res)
187
+ {
188
+ size_t i;
189
+ size_t len = lhs->length;
190
+
191
+ if (len > rhs->length)
192
+ len = rhs->length;
193
+
194
+ if (!res)
195
+ res = pdlc_complex_buffer_new(len);
196
+ else
197
+ pdlc_complex_buffer_resize(res, len, 0);
198
+
199
+ for (i = 0; i < len; i++) {
200
+ res->data[i].real = fminf(lhs->data[i].real, rhs->data[i].real);
201
+ res->data[i].imag = fminf(lhs->data[i].imag, rhs->data[i].imag);
202
+ }
203
+
204
+ return res;
205
+ }
206
+
207
+
208
+ pdlc_complex_buffer_t* pdlc_cb_cb_min_inplace(pdlc_complex_buffer_t *lhs, const pdlc_complex_buffer_t *rhs)
209
+ {
210
+ size_t i;
211
+ size_t len = lhs->length;
212
+
213
+ if (len > rhs->length)
214
+ len = rhs->length;
215
+
216
+ for (i = 0; i < len; i++) {
217
+ lhs->data[i].real = fminf(lhs->data[i].real, rhs->data[i].real);
218
+ lhs->data[i].imag = fminf(lhs->data[i].imag, rhs->data[i].imag);
219
+ }
220
+
221
+ return lhs;
222
+ }
223
+
224
+
225
+ pdlc_complex_buffer_t* pdlc_cb_cs_min(const pdlc_complex_buffer_t *lhs, pdlc_complex_t rhs, pdlc_complex_buffer_t *res)
226
+ {
227
+ size_t i;
228
+ const size_t len = lhs->length;
229
+
230
+ if (!res)
231
+ res = pdlc_complex_buffer_new(len);
232
+ else
233
+ pdlc_complex_buffer_resize(res, len, 0);
234
+
235
+ for (i = 0; i < len; i++) {
236
+ res->data[i].real = fminf(lhs->data[i].real, rhs.real);
237
+ res->data[i].imag = fminf(lhs->data[i].imag, rhs.imag);
238
+ }
239
+
240
+ return res;
241
+ }
242
+
243
+
244
+ pdlc_complex_buffer_t* pdlc_cb_cs_min_inplace(pdlc_complex_buffer_t *lhs, pdlc_complex_t rhs)
245
+ {
246
+ size_t i;
247
+ const size_t len = lhs->length;
248
+
249
+ for (i = 0; i < len; i++) {
250
+ lhs->data[i].real = fminf(lhs->data[i].real, rhs.real);
251
+ lhs->data[i].imag = fminf(lhs->data[i].imag, rhs.imag);
252
+ }
253
+
254
+ return lhs;
255
+ }
256
+
257
+
258
+ pdlc_complex_buffer_t* pdlc_cb_fb_min(const pdlc_complex_buffer_t *lhs, const pdlc_buffer_t *rhs, pdlc_complex_buffer_t *res)
259
+ {
260
+ size_t i;
261
+ size_t len = lhs->length;
262
+
263
+ if (len > rhs->length)
264
+ len = rhs->length;
265
+
266
+ if (!res)
267
+ res = pdlc_complex_buffer_new(len);
268
+ else
269
+ pdlc_complex_buffer_resize(res, len, 0);
270
+
271
+ for (i = 0; i < len; i++) {
272
+ res->data[i].real = fminf(lhs->data[i].real, rhs->data[i]);
273
+ res->data[i].imag = fminf(lhs->data[i].imag, rhs->data[i]);
274
+ }
275
+
276
+ return res;
277
+ }
278
+
279
+
280
+ pdlc_complex_buffer_t* pdlc_cb_fb_min_inplace(pdlc_complex_buffer_t *lhs, const pdlc_buffer_t *rhs)
281
+ {
282
+ size_t i;
283
+ size_t len = lhs->length;
284
+
285
+ if (len > rhs->length)
286
+ len = rhs->length;
287
+
288
+ for (i = 0; i < len; i++) {
289
+ lhs->data[i].real = fminf(lhs->data[i].real, rhs->data[i]);
290
+ lhs->data[i].imag = fminf(lhs->data[i].imag, rhs->data[i]);
291
+ }
292
+
293
+ return lhs;
294
+ }
295
+
296
+
297
+ pdlc_complex_buffer_t* pdlc_cb_fs_min(const pdlc_complex_buffer_t *lhs, float rhs, pdlc_complex_buffer_t *res)
298
+ {
299
+ size_t i;
300
+ const size_t len = lhs->length;
301
+
302
+ if (!res)
303
+ res = pdlc_complex_buffer_new(len);
304
+ else
305
+ pdlc_complex_buffer_resize(res, len, 0);
306
+
307
+ for (i = 0; i < len; i++) {
308
+ res->data[i].real = fminf(lhs->data[i].real, rhs);
309
+ res->data[i].imag = fminf(lhs->data[i].imag, rhs);
310
+ }
311
+
312
+ return res;
313
+ }
314
+
315
+
316
+ pdlc_complex_buffer_t* pdlc_cb_fs_min_inplace(pdlc_complex_buffer_t *lhs, float rhs)
317
+ {
318
+ size_t i;
319
+ const size_t len = lhs->length;
320
+
321
+ for (i = 0; i < len; i++) {
322
+ lhs->data[i].real = fminf(lhs->data[i].real, rhs);
323
+ lhs->data[i].imag = fminf(lhs->data[i].imag, rhs);
324
+ }
325
+
326
+ return lhs;
327
+ }
328
+
329
+
330
+ pdlc_buffer_t* pdlc_fb_fb_max(const pdlc_buffer_t *lhs, const pdlc_buffer_t *rhs, pdlc_buffer_t *res)
331
+ {
332
+ size_t i;
333
+ size_t len = lhs->length;
334
+
335
+ if (len > rhs->length)
336
+ len = rhs->length;
337
+
338
+ if (!res)
339
+ res = pdlc_buffer_new(len);
340
+ else
341
+ pdlc_buffer_resize(res, len, 0);
342
+
343
+ for (i = 0; i < len; i++)
344
+ res->data[i] = fmaxf(lhs->data[i], rhs->data[i]);
345
+
346
+ return res;
347
+ }
348
+
349
+
350
+ pdlc_buffer_t* pdlc_fb_fb_max_inplace(pdlc_buffer_t *lhs, const pdlc_buffer_t *rhs)
351
+ {
352
+ size_t i;
353
+ size_t len = lhs->length;
354
+
355
+ if (len > rhs->length)
356
+ len = rhs->length;
357
+
358
+ for (i = 0; i < len; i++)
359
+ lhs->data[i] = fmaxf(lhs->data[i], rhs->data[i]);
360
+
361
+ return lhs;
362
+ }
363
+
364
+
365
+ pdlc_buffer_t* pdlc_fb_fs_max(const pdlc_buffer_t *lhs, float rhs, pdlc_buffer_t *res)
366
+ {
367
+ size_t i;
368
+ const size_t len = lhs->length;
369
+
370
+ if (!res)
371
+ res = pdlc_buffer_new(len);
372
+ else
373
+ pdlc_buffer_resize(res, len, 0);
374
+
375
+ for (i = 0; i < len; i++)
376
+ res->data[i] = fmaxf(lhs->data[i], rhs);
377
+
378
+ return res;
379
+ }
380
+
381
+
382
+ pdlc_buffer_t* pdlc_fb_fs_max_inplace(pdlc_buffer_t *lhs, float rhs)
383
+ {
384
+ size_t i;
385
+ const size_t len = lhs->length;
386
+
387
+ for (i = 0; i < len; i++)
388
+ lhs->data[i] = fmaxf(lhs->data[i], rhs);
389
+
390
+ return lhs;
391
+ }
392
+
393
+
394
+ pdlc_complex_buffer_t* pdlc_cb_cb_max(const pdlc_complex_buffer_t *lhs, const pdlc_complex_buffer_t *rhs, pdlc_complex_buffer_t *res)
395
+ {
396
+ size_t i;
397
+ size_t len = lhs->length;
398
+
399
+ if (len > rhs->length)
400
+ len = rhs->length;
401
+
402
+ if (!res)
403
+ res = pdlc_complex_buffer_new(len);
404
+ else
405
+ pdlc_complex_buffer_resize(res, len, 0);
406
+
407
+ for (i = 0; i < len; i++) {
408
+ res->data[i].real = fmaxf(lhs->data[i].real, rhs->data[i].real);
409
+ res->data[i].imag = fmaxf(lhs->data[i].imag, rhs->data[i].imag);
410
+ }
411
+
412
+ return res;
413
+ }
414
+
415
+
416
+ pdlc_complex_buffer_t* pdlc_cb_cb_max_inplace(pdlc_complex_buffer_t *lhs, const pdlc_complex_buffer_t *rhs)
417
+ {
418
+ size_t i;
419
+ size_t len = lhs->length;
420
+
421
+ if (len > rhs->length)
422
+ len = rhs->length;
423
+
424
+ for (i = 0; i < len; i++) {
425
+ lhs->data[i].real = fmaxf(lhs->data[i].real, rhs->data[i].real);
426
+ lhs->data[i].imag = fmaxf(lhs->data[i].imag, rhs->data[i].imag);
427
+ }
428
+
429
+ return lhs;
430
+ }
431
+
432
+
433
+ pdlc_complex_buffer_t* pdlc_cb_cs_max(const pdlc_complex_buffer_t *lhs, pdlc_complex_t rhs, pdlc_complex_buffer_t *res)
434
+ {
435
+ size_t i;
436
+ const size_t len = lhs->length;
437
+
438
+ if (!res)
439
+ res = pdlc_complex_buffer_new(len);
440
+ else
441
+ pdlc_complex_buffer_resize(res, len, 0);
442
+
443
+ for (i = 0; i < len; i++) {
444
+ res->data[i].real = fmaxf(lhs->data[i].real, rhs.real);
445
+ res->data[i].imag = fmaxf(lhs->data[i].imag, rhs.imag);
446
+ }
447
+
448
+ return res;
449
+ }
450
+
451
+
452
+ pdlc_complex_buffer_t* pdlc_cb_cs_max_inplace(pdlc_complex_buffer_t *lhs, pdlc_complex_t rhs)
453
+ {
454
+ size_t i;
455
+ const size_t len = lhs->length;
456
+
457
+ for (i = 0; i < len; i++) {
458
+ lhs->data[i].real = fmaxf(lhs->data[i].real, rhs.real);
459
+ lhs->data[i].imag = fmaxf(lhs->data[i].imag, rhs.imag);
460
+ }
461
+
462
+ return lhs;
463
+ }
464
+
465
+
466
+ pdlc_complex_buffer_t* pdlc_cb_fb_max(const pdlc_complex_buffer_t *lhs, const pdlc_buffer_t *rhs, pdlc_complex_buffer_t *res)
467
+ {
468
+ size_t i;
469
+ size_t len = lhs->length;
470
+
471
+ if (len > rhs->length)
472
+ len = rhs->length;
473
+
474
+ if (!res)
475
+ res = pdlc_complex_buffer_new(len);
476
+ else
477
+ pdlc_complex_buffer_resize(res, len, 0);
478
+
479
+ for (i = 0; i < len; i++) {
480
+ res->data[i].real = fmaxf(lhs->data[i].real, rhs->data[i]);
481
+ res->data[i].imag = fmaxf(lhs->data[i].imag, rhs->data[i]);
482
+ }
483
+
484
+ return res;
485
+ }
486
+
487
+
488
+ pdlc_complex_buffer_t* pdlc_cb_fb_max_inplace(pdlc_complex_buffer_t *lhs, const pdlc_buffer_t *rhs)
489
+ {
490
+ size_t i;
491
+ size_t len = lhs->length;
492
+
493
+ if (len > rhs->length)
494
+ len = rhs->length;
495
+
496
+ for (i = 0; i < len; i++) {
497
+ lhs->data[i].real = fmaxf(lhs->data[i].real, rhs->data[i]);
498
+ lhs->data[i].imag = fmaxf(lhs->data[i].imag, rhs->data[i]);
499
+ }
500
+
501
+ return lhs;
502
+ }
503
+
504
+
505
+ pdlc_complex_buffer_t* pdlc_cb_fs_max(const pdlc_complex_buffer_t *lhs, float rhs, pdlc_complex_buffer_t *res)
506
+ {
507
+ size_t i;
508
+ const size_t len = lhs->length;
509
+
510
+ if (!res)
511
+ res = pdlc_complex_buffer_new(len);
512
+ else
513
+ pdlc_complex_buffer_resize(res, len, 0);
514
+
515
+ for (i = 0; i < len; i++) {
516
+ res->data[i].real = fmaxf(lhs->data[i].real, rhs);
517
+ res->data[i].imag = fmaxf(lhs->data[i].imag, rhs);
518
+ }
519
+
520
+ return res;
521
+ }
522
+
523
+
524
+ pdlc_complex_buffer_t* pdlc_cb_fs_max_inplace(pdlc_complex_buffer_t *lhs, float rhs)
525
+ {
526
+ size_t i;
527
+ const size_t len = lhs->length;
528
+
529
+ for (i = 0; i < len; i++) {
530
+ lhs->data[i].real = fmaxf(lhs->data[i].real, rhs);
531
+ lhs->data[i].imag = fmaxf(lhs->data[i].imag, rhs);
532
+ }
533
+
534
+ return lhs;
535
+ }
536
+
537
+
538
+ pdlc_buffer_t* pdlc_buffer_clipp(const pdlc_buffer_t *fbuf, float mi, float ma, pdlc_buffer_t *res)
539
+ {
540
+ const size_t len = fbuf->length;
541
+ size_t i;
542
+ float tmp;
543
+
544
+ if (mi > ma) {
545
+ tmp = mi;
546
+ mi = ma;
547
+ ma = tmp;
548
+ }
549
+
550
+ if (!res)
551
+ res = pdlc_buffer_new(len);
552
+ else
553
+ pdlc_buffer_resize(res, len, 0);
554
+
555
+ for (i = 0; i < len; i++)
556
+ res->data[i] = fminf(ma, fmaxf(mi, fbuf->data[i]));
557
+
558
+ return res;
559
+ }
560
+
561
+
562
+ pdlc_buffer_t* pdlc_buffer_clipp_inplace(pdlc_buffer_t *fbuf, float mi, float ma)
563
+ {
564
+ const size_t len = fbuf->length;
565
+ size_t i;
566
+ float tmp;
567
+
568
+ if (mi > ma) {
569
+ tmp = mi;
570
+ mi = ma;
571
+ ma = tmp;
572
+ }
573
+
574
+ for (i = 0; i < len; i++)
575
+ fbuf->data[i] = fminf(ma, fmaxf(mi, fbuf->data[i]));
576
+
577
+ return fbuf;
578
+ }
579
+
580
+
581
+ pdlc_complex_buffer_t* pdlc_complex_buffer_clipp(const pdlc_complex_buffer_t *cbuf, float mi, float ma, pdlc_complex_buffer_t *res)
582
+ {
583
+ const size_t len = cbuf->length;
584
+ size_t i;
585
+ float tmp;
586
+
587
+ if (mi > ma) {
588
+ tmp = mi;
589
+ mi = ma;
590
+ ma = tmp;
591
+ }
592
+
593
+ if (!res)
594
+ res = pdlc_complex_buffer_new(len);
595
+ else
596
+ pdlc_complex_buffer_resize(res, len, 0);
597
+
598
+ for (i = 0; i < len; i++) {
599
+ res->data[i].real = fminf(ma, fmaxf(mi, cbuf->data[i].real));
600
+ res->data[i].imag = fminf(ma, fmaxf(mi, cbuf->data[i].imag));
601
+ }
602
+
603
+ return res;
604
+ }
605
+
606
+
607
+ pdlc_complex_buffer_t* pdlc_complex_buffer_clipp_inplace(pdlc_complex_buffer_t *cbuf, float mi, float ma)
608
+ {
609
+ const size_t len = cbuf->length;
610
+ size_t i;
611
+ float tmp;
612
+
613
+ if (mi > ma) {
614
+ tmp = mi;
615
+ mi = ma;
616
+ ma = tmp;
617
+ }
618
+
619
+ for (i = 0; i < len; i++) {
620
+ cbuf->data[i].real = fminf(ma, fmaxf(mi, cbuf->data[i].real));
621
+ cbuf->data[i].imag = fminf(ma, fmaxf(mi, cbuf->data[i].imag));
622
+ }
623
+
624
+ return cbuf;
625
+ }
626
+
627
+
628
+
629
+ /* Arithmetic modulo */
630
+
631
+ static inline float pdlc_fmodf(float x, float y)
632
+ {
633
+ if (isnan(x) || isnan(y) || isinf(x) || y == 0.0f)
634
+ return NAN;
635
+
636
+ if (x == 0.0f || x == -0.0f)
637
+ return x;
638
+
639
+ return (x - floorf(x / y)*y);
640
+ }
641
+
642
+
643
+ pdlc_buffer_t* pdlc_fb_fb_modulo(const pdlc_buffer_t *lhs, const pdlc_buffer_t *rhs, pdlc_buffer_t *res)
644
+ {
645
+ size_t i;
646
+ size_t len = lhs->length;
647
+
648
+ if (len > rhs->length)
649
+ len = rhs->length;
650
+
651
+ if (!res)
652
+ res = pdlc_buffer_new(len);
653
+ else
654
+ pdlc_buffer_resize(res, len, 0);
655
+
656
+ for (i = 0; i < len; i++)
657
+ res->data[i] = pdlc_fmodf(lhs->data[i], rhs->data[i]);
658
+
659
+ return res;
660
+ }
661
+
662
+
663
+ pdlc_buffer_t* pdlc_fb_fb_modulo_inplace(pdlc_buffer_t *lhs, const pdlc_buffer_t *rhs)
664
+ {
665
+ size_t i;
666
+ size_t len = lhs->length;
667
+
668
+ if (len > rhs->length)
669
+ len = rhs->length;
670
+
671
+ for (i = 0; i < len; i++)
672
+ lhs->data[i] = pdlc_fmodf(lhs->data[i], rhs->data[i]);
673
+
674
+ return lhs;
675
+ }
676
+
677
+
678
+ pdlc_buffer_t* pdlc_fb_fs_modulo(const pdlc_buffer_t *lhs, float rhs, pdlc_buffer_t *res)
679
+ {
680
+ size_t i;
681
+ const size_t len = lhs->length;
682
+
683
+ if (!res)
684
+ res = pdlc_buffer_new(len);
685
+ else
686
+ pdlc_buffer_resize(res, len, 0);
687
+
688
+ for (i = 0; i < len; i++)
689
+ res->data[i] = pdlc_fmodf(lhs->data[i], rhs);
690
+
691
+ return res;
692
+ }
693
+
694
+
695
+ pdlc_buffer_t* pdlc_fb_fs_modulo_inplace(pdlc_buffer_t *lhs, float rhs)
696
+ {
697
+ size_t i;
698
+ const size_t len = lhs->length;
699
+
700
+ for (i = 0; i < len; i++)
701
+ lhs->data[i] = pdlc_fmodf(lhs->data[i], rhs);
702
+
703
+ return lhs;
704
+ }
705
+
706
+
707
+ pdlc_buffer_t* pdlc_fb_fb_emod(const pdlc_buffer_t *lhs, const pdlc_buffer_t *rhs, pdlc_buffer_t *res)
708
+ {
709
+ size_t i;
710
+ size_t len = lhs->length;
711
+
712
+ if (len > rhs->length)
713
+ len = rhs->length;
714
+
715
+ if (!res)
716
+ res = pdlc_buffer_new(len);
717
+ else
718
+ pdlc_buffer_resize(res, len, 0);
719
+
720
+ for (i = 0; i < len; i++)
721
+ res->data[i] = pdlc_fmodf(lhs->data[i], rhs->data[i]);
722
+
723
+ return res;
724
+ }
725
+
726
+
727
+ pdlc_buffer_t* pdlc_fb_fb_emod_inplace(pdlc_buffer_t *lhs, const pdlc_buffer_t *rhs)
728
+ {
729
+ size_t i;
730
+ size_t len = lhs->length;
731
+
732
+ if (len > rhs->length)
733
+ len = rhs->length;
734
+
735
+ for (i = 0; i < len; i++)
736
+ lhs->data[i] = pdlc_fmodf(lhs->data[i], rhs->data[i]);
737
+
738
+ return lhs;
739
+ }
740
+
741
+
742
+ pdlc_buffer_t* pdlc_fb_fs_emod(const pdlc_buffer_t *lhs, float rhs, pdlc_buffer_t *res)
743
+ {
744
+ size_t i;
745
+ const size_t len = lhs->length;
746
+
747
+ if (!res)
748
+ res = pdlc_buffer_new(len);
749
+ else
750
+ pdlc_buffer_resize(res, len, 0);
751
+
752
+ for (i = 0; i < len; i++)
753
+ res->data[i] = pdlc_fmodf(lhs->data[i], rhs);
754
+
755
+ return res;
756
+ }
757
+
758
+
759
+ pdlc_buffer_t* pdlc_fb_fs_emod_inplace(pdlc_buffer_t *lhs, float rhs)
760
+ {
761
+ size_t i;
762
+ const size_t len = lhs->length;
763
+
764
+ for (i = 0; i < len; i++)
765
+ lhs->data[i] = pdlc_fmodf(lhs->data[i], rhs);
766
+
767
+ return lhs;
768
+ }
769
+
770
+
771
+ pdlc_complex_buffer_t* pdlc_cb_cb_emod(const pdlc_complex_buffer_t *lhs, const pdlc_complex_buffer_t *rhs, pdlc_complex_buffer_t *res)
772
+ {
773
+ size_t i;
774
+ size_t len = lhs->length;
775
+
776
+ if (len > rhs->length)
777
+ len = rhs->length;
778
+
779
+ if (!res)
780
+ res = pdlc_complex_buffer_new(len);
781
+ else
782
+ pdlc_complex_buffer_resize(res, len, 0);
783
+
784
+ for (i = 0; i < len; i++) {
785
+ res->data[i].real = pdlc_fmodf(lhs->data[i].real, rhs->data[i].real);
786
+ res->data[i].imag = pdlc_fmodf(lhs->data[i].imag, rhs->data[i].imag);
787
+ }
788
+
789
+ return res;
790
+ }
791
+
792
+
793
+ pdlc_complex_buffer_t* pdlc_cb_cb_emod_inplace(pdlc_complex_buffer_t *lhs, const pdlc_complex_buffer_t *rhs)
794
+ {
795
+ size_t i;
796
+ size_t len = lhs->length;
797
+
798
+ if (len > rhs->length)
799
+ len = rhs->length;
800
+
801
+ for (i = 0; i < len; i++) {
802
+ lhs->data[i].real = pdlc_fmodf(lhs->data[i].real, rhs->data[i].real);
803
+ lhs->data[i].imag = pdlc_fmodf(lhs->data[i].imag, rhs->data[i].imag);
804
+ }
805
+
806
+ return lhs;
807
+ }
808
+
809
+
810
+ pdlc_complex_buffer_t* pdlc_cb_cs_emod(const pdlc_complex_buffer_t *lhs, pdlc_complex_t rhs, pdlc_complex_buffer_t *res)
811
+ {
812
+ size_t i;
813
+ const size_t len = lhs->length;
814
+
815
+ if (!res)
816
+ res = pdlc_complex_buffer_new(len);
817
+ else
818
+ pdlc_complex_buffer_resize(res, len, 0);
819
+
820
+ for (i = 0; i < len; i++) {
821
+ res->data[i].real = pdlc_fmodf(lhs->data[i].real, rhs.real);
822
+ res->data[i].imag = pdlc_fmodf(lhs->data[i].imag, rhs.imag);
823
+ }
824
+
825
+ return res;
826
+ }
827
+
828
+
829
+ pdlc_complex_buffer_t* pdlc_cb_cs_emod_inplace(pdlc_complex_buffer_t *lhs, pdlc_complex_t rhs)
830
+ {
831
+ size_t i;
832
+ const size_t len = lhs->length;
833
+
834
+ for (i = 0; i < len; i++) {
835
+ lhs->data[i].real = pdlc_fmodf(lhs->data[i].real, rhs.real);
836
+ lhs->data[i].imag = pdlc_fmodf(lhs->data[i].imag, rhs.imag);
837
+ }
838
+
839
+ return lhs;
840
+ }
841
+
842
+
843
+ pdlc_complex_buffer_t* pdlc_fb_cb_emod(const pdlc_buffer_t *lhs, const pdlc_complex_buffer_t *rhs, pdlc_complex_buffer_t *res)
844
+ {
845
+ size_t i;
846
+ size_t len = lhs->length;
847
+
848
+ if (len > rhs->length)
849
+ len = rhs->length;
850
+
851
+ if (!res)
852
+ res = pdlc_complex_buffer_new(len);
853
+ else
854
+ pdlc_complex_buffer_resize(res, len, 0);
855
+
856
+ for (i = 0; i < len; i++) {
857
+ res->data[i].real = pdlc_fmodf(lhs->data[i], rhs->data[i].real);
858
+ res->data[i].imag = pdlc_fmodf(lhs->data[i], rhs->data[i].imag);
859
+ }
860
+
861
+ return res;
862
+ }
863
+
864
+
865
+ pdlc_complex_buffer_t* pdlc_fb_cs_emod(const pdlc_buffer_t *lhs, pdlc_complex_t rhs, pdlc_complex_buffer_t *res)
866
+ {
867
+ size_t i;
868
+ const size_t len = lhs->length;
869
+
870
+ if (!res)
871
+ res = pdlc_complex_buffer_new(len);
872
+ else
873
+ pdlc_complex_buffer_resize(res, len, 0);
874
+
875
+ for (i = 0; i < len; i++) {
876
+ res->data[i].real = pdlc_fmodf(lhs->data[i], rhs.real);
877
+ res->data[i].imag = pdlc_fmodf(lhs->data[i], rhs.imag);
878
+ }
879
+
880
+ return res;
881
+ }
882
+
883
+
884
+ pdlc_complex_buffer_t* pdlc_cb_fb_emod(const pdlc_complex_buffer_t *lhs, const pdlc_buffer_t *rhs, pdlc_complex_buffer_t *res)
885
+ {
886
+ size_t i;
887
+ size_t len = lhs->length;
888
+
889
+ if (len > rhs->length)
890
+ len = rhs->length;
891
+
892
+ if (!res)
893
+ res = pdlc_complex_buffer_new(len);
894
+ else
895
+ pdlc_complex_buffer_resize(res, len, 0);
896
+
897
+ for (i = 0; i < len; i++) {
898
+ res->data[i].real = pdlc_fmodf(lhs->data[i].real, rhs->data[i]);
899
+ res->data[i].imag = pdlc_fmodf(lhs->data[i].imag, rhs->data[i]);
900
+ }
901
+
902
+ return res;
903
+ }
904
+
905
+
906
+ pdlc_complex_buffer_t* pdlc_cb_fb_emod_inplace(pdlc_complex_buffer_t *lhs, const pdlc_buffer_t *rhs)
907
+ {
908
+ size_t i;
909
+ size_t len = lhs->length;
910
+
911
+ if (len > rhs->length)
912
+ len = rhs->length;
913
+
914
+ for (i = 0; i < len; i++) {
915
+ lhs->data[i].real = pdlc_fmodf(lhs->data[i].real, rhs->data[i]);
916
+ lhs->data[i].imag = pdlc_fmodf(lhs->data[i].imag, rhs->data[i]);
917
+ }
918
+
919
+ return lhs;
920
+ }
921
+
922
+
923
+ pdlc_complex_buffer_t* pdlc_cb_fs_emod(const pdlc_complex_buffer_t *lhs, float rhs, pdlc_complex_buffer_t *res)
924
+ {
925
+ size_t i;
926
+ const size_t len = lhs->length;
927
+
928
+ if (!res)
929
+ res = pdlc_complex_buffer_new(len);
930
+ else
931
+ pdlc_complex_buffer_resize(res, len, 0);
932
+
933
+ for (i = 0; i < len; i++) {
934
+ res->data[i].real = pdlc_fmodf(lhs->data[i].real, rhs);
935
+ res->data[i].imag = pdlc_fmodf(lhs->data[i].imag, rhs);
936
+ }
937
+
938
+ return res;
939
+ }
940
+
941
+
942
+ pdlc_complex_buffer_t* pdlc_cb_fs_emod_inplace(pdlc_complex_buffer_t *lhs, float rhs)
943
+ {
944
+ size_t i;
945
+ const size_t len = lhs->length;
946
+
947
+ for (i = 0; i < len; i++) {
948
+ lhs->data[i].real = pdlc_fmodf(lhs->data[i].real, rhs);
949
+ lhs->data[i].imag = pdlc_fmodf(lhs->data[i].imag, rhs);
950
+ }
951
+
952
+ return lhs;
953
+ }
954
+
955
+