192d648b2SVijay Khemka /*
292d648b2SVijay Khemka  * This define will disable the ability for expressions to have comments.
392d648b2SVijay Khemka  * Expressions that have comments when parsed with a build that has this
492d648b2SVijay Khemka  * option, will result in a compilation failure.
592d648b2SVijay Khemka  */
692d648b2SVijay Khemka // #define exprtk_disable_comments
792d648b2SVijay Khemka /*
892d648b2SVijay Khemka  * This define will disable the loop-wise 'break' and 'continue'
992d648b2SVijay Khemka  * capabilities. Any expression that contains those keywords will result
1092d648b2SVijay Khemka  * in a compilation failure.
1192d648b2SVijay Khemka  */
1292d648b2SVijay Khemka #define exprtk_disable_break_continue
1392d648b2SVijay Khemka /*
1492d648b2SVijay Khemka  * This define will disable the short-circuit '&' (and) and '|' (or)
1592d648b2SVijay Khemka  * operators
1692d648b2SVijay Khemka  */
1792d648b2SVijay Khemka #define exprtk_disable_sc_andor
1892d648b2SVijay Khemka /*
1992d648b2SVijay Khemka  * This define will disable all enhanced features such as strength
2092d648b2SVijay Khemka  * reduction and special function optimisations and expression specific
2192d648b2SVijay Khemka  * type instantiations. This feature will reduce compilation times and
2292d648b2SVijay Khemka  * binary sizes but will also result in massive performance degradation
2392d648b2SVijay Khemka  * of expression evaluations.
2492d648b2SVijay Khemka  */
2592d648b2SVijay Khemka #define exprtk_disable_enhanced_features
2692d648b2SVijay Khemka /*
2792d648b2SVijay Khemka  * This define will disable all string processing capabilities. Any
2892d648b2SVijay Khemka  * expression that contains a string or string related syntax will result
2992d648b2SVijay Khemka  * in a compilation failure.
3092d648b2SVijay Khemka  */
3192d648b2SVijay Khemka #define exprtk_disable_string_capabilities
3292d648b2SVijay Khemka 
3392d648b2SVijay Khemka #define exprtk_disable_rtl_io_file
3492d648b2SVijay Khemka #define exprtk_disable_return_statement
3592d648b2SVijay Khemka #define exprtk_disable_rtl_io
3692d648b2SVijay Khemka #define exprtk_disable_superscalar_unroll
3792d648b2SVijay Khemka 
3892d648b2SVijay Khemka /* include main exprtk header library */
3992d648b2SVijay Khemka #include <exprtk.hpp>
400ab9d838SLei YU 
410ab9d838SLei YU #include <cmath>
420ab9d838SLei YU #include <limits>
430ab9d838SLei YU #include <numeric>
440ab9d838SLei YU 
450ab9d838SLei YU /* For floating types. (float, double, long double et al) */
460ab9d838SLei YU template <typename T>
470ab9d838SLei YU struct FuncMaxIgnoreNaN : public exprtk::ivararg_function<T>
480ab9d838SLei YU {
490ab9d838SLei YU     FuncMaxIgnoreNaN()
500ab9d838SLei YU     {
510ab9d838SLei YU         exprtk::set_min_num_args(*this, 2);
520ab9d838SLei YU         exprtk::set_max_num_args(*this, 255);
530ab9d838SLei YU     }
540ab9d838SLei YU 
550ab9d838SLei YU     inline T operator()(const std::vector<T>& argList)
560ab9d838SLei YU     {
570ab9d838SLei YU         return std::reduce(std::begin(argList), std::end(argList),
580ab9d838SLei YU                            std::numeric_limits<double>::quiet_NaN(),
590ab9d838SLei YU                            [](auto a, auto b) {
600ab9d838SLei YU             if (std::isnan(b))
610ab9d838SLei YU             {
620ab9d838SLei YU                 return a;
630ab9d838SLei YU             }
640ab9d838SLei YU             if (std::isnan(a))
650ab9d838SLei YU             {
660ab9d838SLei YU                 return b;
670ab9d838SLei YU             }
680ab9d838SLei YU             return std::max(a, b);
690ab9d838SLei YU         });
700ab9d838SLei YU     }
710ab9d838SLei YU };
72*87d35115SLei YU 
73*87d35115SLei YU template <typename T>
74*87d35115SLei YU struct FuncSumIgnoreNaN : public exprtk::ivararg_function<T>
75*87d35115SLei YU {
76*87d35115SLei YU     inline T operator()(const std::vector<T>& argList)
77*87d35115SLei YU     {
78*87d35115SLei YU         return std::reduce(std::begin(argList), std::end(argList),
79*87d35115SLei YU                            std::numeric_limits<double>::quiet_NaN(),
80*87d35115SLei YU                            [](auto a, auto b) {
81*87d35115SLei YU             if (std::isnan(b))
82*87d35115SLei YU             {
83*87d35115SLei YU                 return a;
84*87d35115SLei YU             }
85*87d35115SLei YU             if (std::isnan(a))
86*87d35115SLei YU             {
87*87d35115SLei YU                 return b;
88*87d35115SLei YU             }
89*87d35115SLei YU             return a + b;
90*87d35115SLei YU         });
91*87d35115SLei YU     }
92*87d35115SLei YU };
93