generated from chaos-lang/template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
math.c
1220 lines (1077 loc) · 33.1 KB
/
math.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <math.h>
#include "Chaos.h"
// Mathematical constants
const long double pi = 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214;
const long double e = 2.71828182845904523536028747135266249775724709369995957496696762772407663035354759457138217852516642742746;
const long double golden_ratio = 1.61803398874989484820458683436563811772030917980576286213544862270526046281890244970720720418939113748475;
// num math.pi()
char *pi_params_name[] = {};
unsigned pi_params_type[] = {};
unsigned pi_params_secondary_type[] = {};
unsigned short pi_params_length = 0;
int KAOS_EXPORT Kaos_pi()
{
kaos.returnVariableFloat(pi);
return 0;
}
// num math.e()
char *e_params_name[] = {};
unsigned e_params_type[] = {};
unsigned e_params_secondary_type[] = {};
unsigned short e_params_length = 0;
int KAOS_EXPORT Kaos_e()
{
kaos.returnVariableFloat(e);
return 0;
}
// num math.golden_ratio()
char *golden_ratio_params_name[] = {};
unsigned golden_ratio_params_type[] = {};
unsigned golden_ratio_params_secondary_type[] = {};
unsigned short golden_ratio_params_length = 0;
int KAOS_EXPORT Kaos_golden_ratio()
{
kaos.returnVariableFloat(golden_ratio);
return 0;
}
// num math.inf()
char *inf_params_name[] = {};
unsigned inf_params_type[] = {};
unsigned inf_params_secondary_type[] = {};
unsigned short inf_params_length = 0;
int KAOS_EXPORT Kaos_inf()
{
long double inf = INFINITY;
kaos.returnVariableFloat(inf);
return 0;
}
// num math.nan()
char *nan_params_name[] = {};
unsigned nan_params_type[] = {};
unsigned nan_params_secondary_type[] = {};
unsigned short nan_params_length = 0;
int KAOS_EXPORT Kaos_nan()
{
long double nan = NAN;
kaos.returnVariableFloat(nan);
return 0;
}
// Trigonometric functions
// num math.cos(num x)
char *cos_params_name[] = {
"x"
};
unsigned cos_params_type[] = {
K_NUMBER
};
unsigned cos_params_secondary_type[] = {
K_ANY
};
unsigned short cos_params_length = (unsigned short) sizeof(cos_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_cos()
{
long double x = kaos.getVariableFloat(cos_params_name[0]);
x = cosl(x * pi / 180.0);
kaos.returnVariableFloat(x);
return 0;
}
// num math.sin(num x)
char *sin_params_name[] = {
"x"
};
unsigned sin_params_type[] = {
K_NUMBER
};
unsigned sin_params_secondary_type[] = {
K_ANY
};
unsigned short sin_params_length = (unsigned short) sizeof(sin_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_sin()
{
long double x = kaos.getVariableFloat(sin_params_name[0]);
x = sinl(x * pi / 180.0);
kaos.returnVariableFloat(x);
return 0;
}
// num math.tan(num x)
char *tan_params_name[] = {
"x"
};
unsigned tan_params_type[] = {
K_NUMBER
};
unsigned tan_params_secondary_type[] = {
K_ANY
};
unsigned short tan_params_length = (unsigned short) sizeof(tan_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_tan()
{
long double x = kaos.getVariableFloat(tan_params_name[0]);
x = tanl(x * pi / 180.0);
kaos.returnVariableFloat(x);
return 0;
}
// num math.acos(num x)
char *acos_params_name[] = {
"x"
};
unsigned acos_params_type[] = {
K_NUMBER
};
unsigned acos_params_secondary_type[] = {
K_ANY
};
unsigned short acos_params_length = (unsigned short) sizeof(acos_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_acos()
{
long double x = kaos.getVariableFloat(acos_params_name[0]);
x = acosl(x) * 180.0 / pi;
kaos.returnVariableFloat(x);
return 0;
}
// num math.asin(num x)
char *asin_params_name[] = {
"x"
};
unsigned asin_params_type[] = {
K_NUMBER
};
unsigned asin_params_secondary_type[] = {
K_ANY
};
unsigned short asin_params_length = (unsigned short) sizeof(asin_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_asin()
{
long double x = kaos.getVariableFloat(asin_params_name[0]);
x = asinl(x) * 180.0 / pi;
kaos.returnVariableFloat(x);
return 0;
}
// num math.atan(num x)
char *atan_params_name[] = {
"x"
};
unsigned atan_params_type[] = {
K_NUMBER
};
unsigned atan_params_secondary_type[] = {
K_ANY
};
unsigned short atan_params_length = (unsigned short) sizeof(atan_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_atan()
{
long double x = kaos.getVariableFloat(atan_params_name[0]);
x = atanl(x) * 180.0 / pi;
kaos.returnVariableFloat(x);
return 0;
}
// num math.atan2(num x, num y)
char *atan2_params_name[] = {
"x",
"y"
};
unsigned atan2_params_type[] = {
K_NUMBER,
K_NUMBER
};
unsigned atan2_params_secondary_type[] = {
K_ANY,
K_ANY
};
unsigned short atan2_params_length = (unsigned short) sizeof(atan2_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_atan2()
{
long double x = kaos.getVariableFloat(atan2_params_name[0]);
long double y = kaos.getVariableFloat(atan2_params_name[1]);
x = atan2l(y, x) * 180.0 / pi;
kaos.returnVariableFloat(x);
return 0;
}
// Hyperbolic functions
// num math.cosh(num x)
char *cosh_params_name[] = {
"x"
};
unsigned cosh_params_type[] = {
K_NUMBER
};
unsigned cosh_params_secondary_type[] = {
K_ANY
};
unsigned short cosh_params_length = (unsigned short) sizeof(cosh_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_cosh()
{
long double x = kaos.getVariableFloat(cosh_params_name[0]);
x = coshl(x);
kaos.returnVariableFloat(x);
return 0;
}
// num math.sinh(num x)
char *sinh_params_name[] = {
"x"
};
unsigned sinh_params_type[] = {
K_NUMBER
};
unsigned sinh_params_secondary_type[] = {
K_ANY
};
unsigned short sinh_params_length = (unsigned short) sizeof(sinh_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_sinh()
{
long double x = kaos.getVariableFloat(sinh_params_name[0]);
x = sinhl(x);
kaos.returnVariableFloat(x);
return 0;
}
// num math.tanh(num x)
char *tanh_params_name[] = {
"x"
};
unsigned tanh_params_type[] = {
K_NUMBER
};
unsigned tanh_params_secondary_type[] = {
K_ANY
};
unsigned short tanh_params_length = (unsigned short) sizeof(tanh_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_tanh()
{
long double x = kaos.getVariableFloat(tanh_params_name[0]);
x = tanhl(x);
kaos.returnVariableFloat(x);
return 0;
}
// num math.acosh(num x)
char *acosh_params_name[] = {
"x"
};
unsigned acosh_params_type[] = {
K_NUMBER
};
unsigned acosh_params_secondary_type[] = {
K_ANY
};
unsigned short acosh_params_length = (unsigned short) sizeof(acosh_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_acosh()
{
long double x = kaos.getVariableFloat(acosh_params_name[0]);
x = acoshl(x);
kaos.returnVariableFloat(x);
return 0;
}
// num math.asinh(num x)
char *asinh_params_name[] = {
"x"
};
unsigned asinh_params_type[] = {
K_NUMBER
};
unsigned asinh_params_secondary_type[] = {
K_ANY
};
unsigned short asinh_params_length = (unsigned short) sizeof(asinh_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_asinh()
{
long double x = kaos.getVariableFloat(asinh_params_name[0]);
x = asinhl(x);
kaos.returnVariableFloat(x);
return 0;
}
// num math.atanh(num x)
char *atanh_params_name[] = {
"x"
};
unsigned atanh_params_type[] = {
K_NUMBER
};
unsigned atanh_params_secondary_type[] = {
K_ANY
};
unsigned short atanh_params_length = (unsigned short) sizeof(atanh_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_atanh()
{
long double x = kaos.getVariableFloat(atanh_params_name[0]);
x = atanhl(x);
kaos.returnVariableFloat(x);
return 0;
}
// Exponential and logarithmic functions
// num math.exp(num x)
char *exp_params_name[] = {
"x"
};
unsigned exp_params_type[] = {
K_NUMBER
};
unsigned exp_params_secondary_type[] = {
K_ANY
};
unsigned short exp_params_length = (unsigned short) sizeof(exp_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_exp()
{
long double x = kaos.getVariableFloat(exp_params_name[0]);
x = expl(x);
kaos.returnVariableFloat(x);
return 0;
}
// num dict math.frexp(num x)
char *frexp_params_name[] = {
"x"
};
unsigned frexp_params_type[] = {
K_NUMBER
};
unsigned frexp_params_secondary_type[] = {
K_ANY
};
unsigned short frexp_params_length = (unsigned short) sizeof(frexp_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_frexp()
{
long double x = kaos.getVariableFloat(frexp_params_name[0]);
int n;
long double m = frexpl(x , &n);
kaos.startBuildingDict();
kaos.createVariableFloat("mantissa", m);
kaos.createVariableInt("exponent", (long long) n);
kaos.returnDict(K_NUMBER);
return 0;
}
// num math.ldexp(num x, num exp)
char *ldexp_params_name[] = {
"x",
"y"
};
unsigned ldexp_params_type[] = {
K_NUMBER,
K_NUMBER
};
unsigned ldexp_params_secondary_type[] = {
K_ANY,
K_ANY
};
unsigned short ldexp_params_length = (unsigned short) sizeof(ldexp_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_ldexp()
{
long double x = kaos.getVariableFloat(ldexp_params_name[0]);
long double y = kaos.getVariableFloat(ldexp_params_name[1]);
x = ldexpl(x, y);
kaos.returnVariableFloat(x);
return 0;
}
// num math.ln(num x)
char *ln_params_name[] = {
"x"
};
unsigned ln_params_type[] = {
K_NUMBER
};
unsigned ln_params_secondary_type[] = {
K_ANY
};
unsigned short ln_params_length = (unsigned short) sizeof(ln_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_ln()
{
long double x = kaos.getVariableFloat(ln_params_name[0]);
x = logl(x);
kaos.returnVariableFloat(x);
return 0;
}
// num math.log(num x, num b)
char *log_params_name[] = {
"x",
"b"
};
unsigned log_params_type[] = {
K_NUMBER,
K_NUMBER
};
unsigned log_params_secondary_type[] = {
K_ANY,
K_ANY
};
unsigned short log_params_length = (unsigned short) sizeof(log_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_log()
{
long double x = kaos.getVariableFloat(log_params_name[0]);
long double b = kaos.getVariableFloat(log_params_name[1]);
x = logl(x) / logl(b);
kaos.returnVariableFloat(x);
return 0;
}
// num math.log1p(num x)
char *log1p_params_name[] = {
"x"
};
unsigned log1p_params_type[] = {
K_NUMBER
};
unsigned log1p_params_secondary_type[] = {
K_ANY
};
unsigned short log1p_params_length = (unsigned short) sizeof(log1p_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_log1p()
{
long double x = kaos.getVariableFloat(log1p_params_name[0]);
x = log1pl(x);
kaos.returnVariableFloat(x);
return 0;
}
// num math.log2(num x)
char *log2_params_name[] = {
"x"
};
unsigned log2_params_type[] = {
K_NUMBER
};
unsigned log2_params_secondary_type[] = {
K_ANY
};
unsigned short log2_params_length = (unsigned short) sizeof(log2_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_log2()
{
long double x = kaos.getVariableFloat(log2_params_name[0]);
x = log2l(x);
kaos.returnVariableFloat(x);
return 0;
}
// num math.log10(num x)
char *log10_params_name[] = {
"x"
};
unsigned log10_params_type[] = {
K_NUMBER
};
unsigned log10_params_secondary_type[] = {
K_ANY
};
unsigned short log10_params_length = (unsigned short) sizeof(log10_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_log10()
{
long double x = kaos.getVariableFloat(log10_params_name[0]);
x = log10l(x);
kaos.returnVariableFloat(x);
return 0;
}
// num dict math.modf(num x)
char *modf_params_name[] = {
"x"
};
unsigned modf_params_type[] = {
K_NUMBER
};
unsigned modf_params_secondary_type[] = {
K_ANY
};
unsigned short modf_params_length = (unsigned short) sizeof(modf_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_modf()
{
long double x = kaos.getVariableFloat(modf_params_name[0]);
long double i;
long double f = modfl(x , &i);
kaos.startBuildingDict();
kaos.createVariableInt("integer", (long long) i);
kaos.createVariableFloat("fraction", f);
kaos.returnDict(K_NUMBER);
return 0;
}
// num math.expm1(num x)
char *expm1_params_name[] = {
"x"
};
unsigned expm1_params_type[] = {
K_NUMBER
};
unsigned expm1_params_secondary_type[] = {
K_ANY
};
unsigned short expm1_params_length = (unsigned short) sizeof(expm1_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_expm1()
{
long double x = kaos.getVariableFloat(expm1_params_name[0]);
x = expm1l(x);
kaos.returnVariableFloat(x);
return 0;
}
// Power functions
// num math.pow(num x, num y)
char *pow_params_name[] = {
"x",
"y"
};
unsigned pow_params_type[] = {
K_NUMBER,
K_NUMBER
};
unsigned pow_params_secondary_type[] = {
K_ANY,
K_ANY
};
unsigned short pow_params_length = (unsigned short) sizeof(pow_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_pow()
{
long double x = kaos.getVariableFloat(pow_params_name[0]);
long double y = kaos.getVariableFloat(pow_params_name[1]);
x = powl(x ,y);
kaos.returnVariableFloat(x);
return 0;
}
// num math.sqrt(num x)
char *sqrt_params_name[] = {
"x"
};
unsigned sqrt_params_type[] = {
K_NUMBER
};
unsigned sqrt_params_secondary_type[] = {
K_ANY
};
unsigned short sqrt_params_length = (unsigned short) sizeof(sqrt_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_sqrt()
{
long double x = kaos.getVariableFloat(sqrt_params_name[0]);
x = sqrtl(x);
kaos.returnVariableFloat(x);
return 0;
}
// num math.cbrt(num x)
char *cbrt_params_name[] = {
"x"
};
unsigned cbrt_params_type[] = {
K_NUMBER
};
unsigned cbrt_params_secondary_type[] = {
K_ANY
};
unsigned short cbrt_params_length = (unsigned short) sizeof(cbrt_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_cbrt()
{
long double x = kaos.getVariableFloat(cbrt_params_name[0]);
x = cbrtl(x);
kaos.returnVariableFloat(x);
return 0;
}
// num math.hypot(num x, num y)
char *hypot_params_name[] = {
"x",
"y"
};
unsigned hypot_params_type[] = {
K_NUMBER,
K_NUMBER
};
unsigned hypot_params_secondary_type[] = {
K_ANY,
K_ANY
};
unsigned short hypot_params_length = (unsigned short) sizeof(hypot_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_hypot()
{
long double x = kaos.getVariableFloat(hypot_params_name[0]);
long double y = kaos.getVariableFloat(hypot_params_name[1]);
x = hypotl(x ,y);
kaos.returnVariableFloat(x);
return 0;
}
// Error and gamma functions
// num math.erf(num x)
char *erf_params_name[] = {
"x"
};
unsigned erf_params_type[] = {
K_NUMBER
};
unsigned erf_params_secondary_type[] = {
K_ANY
};
unsigned short erf_params_length = (unsigned short) sizeof(erf_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_erf()
{
long double x = kaos.getVariableFloat(erf_params_name[0]);
x = erfl(x);
kaos.returnVariableFloat(x);
return 0;
}
// num math.erfc(num x)
char *erfc_params_name[] = {
"x"
};
unsigned erfc_params_type[] = {
K_NUMBER
};
unsigned erfc_params_secondary_type[] = {
K_ANY
};
unsigned short erfc_params_length = (unsigned short) sizeof(erfc_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_erfc()
{
long double x = kaos.getVariableFloat(erfc_params_name[0]);
x = erfcl(x);
kaos.returnVariableFloat(x);
return 0;
}
// num math.gamma(num x)
char *gamma_params_name[] = {
"x"
};
unsigned gamma_params_type[] = {
K_NUMBER
};
unsigned gamma_params_secondary_type[] = {
K_ANY
};
unsigned short gamma_params_length = (unsigned short) sizeof(gamma_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_gamma()
{
long double x = kaos.getVariableFloat(gamma_params_name[0]);
x = tgammal(x);
kaos.returnVariableFloat(x);
return 0;
}
// num math.lgamma(num x)
char *lgamma_params_name[] = {
"x"
};
unsigned lgamma_params_type[] = {
K_NUMBER
};
unsigned lgamma_params_secondary_type[] = {
K_ANY
};
unsigned short lgamma_params_length = (unsigned short) sizeof(lgamma_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_lgamma()
{
long double x = kaos.getVariableFloat(lgamma_params_name[0]);
x = lgammal(x);
kaos.returnVariableFloat(x);
return 0;
}
// Rounding and remainder functions
// num math.ceil(num x)
char *ceil_params_name[] = {
"x"
};
unsigned ceil_params_type[] = {
K_NUMBER
};
unsigned ceil_params_secondary_type[] = {
K_ANY
};
unsigned short ceil_params_length = (unsigned short) sizeof(ceil_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_ceil()
{
long double x = kaos.getVariableFloat(ceil_params_name[0]);
long long y = (long long) ceill(x);
kaos.returnVariableInt(y);
return 0;
}
// num math.floor(num x)
char *floor_params_name[] = {
"x"
};
unsigned floor_params_type[] = {
K_NUMBER
};
unsigned floor_params_secondary_type[] = {
K_ANY
};
unsigned short floor_params_length = (unsigned short) sizeof(floor_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_floor()
{
long double x = kaos.getVariableFloat(floor_params_name[0]);
long long y = (long long) floorl(x);
kaos.returnVariableInt(y);
return 0;
}
// num math.mod(num x, num y)
char *mod_params_name[] = {
"x",
"y"
};
unsigned mod_params_type[] = {
K_NUMBER,
K_NUMBER
};
unsigned mod_params_secondary_type[] = {
K_ANY,
K_ANY
};
unsigned short mod_params_length = (unsigned short) sizeof(mod_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_mod()
{
long long x = kaos.getVariableInt(mod_params_name[0]);
long long y = kaos.getVariableInt(mod_params_name[1]);
x = x % y;
kaos.returnVariableInt(x);
return 0;
}
// num math.fmod(num x, num y)
char *fmod_params_name[] = {
"x",
"y"
};
unsigned fmod_params_type[] = {
K_NUMBER,
K_NUMBER
};
unsigned fmod_params_secondary_type[] = {
K_ANY,
K_ANY
};
unsigned short fmod_params_length = (unsigned short) sizeof(fmod_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_fmod()
{
long double x = kaos.getVariableFloat(fmod_params_name[0]);
long double y = kaos.getVariableFloat(fmod_params_name[1]);
x = fmodl(x, y);
kaos.returnVariableFloat(x);
return 0;
}
// num math.trunc(num x)
char *trunc_params_name[] = {
"x"
};
unsigned trunc_params_type[] = {
K_NUMBER
};
unsigned trunc_params_secondary_type[] = {
K_ANY
};
unsigned short trunc_params_length = (unsigned short) sizeof(trunc_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_trunc()
{
long double x = kaos.getVariableFloat(trunc_params_name[0]);
long long y = (long long) truncl(x);
kaos.returnVariableInt(y);
return 0;
}
// num math.round(num x)
char *round_params_name[] = {
"x"
};
unsigned round_params_type[] = {
K_NUMBER
};
unsigned round_params_secondary_type[] = {
K_ANY
};
unsigned short round_params_length = (unsigned short) sizeof(round_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_round()
{
long double x = kaos.getVariableFloat(round_params_name[0]);
long long y = llroundl(x);
kaos.returnVariableInt(y);
return 0;
}
// num math.remainder(num x, num y)
char *remainder_params_name[] = {
"x",
"y"
};
unsigned remainder_params_type[] = {
K_NUMBER,
K_NUMBER
};
unsigned remainder_params_secondary_type[] = {
K_ANY,
K_ANY
};
unsigned short remainder_params_length = (unsigned short) sizeof(remainder_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_remainder()
{
long double x = kaos.getVariableFloat(remainder_params_name[0]);
long double y = kaos.getVariableFloat(remainder_params_name[1]);
x = remainderl(x, y);
kaos.returnVariableFloat(x);
return 0;
}
// num dict math.remquo(num x, num y)
char *remquo_params_name[] = {
"x",
"y"
};
unsigned remquo_params_type[] = {
K_NUMBER,
K_NUMBER
};
unsigned remquo_params_secondary_type[] = {
K_ANY,
K_ANY
};
unsigned short remquo_params_length = (unsigned short) sizeof(remquo_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_remquo()
{
long double x = kaos.getVariableFloat(remquo_params_name[0]);
long double y = kaos.getVariableFloat(remquo_params_name[1]);
int q;
x = remquol(x, y, &q);
kaos.startBuildingDict();
kaos.createVariableFloat("remainder", x);
kaos.createVariableInt("quotient", (long long) q);
kaos.returnDict(K_NUMBER);
return 0;
}
// Floating-point manipulation functions
// num math.copysign(num x, num y)
char *copysign_params_name[] = {
"x",
"y"
};
unsigned copysign_params_type[] = {
K_NUMBER,
K_NUMBER
};
unsigned copysign_params_secondary_type[] = {
K_ANY,
K_ANY
};
unsigned short copysign_params_length = (unsigned short) sizeof(copysign_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_copysign()
{
long double x = kaos.getVariableFloat(copysign_params_name[0]);
long double y = kaos.getVariableFloat(copysign_params_name[1]);
x = copysignl(x ,y);
kaos.returnVariableFloat(x);
return 0;
}
// num math.nextafter(num x, num y)
char *nextafter_params_name[] = {
"x",
"y"
};
unsigned nextafter_params_type[] = {
K_NUMBER,
K_NUMBER
};
unsigned nextafter_params_secondary_type[] = {
K_ANY,
K_ANY
};
unsigned short nextafter_params_length = (unsigned short) sizeof(nextafter_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_nextafter()
{
long double x = kaos.getVariableFloat(nextafter_params_name[0]);
long double y = kaos.getVariableFloat(nextafter_params_name[1]);
x = nextafterl(x ,y);
kaos.returnVariableFloat(x);
return 0;
}
// Other functions
// num math.abs(num x)
char *abs_params_name[] = {
"x"
};
unsigned abs_params_type[] = {
K_NUMBER
};
unsigned abs_params_secondary_type[] = {
K_ANY
};
unsigned short abs_params_length = (unsigned short) sizeof(abs_params_type) / sizeof(unsigned);
int KAOS_EXPORT Kaos_abs()
{
long double x = kaos.getVariableFloat(abs_params_name[0]);
x = fabsl(x);
kaos.returnVariableFloat(x);
return 0;
}
// num math.factorial(num x)
long long factorial(long long n) {
return n < 0 ? -1 : n == 0 ? 1 : n * factorial(n - 1);
}
char *factorial_params_name[] = {
"x"