8000 Merge pull request #18 from ChaiScript/skip-advanced · ChaiScript/ChaiScript_Extras@2aee0d2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2aee0d2

Browse files
authored
Merge pull request #18 from ChaiScript/skip-advanced
math: Allow skipping some advanced functions
2 parents 4f3ee02 + 6d77ff3 commit 2aee0d2

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ chai.add(mathlib);
2828
var result = cos(0.5f)
2929
```
3030

31+
#### Options
32+
33+
Compile with one of the following flags to enable or disable features...
34+
- `CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED` When enabled, will skip some of the advanced math functions.
35+
3136
### String ID
3237

3338
Adds [String ID](https://github.com/foonathan/string_id) support to ChaiScript.
@@ -69,4 +74,4 @@ chai.add(stringmethods);
6974
var input = "Hello, World!"
7075
var output = input.replace("Hello", "Goodbye")
7176
// => "Goodbye, World!"
72-
```
77+
```

include/chaiscript/extras/math.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ namespace chaiscript {
8181
return m;
8282
}
8383

84+
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
8485
template<typename Ret, typename Param>
8586
ModulePtr acosh(ModulePtr m = std::make_shared<Module>())
8687
{
@@ -101,6 +102,7 @@ namespace chaiscript {
101102
m->add(chaiscript::fun([](Param p){ return std::atanh(p); }), "atanh");
102103
return m;
103104
}
105+
#endif
104106

105107
// EXPONENTIAL AND LOGARITHMIC FUNCTIONS
106108
template<typename Ret, typename Param>
@@ -144,6 +146,8 @@ namespace chaiscript {
144146
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::modf(p1, p2); }), "modf");
145147
return m;
146148
}
149+
150+
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
147151
template<typename Ret, typename Param>
148152
ModulePtr exp2(ModulePtr m = std::make_shared<Module>())
149153
{
@@ -199,6 +203,7 @@ namespace chaiscript {
199203
m->add(chaiscript::fun([](Param1 p1, Param2 p2){ return std::scalbln(p1, p2); }), "scalbln");
200204
return m;
201205
}
206+
#endif
202207

203208
// POWER FUNCTIONS
204209
template<typename Ret, typename Param1, typename Param2>
@@ -215,6 +220,7 @@ namespace chaiscript {
215220
return m;
216221
}
217222

223+
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
218224
template<typename Ret, typename Param>
219225
ModulePtr cbrt(ModulePtr m = std::make_shared<Module>())
220226
{
@@ -257,6 +263,7 @@ namespace chaiscript {
257263
m->add(chaiscript::fun([](Param p){ return std::lgamma(p); }), "lgamma");
258264
return m;
259265
}
266+
#endif
260267

261268
// ROUNDING AND REMAINDER FUNCTIONS
262269
template<typename Ret, typename Param>
@@ -280,6 +287,7 @@ namespace chaiscript {
280287
return m;
281288
}
282289

290+
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
283291
template<typename Ret, typename Param>
284292
ModulePtr trunc(ModulePtr m = std::make_shared<Module>())
285293
{
@@ -410,6 +418,7 @@ namespace chaiscript {
410418
m->add(chaiscript::fun([](Param p){ return std::fabs(p); }), "fabs");
411419
return m;
412420
}
421+
#endif
413422

414423
template<typename Ret, typename Param>
415424
ModulePtr abs(ModulePtr m = std::make_shared<Module>())
@@ -418,6 +427,7 @@ namespace chaiscript {
418427
return m;
419428
}
420429

430+
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
421431
template<typename Ret, typename Param1, typename Param2, typename Param3>
422432
ModulePtr fma(ModulePtr m = std::make_shared<Module>())
423433
{
@@ -432,6 +442,7 @@ namespace chaiscript {
432442
m->add(chaiscript::fun([](Param p){ return std::fpclassify(p); }), "fpclassify");
433443
return m;
434444
}
445+
#endif
435446

436447
template<typename Ret, typename Param>
437448
ModulePtr isfinite(ModulePtr m = std::make_shared<Module>())
@@ -556,6 +567,7 @@ namespace chaiscript {
556567
tanh<float, float>(m);
557568
tanh<long double, long double>(m);
558569

570+
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
559571
acosh<double, double>(m);
560572
acosh<float, float>(m);
561573
acosh<long double, long double>(m);
@@ -567,6 +579,7 @@ namespace chaiscript {
567579
atanh<double, double>(m);
568580
atanh<float, float>(m);
569581
atanh<long double, long double>(m);
582+
#endif
570583

571584
// EXPONENTIAL AND LOGARITHMIC FUNCTIONS
572585
exp<double, double>(m);
@@ -593,6 +606,7 @@ namespace chaiscript {
593606
modf<float, float, float *>(m);
594607
modf<long double, long double, long double *>(m);
595608

609+
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
596610
exp2<double, double>(m);
597611
exp2<float, float>(m);
598612
exp2<long double, long double>(m);
@@ -624,6 +638,7 @@ namespace chaiscript {
624638
scalbln<double, double, long int>(m);
625639
scalbln<float, float, long int>(m);
626640
scalbln<long double, long double, long int>(m);
641+
#endif
627642

628643
// POWER FUNCTIONS
629644
pow<double, double, double>(m);
@@ -634,6 +649,7 @@ namespace chaiscript {
634649
sqrt<float, float>(m);
635650
sqrt<long double, long double>(m);
636651

652+
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
637653
cbrt<double, double>(m);
638654
cbrt<float, float>(m);
639655
cbrt<long double, long double>(m);
@@ -658,6 +674,7 @@ namespace chaiscript {
658674
lgamma<double, double>(m);
659675
lgamma<float, float>(m);
660676
lgamma<long double, long double>(m);
677+
#endif
661678

662679
// ROUNDING AND REMAINDER FUNCTIONS
663680
ceil<double, double>(m);
@@ -672,6 +689,7 @@ namespace chaiscript {
672689
fmod<float, float, float>(m);
673690
fmod<long double, long double, long double>(m);
674691

692+
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
675693
trunc<double, double>(m);
676694
trunc<float, float>(m);
677695
trunc<long double, long double>(m);
@@ -746,11 +764,13 @@ namespace chaiscript {
746764
fabs<double, double>(m);
747765
fabs<float, float>(m);
748766
fabs<long double, long double>(m);
767+
#endif
749768

750769
abs<double, double>(m);
751770
abs<float, float>(m);
752771
abs<long double, long double>(m);
753772

773+
#ifndef CHAISCRIPT_EXTRAS_MATH_SKIP_ADVANCED
754774
fma<double, double, double, double>(m);
755775
fma<float, float, float, float>(m);
756776
fma<long double, long double, long double, long double>(m);
@@ -759,6 +779,7 @@ namespace chaiscript {
759779
fpclassify<int, float>(m);
760780
fpclassify<int, double>(m);
761781
fpclassify<int, long double>(m);
782+
#endif
762783

763784
isfinite<bool, float>(m);
764785
isfinite<bool, double>(m);

0 commit comments

Comments
 (0)
0