#pragma once

namespace Juliet
{
// From MUSL lib https://github.com/rofl0r/musl
#ifndef fp_force_evalf
#define fp_force_evalf fp_force_evalf
    static inline void fp_force_evalf(float x)
    {
        volatile float y;
        y = x;
        (void)y;
    }
#endif

#ifndef fp_force_eval
#define fp_force_eval fp_force_eval
    static inline void fp_force_eval(double x)
    {
        volatile double y;
        y = x;
        (void)y;
    }
#endif

#ifndef fp_force_evall
#define fp_force_evall fp_force_evall
    static inline void fp_force_evall(long double x)
    {
        volatile long double y;
        y = x;
        (void)y;
    }
#endif

    template <typename T>
    inline void ForceEval(T x)
    {
        if constexpr (std::is_same_v<T, float>)
        {
            fp_force_evalf(x);
        }
        else if constexpr (std::is_same_v<T, double>)
        {
            fp_force_eval(x);
        }
        else
        {
            fp_force_evall(x);
        }
    }

} // namespace Juliet
