c++templatesc++11exprtk

ExprTk with increased precision


I am trying to compile the ExprTk library with more precision than long double. I thought the simplist would be to try GCC's __float128 but I am getting the following compilation error and am not sure how to correct it.

exprtk.hpp: In instantiation of ‘static T exprtk::details::and_op<T>::process(exprtk::details::and_op<T>::Type, exprtk::details::and_op<T>::Type) [with T = __float128; exprtk::details::and_op<T>::Type = const __float128&]’:
exprtk.hpp:28439:10:   required from ‘void exprtk::parser<T>::load_binary_operations_map(exprtk::parser<T>::binary_op_map_t&) [with T = __float128; exprtk::parser<T>::binary_op_map_t = std::map<exprtk::details::operator_type, __float128 (*)(const __float128&, const __float128&), std::less<exprtk::details::operator_type>, std::allocator<std::pair<const exprtk::details::operator_type, __float128 (*)(const __float128&, const __float128&)> > >; typename exprtk::details::functor_t<T>::bfunc_t = __float128 (*)(const __float128&, const __float128&)]’
exprtk.hpp:15660:51:   required from ‘exprtk::parser<T>::parser(std::size_t) [with T = __float128; std::size_t = long unsigned int]’
mathtof.cpp:18:33:   required from here
exprtk.hpp:9923:105: error: call of overloaded ‘is_true(const __float128&)’ is ambiguous
          static inline T process(Type t1, Type t2) { return (details::is_true(t1) && details::is_true(t2)) ? T(1) : T(0); }
                                                                                                         ^
compilation terminated due to -Wfatal-errors.

EDIT:

I've tried implementing my own is_true

<typename T>
inline bool is_true(const T v)
{
    return std::not_equal_to<T>()(T(0),v);
}

Solution

  • It is rather trivial to specialize ExprTk upon a custom numeric type. There are TWO examples found on the project's page that give a clear and concise means to introduce new numeric types within ExprTk.

    The examples are:

    1. Custom Real Type Adaptor [link]
    2. MPFR Adaptor [link]

    The real type example implements a simple real type using the double type. Furthermore it provides the necessary additions into the ExprTk namespace that needs to be included prior to including the actual ExprTk header.

    The MPFR adaptor builds upon the previous example and shows how one can easily adapt the MPFR/GMP type for use in ExprTk.

    Both examples come packaged with the full test suite and benchmark using the newly introduced types.


    Here is an example where someone has adapted their own type called DScalar to ExprTk:

    https://github.com/filiatra/gismo/blob/stable/external/exprtk_ad_adaptor.hpp

    and here it is being used:

    https://github.com/filiatra/gismo/blob/stable/src/gsCore/gsFunctionExpr.hpp#L146


    It should be noted that one can simply take the "Custom Real Type Adaptor" and search-n-replace the string "real::type" with __float128 and some other minor replace changes and should be all good to go.