<commit_before>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2013.  All rights reserved
 */
#ifndef _Stroika_Foundation_Math_Basic_h_
#define _Stroika_Foundation_Math_Basic_h_   1

#include    "../StroikaPreComp.h"

#include    <cmath>         // though perhaps not strictly needed, probably wanted if including Stroika/Foundation/Math/Common.h
#include    <limits>


/*
 *  TODO:
 *      @todo   This rounding code doesn't work for floating point numbers. That should either be fixed
 *              or documented better why.
 */



namespace   Stroika {
    namespace   Foundation {
        namespace   Math {

            using   std::numeric_limits;

            double  nan ();

            const   double  kE  =   2.71828182845904523536;
            const   double  kPi =   3.14159265358979323846;


            /**
             * RoundUpTo() - round towards positive infinity.
             *
             *  T can be any of int, long, or long long, or unsigned int, or unsigned long, or unsigned long long
             *  (after review of this API/implementation, probably should add short/char with unsigned variants
             *  to this list)
             */
            template    <typename T>
            T   RoundUpTo (T x, T toNearest);

            /**
             *  RoundDownTo() - round towards negative infinity.
             *
             *  T can be any of int, long, or long long, or unsigned int, or unsigned long, or unsigned long long
             *  (after review of this API/implementation, probably should add short/char with unsigned variants
             *  to this list)
             */
            template    <typename T>
            T   RoundDownTo (T x, T toNearest);



            /**
             *  NearlyEquals() can be used as a utility for floating point comparisons.
             */
#if  qCompilerAndStdLib_TemplateCompileWithNumericLimitsCompilerBug
            template    <typename   T>
            T   NearlyEquals (T l, T r, T epsilon = (1000 * numeric_limits<float>::epsilon()));
#else
            template    <typename   T>
            T   NearlyEquals (T l, T r, T epsilon = (1000 * numeric_limits<T>::epsilon()));
#endif


        }
    }
}

#if     !qCompilerAndStdLib_isnan
// SB in std namespace
namespace   std {
    bool    isnan (float f);
    bool    isnan (double d);
}
#endif


#endif  /*_Stroika_Foundation_Math_Basic_h_*/





/*
 ********************************************************************************
 ***************************** Implementation Details ***************************
 ********************************************************************************
 */
#include    "Common.inl"

<commit_msg>Math/Common constants SB constexpr<commit_after>/*
 * Copyright(c) Sophist Solutions, Inc. 1990-2013.  All rights reserved
 */
#ifndef _Stroika_Foundation_Math_Basic_h_
#define _Stroika_Foundation_Math_Basic_h_   1

#include    "../StroikaPreComp.h"

#include    <cmath>         // though perhaps not strictly needed, probably wanted if including Stroika/Foundation/Math/Common.h
#include    <limits>


/*
 *  TODO:
 *      @todo   This rounding code doesn't work for floating point numbers. That should either be fixed
 *              or documented better why.
 */

namespace   Stroika {
    namespace   Foundation {
        namespace   Math {

            using   std::numeric_limits;


            double  nan ();


            constexpr   double  kE  =   2.71828182845904523536;
            constexpr   double  kPi =   3.14159265358979323846;


            /**
             * RoundUpTo() - round towards positive infinity.
             *
             *  T can be any of int, long, or long long, or unsigned int, or unsigned long, or unsigned long long
             *  (after review of this API/implementation, probably should add short/char with unsigned variants
             *  to this list)
             */
            template    <typename T>
            T   RoundUpTo (T x, T toNearest);


            /**
             *  RoundDownTo() - round towards negative infinity.
             *
             *  T can be any of int, long, or long long, or unsigned int, or unsigned long, or unsigned long long
             *  (after review of this API/implementation, probably should add short/char with unsigned variants
             *  to this list)
             */
            template    <typename T>
            T   RoundDownTo (T x, T toNearest);


            /**
             *  NearlyEquals() can be used as a utility for floating point comparisons.
             */
#if  qCompilerAndStdLib_TemplateCompileWithNumericLimitsCompilerBug
            template    <typename   T>
            T   NearlyEquals (T l, T r, T epsilon = (1000 * numeric_limits<float>::epsilon()));
#else
            template    <typename   T>
            T   NearlyEquals (T l, T r, T epsilon = (1000 * numeric_limits<T>::epsilon()));
#endif


        }
    }
}

#if     !qCompilerAndStdLib_isnan
// SB in std namespace
namespace   std {
    bool    isnan (float f);
    bool    isnan (double d);
}
#endif


#endif  /*_Stroika_Foundation_Math_Basic_h_*/





/*
 ********************************************************************************
 ***************************** Implementation Details ***************************
 ********************************************************************************
 */
#include    "Common.inl"
{'fraction_non_alphanumeric': 0.15343327780862484, 'fraction_numerical': 0.021839718674810292, 'mean_word_length': 2.125506072874494, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, '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': '818232', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1385, 'n_words': 463}