<commit_before>#ifndef ARC_UTILITIES_MATH_HELPERS_HPP
#define ARC_UTILITIES_MATH_HELPERS_HPP

#include <vector>
#include <cmath>
#include <cstddef>
#include <iostream>
#include <cassert>

namespace EigenHelpers //TODO: Change namespace to ArcMath, breaking change
{
    ////////////////////////////////////////////////////////////////////////////
    // Misc
    ////////////////////////////////////////////////////////////////////////////

    inline bool CloseEnough(const double p1, const double p2, const double threshold)
    {
        const double real_threshold = std::abs(threshold);
        const double abs_delta = std::abs(p2 - p1);
        return abs_delta <= real_threshold;
    }

    inline bool CloseEnough(const std::vector<double> &v1, const std::vector<double> &v2,
                            const double threshold)
    {
        if(v1.size() != v2.size())
        {
            return false;
        }
        for(size_t i=0; i<v1.size(); i++)
        {
            if(!CloseEnough(v1[i], v2[i], threshold))
            {
                return false;
            }
        }
        return true;
    }

    // Inspired by Eigen's "isApprox" function
    inline bool IsApprox(const double p1, const double p2, const double precision)
    {
        const double smallest_element = std::min(std::abs(p1), std::abs(p2));
        const double threshold = precision * smallest_element;
        return CloseEnough(p1, p2, threshold);
    }

    ////////////////////////////////////////////////////////////////////////////
    // Interpolation functions
    ////////////////////////////////////////////////////////////////////////////

    inline double EnforceContinuousRevoluteBounds(const double value)
    {
        if ((value <= -M_PI) || (value > M_PI))
        {
            const double remainder = fmod(value, 2.0 * M_PI);
            if (remainder <= -M_PI)
            {<commit_msg>Added Sign function for signed integers.<commit_after>#ifndef ARC_UTILITIES_MATH_HELPERS_HPP
#define ARC_UTILITIES_MATH_HELPERS_HPP

#include <vector>
#include <cmath>
#include <cstddef>
#include <iostream>
#include <cassert>

namespace EigenHelpers //TODO: Change namespace to ArcMath, breaking change
{
    ////////////////////////////////////////////////////////////////////////////
    // Misc
    ////////////////////////////////////////////////////////////////////////////

    inline bool CloseEnough(const double p1, const double p2, const double threshold)
    {
        const double real_threshold = std::abs(threshold);
        const double abs_delta = std::abs(p2 - p1);
        return abs_delta <= real_threshold;
    }

    inline bool CloseEnough(const std::vector<double> &v1, const std::vector<double> &v2,
                            const double threshold)
    {
        if(v1.size() != v2.size())
        {
            return false;
        }
        for(size_t i=0; i<v1.size(); i++)
        {
            if(!CloseEnough(v1[i], v2[i], threshold))
            {
                return false;
            }
        }
        return true;
    }

    // Inspired by Eigen's "isApprox" function
    inline bool IsApprox(const double p1, const double p2, const double precision)
    {
        const double smallest_element = std::min(std::abs(p1), std::abs(p2));
        const double threshold = precision * smallest_element;
        return CloseEnough(p1, p2, threshold);
    }

    // https://stackoverflow.com/questions/1903954/is-there-a-standard-sign-function-signum-sgn-in-c-c
    // Returns -1, 0, or 1 depending on the sign of val
    template <typename T>
    inline int Sign(const T val)
    {
        return (T(0) < val) - (val < T(0));
    }

    ////////////////////////////////////////////////////////////////////////////
    // Interpolation functions
    ////////////////////////////////////////////////////////////////////////////

    inline double EnforceContinuousRevoluteBounds(const double value)
    {
        if ((value <= -M_PI) || (value > M_PI))
        {
            const double remainder = fmod(value, 2.0 * M_PI);
            if (remainder <= -M_PI)
            {
{'fraction_non_alphanumeric': 0.24113647401651286, 'fraction_numerical': 0.012627489072365225, 'mean_word_length': 1.414419695193435, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 20, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5510915', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1099, 'n_words': 278}