-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmath.hpp
More file actions
950 lines (787 loc) · 34.2 KB
/
Copy pathmath.hpp
File metadata and controls
950 lines (787 loc) · 34.2 KB
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
#ifndef CHAISCRIPT_EXTRAS_MATH_HPP_
#define CHAISCRIPT_EXTRAS_MATH_HPP_
#include <cmath>
#include <memory>
#include <chaiscript/chaiscript.hpp>
namespace chaiscript {
namespace extras {
namespace math {
// TRIG FUNCTIONS
template<typename Ret, typename Param>
ModulePtr cos(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::cos(p); }), "cos");
return m;
}
template<typename Ret, typename Param>
ModulePtr sin(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::sin(p); }), "sin");
return m;
}
template<typename Ret, typename Param>
ModulePtr tan(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::tan(p); }), "tan");
return m;
}
template<typename Ret, typename Param>
ModulePtr acos(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::acos(p); }), "acos");
return m;
}
template<typename Ret, typename Param>
ModulePtr asin(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::asin(p); }), "asin");
return m;
}
template<typename Ret, typename Param>
ModulePtr atan(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::atan(p); }), "atan");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr atan2(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::atan2(p1, p2); }), "atan2");
return m;
}
// HYPERBOLIC FUNCTIONS
template<typename Ret, typename Param>
ModulePtr cosh(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::cosh(p); }), "cosh");
return m;
}
template<typename Ret, typename Param>
ModulePtr sinh(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::sinh(p); }), "sinh");
return m;
}
template<typename Ret, typename Param>
ModulePtr tanh(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::tanh(p); }), "tanh");
return m;
}
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
template<typename Ret, typename Param>
ModulePtr acosh(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::acosh(p); }), "acosh");
return m;
}
template<typename Ret, typename Param>
ModulePtr asinh(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::asinh(p); }), "asinh");
return m;
}
template<typename Ret, typename Param>
ModulePtr atanh(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::atanh(p); }), "atanh");
return m;
}
#endif
// EXPONENTIAL AND LOGARITHMIC FUNCTIONS
template<typename Ret, typename Param>
ModulePtr exp(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::exp(p); }), "exp");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr frexp(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::frexp(p1, p2); }), "frexp");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr ldexp(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::ldexp(p1, p2); }), "ldexp");
return m;
}
template<typename Ret, typename Param>
ModulePtr log(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::log(p); }), "log");
return m;
}
template<typename Ret, typename Param>
ModulePtr log10(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::log10(p); }), "log10");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr modf(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::modf(p1, p2); }), "modf");
return m;
}
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
template<typename Ret, typename Param>
ModulePtr exp2(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::exp2(p); }), "exp2");
return m;
}
template<typename Ret, typename Param>
ModulePtr expm1(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::expm1(p); }), "expm1");
return m;
}
template<typename Ret, typename Param>
ModulePtr ilogb(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::ilogb(p); }), "ilogb");
return m;
}
template<typename Ret, typename Param>
ModulePtr log1p(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::log1p(p); }), "log1p");
return m;
}
template<typename Ret, typename Param>
ModulePtr log2(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::log2(p); }), "log2");
return m;
}
template<typename Ret, typename Param>
ModulePtr logb(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::logb(p); }), "logb");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr scalbn(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::scalbn(p1, p2); }), "scalbn");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr scalbln(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::scalbln(p1, p2); }), "scalbln");
return m;
}
#endif
// POWER FUNCTIONS
template<typename Ret, typename Param1, typename Param2>
ModulePtr pow(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::pow(p1, p2); }), "pow");
return m;
}
template<typename Ret, typename Param>
ModulePtr sqrt(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::sqrt(p); }), "sqrt");
return m;
}
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
template<typename Ret, typename Param>
ModulePtr cbrt(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::cbrt(p); }), "cbrt");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr hypot(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::hypot(p1, p2); }), "hypot");
return m;
}
// ERROR AND GAMMA FUNCTIONS
template<typename Ret, typename Param>
ModulePtr erf(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::erf(p); }), "erf");
return m;
}
template<typename Ret, typename Param>
ModulePtr erfc(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::erfc(p); }), "erfc");
return m;
}
template<typename Ret, typename Param>
ModulePtr tgamma(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::tgamma(p); }), "tgamma");
return m;
}
template<typename Ret, typename Param>
ModulePtr lgamma(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::lgamma(p); }), "lgamma");
return m;
}
#endif
// ROUNDING AND REMAINDER FUNCTIONS
template<typename Ret, typename Param>
ModulePtr ceil(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::ceil(p); }), "ceil");
return m;
}
template<typename Ret, typename Param>
ModulePtr floor(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::floor(p); }), "floor");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr fmod(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::fmod(p1, p2); }), "fmod");
return m;
}
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
template<typename Ret, typename Param>
ModulePtr trunc(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::trunc(p); }), "trunc");
return m;
}
template<typename Ret, typename Param>
ModulePtr round(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::round(p); }), "round");
return m;
}
template<typename Ret, typename Param>
ModulePtr lround(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::lround(p); }), "lround");
return m;
}
// long long ints do not work
template<typename Ret, typename Param>
ModulePtr llround(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::llround(p); }), "llround");
return m;
}
template<typename Ret, typename Param>
ModulePtr rint(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::rint(p); }), "rint");
return m;
}
template<typename Ret, typename Param>
ModulePtr lrint(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::lrint(p); }), "lrint");
return m;
}
// long long ints do not work
template<typename Ret, typename Param>
ModulePtr llrint(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::llrint(p); }), "llrint");
return m;
}
template<typename Ret, typename Param>
ModulePtr nearbyint(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::nearbyint(p); }), "nearbyint");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr remainder(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::remainder(p1, p2); }), "remainder");
return m;
}
template<typename Ret, typename Param1, typename Param2, typename Param3>
ModulePtr remquo(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2, Param3 p3){ return std::remquo(p1, p2, p3); }), "remquo");
return m;
}
// FLOATING-POINT MANIPULATION FUNCTIONS
template<typename Ret, typename Param1, typename Param2>
ModulePtr copysign(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::copysign(p1, p2); }), "copysign");
return m;
}
template<typename Ret, typename Param>
ModulePtr nan(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::nan(p); }), "nan");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr nextafter(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::nextafter(p1, p2); }), "nextafter");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr nexttoward(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::nexttoward(p1, p2); }), "nexttoward");
return m;
}
// MINIMUM, MAXIMUM, DIFFERENCE FUNCTIONS
template<typename Ret, typename Param1, typename Param2>
ModulePtr fdim(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::fdim(p1, p2); }), "fdim");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr fmax(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::fmax(p1, p2); }), "fmax");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr fmin(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::fmin(p1, p2); }), "fmin");
return m;
}
// OTHER FUNCTIONS
template<typename Ret, typename Param>
ModulePtr fabs(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::fabs(p); }), "fabs");
return m;
}
#endif
template<typename Ret, typename Param>
ModulePtr abs(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::abs(p); }), "abs");
return m;
}
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
template<typename Ret, typename Param1, typename Param2, typename Param3>
ModulePtr fma(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2, Param3 p3){ return std::fma(p1, p2, p3); }), "fma");
return m;
}
// CLASSIFICATION FUNCTIONS
template<typename Ret, typename Param>
ModulePtr fpclassify(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::fpclassify(p); }), "fpclassify");
return m;
}
#endif
template<typename Ret, typename Param>
ModulePtr isfinite(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::isfinite(p); }), "isfinite");
return m;
}
template<typename Ret, typename Param>
ModulePtr isinf(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::isinf(p); }), "isinf");
return m;
}
template<typename Ret, typename Param>
ModulePtr isnan(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::isnan(p); }), "isnan");
return m;
}
template<typename Ret, typename Param>
ModulePtr isnormal(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::isnormal(p); }), "isnormal");
return m;
}
template<typename Ret, typename Param>
ModulePtr signbit(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param p){ return std::signbit(p); }), "signbit");
return m;
}
// COMPARISON FUNCTIONS
template<typename Ret, typename Param1, typename Param2>
ModulePtr isgreater(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::isgreater(p1, p2); }), "isgreater");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr isgreaterequal(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::isgreaterequal(p1, p2); }), "isgreaterequal");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr isless(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::isless(p1, p2); }), "isless");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr islessequal(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::islessequal(p1, p2); }), "islessequal");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr islessgreater(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::islessgreater(p1, p2); }), "islessgreater");
return m;
}
template<typename Ret, typename Param1, typename Param2>
ModulePtr isunordered(ModulePtr m = std::make_shared<Module>())
{
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::isunordered(p1, p2); }), "isunordered");
return m;
}
ModulePtr bootstrap(ModulePtr m = std::make_shared<Module>())
{
// TRIG FUNCTIONS
cos<double, double>(m);
cos<float, float>(m);
cos<long double, long double>(m);
sin<double, double>(m);
sin<float, float>(m);
sin<long double, long double>(m);
tan<double, double>(m);
tan<float, float>(m);
tan<long double, long double>(m);
acos<double, double>(m);
acos<float, float>(m);
acos<long double, long double>(m);
asin<double, double>(m);
asin<float, float>(m);
asin<long double, long double>(m);
atan<double, double>(m);
atan<float, float>(m);
atan<long double, long double>(m);
atan2<double, double, double>(m);
atan2<float, float, float>(m);
atan2<long double, long double, long double>(m);
// HYPERBOLIC FUNCTIONS
cosh<double, double>(m);
cosh<float, float>(m);
cosh<long double, long double>(m);
sinh<double, double>(m);
sinh<float, float>(m);
sinh<long double, long double>(m);
tanh<double, double>(m);
tanh<float, float>(m);
tanh<long double, long double>(m);
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
acosh<double, double>(m);
acosh<float, float>(m);
acosh<long double, long double>(m);
asinh<double, double>(m);
asinh<float, float>(m);
asinh<long double, long double>(m);
atanh<double, double>(m);
atanh<float, float>(m);
atanh<long double, long double>(m);
#endif
// EXPONENTIAL AND LOGARITHMIC FUNCTIONS
exp<double, double>(m);
exp<float, float>(m);
exp<long double, long double>(m);
frexp<double, double, int *>(m);
frexp<float, float, int *>(m);
frexp<long double, long double, int *>(m);
ldexp<double, double, int>(m);
ldexp<float, float, int>(m);
ldexp<long double, long double, int>(m);
log<double, double>(m);
log<float, float>(m);
log<long double, long double>(m);
log10<double, double>(m);
log10<float, float>(m);
log10<long double, long double>(m);
modf<double, double, double *>(m);
modf<float, float, float *>(m);
modf<long double, long double, long double *>(m);
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
exp2<double, double>(m);
exp2<float, float>(m);
exp2<long double, long double>(m);
expm1<double, double>(m);
expm1<float, float>(m);
expm1<long double, long double>(m);
ilogb<int, double>(m);
ilogb<int, float>(m);
ilogb<int, long double>(m);
log1p<double, double>(m);
log1p<float, float>(m);
log1p<long double, long double>(m);
log2<double, double>(m);
log2<float, float>(m);
log2<long double, long double>(m);
logb<double, double>(m);
logb<float, float>(m);
logb<long double, long double>(m);
scalbn<double, double, int>(m);
scalbn<float, float, int>(m);
scalbn<long double, long double, int>(m);
scalbln<double, double, long int>(m);
scalbln<float, float, long int>(m);
scalbln<long double, long double, long int>(m);
#endif
// POWER FUNCTIONS
pow<double, double, double>(m);
pow<float, float, float>(m);
pow<long double, long double, long double>(m);
sqrt<double, double>(m);
sqrt<float, float>(m);
sqrt<long double, long double>(m);
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
cbrt<double, double>(m);
cbrt<float, float>(m);
cbrt<long double, long double>(m);
hypot<double, double, double>(m);
hypot<float, float, float>(m);
hypot<long double, long double, long double>(m);
// ERROR AND GAMMA FUNCTIONS
erf<double, double>(m);
erf<float, float>(m);
erf<long double, long double>(m);
erfc<double, double>(m);
erfc<float, float>(m);
erfc<long double, long double>(m);
tgamma<double, double>(m);
tgamma<float, float>(m);
tgamma<long double, long double>(m);
lgamma<double, double>(m);
lgamma<float, float>(m);
lgamma<long double, long double>(m);
#endif
// ROUNDING AND REMAINDER FUNCTIONS
ceil<double, double>(m);
ceil<float, float>(m);
ceil<long double, long double>(m);
floor<double, double>(m);
floor<float, float>(m);
floor<long double, long double>(m);
fmod<double, double, double>(m);
fmod<float, float, float>(m);
fmod<long double, long double, long double>(m);
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
trunc<double, double>(m);
trunc<float, float>(m);
trunc<long double, long double>(m);
round<double, double>(m);
round<float, float>(m);
round<long double, long double>(m);
lround<long int, double>(m);
lround<long int, float>(m);
lround<long int, long double>(m);
// long long ints do not work
llround<long long int, double>(m);
llround<long long int, float>(m);
llround<long long int, long double>(m);
rint<double, double>(m);
rint<float, float>(m);
rint<long double, long double>(m);
lrint<long int, double>(m);
lrint<long int, float>(m);
lrint<long int, long double>(m);
// long long ints do not work
llrint<long long int, double>(m);
llrint<long long int, float>(m);
llrint<long long int, long double>(m);
nearbyint<double, double>(m);
nearbyint<float, float>(m);
nearbyint<long double, long double>(m);
remainder<double, double, double>(m);
remainder<float, float, float>(m);
remainder<long double, long double, long double>(m);
remquo<double, double, double, int *>(m);
remquo<float, float, float, int *>(m);
remquo<long double, long double, long double, int *>(m);
// FLOATING-POINT MANIPULATION FUNCTIONS
copysign<double, double, double>(m);
copysign<float, float, float>(m);
copysign<long double, long double, long double>(m);
nan<double, const char*>(m);
nextafter<double, double, double>(m);
nextafter<float, float, float>(m);
nextafter<long double, long double, long double>(m);
nexttoward<double, double, long double>(m);
nexttoward<float, float, long double>(m);
nexttoward<long double, long double, long double>(m);
// MINIMUM, MAXIMUM, DIFFERENCE FUNCTIONS
fdim<double, double, double>(m);
fdim<float, float, float>(m);
fdim<long double, long double, long double>(m);
fmax<double, double, double>(m);
fmax<float, float, float>(m);
fmax<long double, long double, long double>(m);
fmin<double, double, double>(m);
fmin<float, float, float>(m);
fmin<long double, long double, long double>(m);
// OTHER FUNCTIONS
fabs<double, double>(m);
fabs<float, float>(m);
fabs<long double, long double>(m);
#endif
abs<double, double>(m);
abs<float, float>(m);
abs<long double, long double>(m);
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
fma<double, double, double, double>(m);
fma<float, float, float, float>(m);
fma<long double, long double, long double, long double>(m);
// CLASSIFICATION FUNCTIONS
fpclassify<int, float>(m);
fpclassify<int, double>(m);
fpclassify<int, long double>(m);
#endif
isfinite<bool, float>(m);
isfinite<bool, double>(m);
isfinite<bool, long double>(m);
isinf<bool, float>(m);
isinf<bool, double>(m);
isinf<bool, long double>(m);
isnan<bool, float>(m);
isnan<bool, double>(m);
isnan<bool, long double>(m);
isnormal<bool, float>(m);
isnormal<bool, double>(m);
isnormal<bool, long double>(m);
signbit<bool, float>(m);
signbit<bool, double>(m);
signbit<bool, long double>(m);
// COMPARISON FUNCTIONS
isgreater<bool, double, double>(m);
isgreater<bool, float, float>(m);
isgreater<bool, long double, long double>(m);
isgreaterequal<bool, double, double>(m);
isgreaterequal<bool, float, float>(m);
isgreaterequal<bool, long double, long double>(m);
isless<bool, double, double>(m);
isless<bool, float, float>(m);
isless<bool, long double, long double>(m);
islessequal<bool, double, double>(m);
islessequal<bool, float, float>(m);
islessequal<bool, long double, long double>(m);
islessgreater<bool, double, double>(m);
islessgreater<bool, float, float>(m);
islessgreater<bool, long double, long double>(m);
isunordered<bool, double, double>(m);
isunordered<bool, float, float>(m);
isunordered<bool, long double, long double>(m);
return m;
}
/// \brief Registers a "math" namespace on the given ChaiScript engine,
/// exposing the standard C++ math functions as attributes of
/// the namespace (e.g. \c math.cos(x), \c math.sqrt(x)).
///
/// Uses ChaiScript's native \c register_namespace API so that the
/// functions live inside a real namespace object rather than being
/// attached to a global variable. The namespace is lazily populated
/// when it is first imported.
inline void bootstrap_namespace(chaiscript::ChaiScript &chai)
{
chai.register_namespace([](chaiscript::Namespace &math) {
// TRIG FUNCTIONS
math["cos"] = chaiscript::var(chaiscript::fun([](double p){ return std::cos(p); }));
math["sin"] = chaiscript::var(chaiscript::fun([](double p){ return std::sin(p); }));
math["tan"] = chaiscript::var(chaiscript::fun([](double p){ return std::tan(p); }));
math["acos"] = chaiscript::var(chaiscript::fun([](double p){ return std::acos(p); }));
math["asin"] = chaiscript::var(chaiscript::fun([](double p){ return std::asin(p); }));
math["atan"] = chaiscript::var(chaiscript::fun([](double p){ return std::atan(p); }));
math["atan2"] = chaiscript::var(chaiscript::fun([](double y, double x){ return std::atan2(y, x); }));
// HYPERBOLIC FUNCTIONS
math["cosh"] = chaiscript::var(chaiscript::fun([](double p){ return std::cosh(p); }));
math["sinh"] = chaiscript::var(chaiscript::fun([](double p){ return std::sinh(p); }));
math["tanh"] = chaiscript::var(chaiscript::fun([](double p){ return std::tanh(p); }));
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
math["acosh"] = chaiscript::var(chaiscript::fun([](double p){ return std::acosh(p); }));
math["asinh"] = chaiscript::var(chaiscript::fun([](double p){ return std::asinh(p); }));
math["atanh"] = chaiscript::var(chaiscript::fun([](double p){ return std::atanh(p); }));
#endif
// EXPONENTIAL AND LOGARITHMIC FUNCTIONS
math["exp"] = chaiscript::var(chaiscript::fun([](double p){ return std::exp(p); }));
math["log"] = chaiscript::var(chaiscript::fun([](double p){ return std::log(p); }));
math["log10"] = chaiscript::var(chaiscript::fun([](double p){ return std::log10(p); }));
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
math["exp2"] = chaiscript::var(chaiscript::fun([](double p){ return std::exp2(p); }));
math["expm1"] = chaiscript::var(chaiscript::fun([](double p){ return std::expm1(p); }));
math["ilogb"] = chaiscript::var(chaiscript::fun([](double p){ return std::ilogb(p); }));
math["log1p"] = chaiscript::var(chaiscript::fun([](double p){ return std::log1p(p); }));
math["log2"] = chaiscript::var(chaiscript::fun([](double p){ return std::log2(p); }));
math["logb"] = chaiscript::var(chaiscript::fun([](double p){ return std::logb(p); }));
#endif
// POWER FUNCTIONS
math["pow"] = chaiscript::var(chaiscript::fun([](double x, double y){ return std::pow(x, y); }));
math["sqrt"] = chaiscript::var(chaiscript::fun([](double p){ return std::sqrt(p); }));
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
math["cbrt"] = chaiscript::var(chaiscript::fun([](double p){ return std::cbrt(p); }));
math["hypot"] = chaiscript::var(chaiscript::fun([](double x, double y){ return std::hypot(x, y); }));
// ERROR AND GAMMA FUNCTIONS
math["erf"] = chaiscript::var(chaiscript::fun([](double p){ return std::erf(p); }));
math["erfc"] = chaiscript::var(chaiscript::fun([](double p){ return std::erfc(p); }));
math["tgamma"] = chaiscript::var(chaiscript::fun([](double p){ return std::tgamma(p); }));
math["lgamma"] = chaiscript::var(chaiscript::fun([](double p){ return std::lgamma(p); }));
#endif
// ROUNDING AND REMAINDER FUNCTIONS
math["ceil"] = chaiscript::var(chaiscript::fun([](double p){ return std::ceil(p); }));
math["floor"] = chaiscript::var(chaiscript::fun([](double p){ return std::floor(p); }));
math["fmod"] = chaiscript::var(chaiscript::fun([](double x, double y){ return std::fmod(x, y); }));
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
math["trunc"] = chaiscript::var(chaiscript::fun([](double p){ return std::trunc(p); }));
math["round"] = chaiscript::var(chaiscript::fun([](double p){ return std::round(p); }));
math["lround"] = chaiscript::var(chaiscript::fun([](double p){ return std::lround(p); }));
math["llround"] = chaiscript::var(chaiscript::fun([](double p){ return std::llround(p); }));
math["rint"] = chaiscript::var(chaiscript::fun([](double p){ return std::rint(p); }));
math["lrint"] = chaiscript::var(chaiscript::fun([](double p){ return std::lrint(p); }));
math["llrint"] = chaiscript::var(chaiscript::fun([](double p){ return std::llrint(p); }));
math["nearbyint"] = chaiscript::var(chaiscript::fun([](double p){ return std::nearbyint(p); }));
math["remainder"] = chaiscript::var(chaiscript::fun([](double x, double y){ return std::remainder(x, y); }));
// FLOATING-POINT MANIPULATION FUNCTIONS
math["copysign"] = chaiscript::var(chaiscript::fun([](double x, double y){ return std::copysign(x, y); }));
math["nextafter"] = chaiscript::var(chaiscript::fun([](double x, double y){ return std::nextafter(x, y); }));
math["nexttoward"] = chaiscript::var(chaiscript::fun([](double x, long double y){ return std::nexttoward(x, y); }));
// MINIMUM, MAXIMUM, DIFFERENCE FUNCTIONS
math["fdim"] = chaiscript::var(chaiscript::fun([](double x, double y){ return std::fdim(x, y); }));
math["fmax"] = chaiscript::var(chaiscript::fun([](double x, double y){ return std::fmax(x, y); }));
math["fmin"] = chaiscript::var(chaiscript::fun([](double x, double y){ return std::fmin(x, y); }));
// OTHER FUNCTIONS
math["fabs"] = chaiscript::var(chaiscript::fun([](double p){ return std::fabs(p); }));
#endif
math["abs"] = chaiscript::var(chaiscript::fun([](double p){ return std::abs(p); }));
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
math["fma"] = chaiscript::var(chaiscript::fun([](double x, double y, double z){ return std::fma(x, y, z); }));
// CLASSIFICATION FUNCTIONS
math["fpclassify"] = chaiscript::var(chaiscript::fun([](double p){ return std::fpclassify(p); }));
#endif
math["isfinite"] = chaiscript::var(chaiscript::fun([](double p){ return std::isfinite(p); }));
math["isinf"] = chaiscript::var(chaiscript::fun([](double p){ return std::isinf(p); }));
math["isnan"] = chaiscript::var(chaiscript::fun([](double p){ return std::isnan(p); }));
math["isnormal"] = chaiscript::var(chaiscript::fun([](double p){ return std::isnormal(p); }));
math["signbit"] = chaiscript::var(chaiscript::fun([](double p){ return std::signbit(p); }));
// COMPARISON FUNCTIONS
math["isgreater"] = chaiscript::var(chaiscript::fun([](double x, double y){ return std::isgreater(x, y); }));
math["isgreaterequal"] = chaiscript::var(chaiscript::fun([](double x, double y){ return std::isgreaterequal(x, y); }));
math["isless"] = chaiscript::var(chaiscript::fun([](double x, double y){ return std::isless(x, y); }));
math["islessequal"] = chaiscript::var(chaiscript::fun([](double x, double y){ return std::islessequal(x, y); }));
math["islessgreater"] = chaiscript::var(chaiscript::fun([](double x, double y){ return std::islessgreater(x, y); }));
math["isunordered"] = chaiscript::var(chaiscript::fun([](double x, double y){ return std::isunordered(x, y); }));
}, "math");
}
}
}
}
#endif /* CHAISCRIPT_EXTRAS_MATH_HPP_ */