<commit_before>///
/// @file  isqrt.hpp
/// @brief Integer square root function
///
/// Copyright (C) 2017 <NAME>, <<EMAIL>>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
///

#ifndef ISQRT_HPP
#define ISQRT_HPP

#include <int128_t.hpp>

#include <algorithm>
#include <cmath>

namespace primecount {

#if __cplusplus >= 201402L

/// C++14 compile time square root using binary search
template <typename T>
constexpr T sqrt_helper(T x, T lo, T hi)
{
  if (lo == hi)
    return lo;

  const T mid = (lo + hi + 1) / 2;

  if (x / mid < mid)
    return sqrt_helper<T>(x, lo, mid - 1);
  else
    return sqrt_helper(x, mid, hi);
}

template <typename T>
constexpr T ct_sqrt(T x)
{
  return sqrt_helper<T>(x, 0, x / 2 + 1);
}

#else

#define MID ((lo + hi + 1) / 2)

/// C++11 compile time square root using binary search
template <typename T>
constexpr T sqrt_helper(T x, T lo, T hi)
{
  return lo == hi ? lo : ((x / MID < MID)
      ? sqrt_helper<T>(x, lo, MID - 1) : sqrt_helper<T>(x, MID, hi));
}

template <typename T>
constexpr T ct_sqrt(T x)
{
  return sqrt_helper<T>(x, 0, x / 2 + 1);
}

#endif

template <typename T>
inline T isqrt(T x)
{
  T r = (T) std::sqrt((double) x);

  constexpr T sqrt_max = ct_sqrt(prt::numeric_limits<T>::max());
  r = std::min(r, sqrt_max);

  while (r * r > x)
    r--;
  while (x - r * r > r * 2)
    r++;

  return r;
}

} // namespace

#endif<commit_msg>Get rid of template metapgramming<commit_after>///
/// @file  isqrt.hpp
/// @brief Integer square root function
///
/// Copyright (C) 2017 <NAME>, <<EMAIL>>
///
/// This file is distributed under the BSD License. See the COPYING
/// file in the top level directory.
///

#ifndef ISQRT_HPP
#define ISQRT_HPP

#include <int128_t.hpp>

#include <algorithm>
#include <cmath>

namespace primecount {

template <typename T>
struct isqrt_limits { };

template <> struct isqrt_limits<int8_t>
{ static constexpr int8_t max() { return 11; } };

template <> struct isqrt_limits<uint8_t>
{ static constexpr uint8_t max() { return 15; } };

template <> struct isqrt_limits<int16_t>
{ static constexpr int16_t max() { return 181; } };

template <> struct isqrt_limits<uint16_t>
{ static constexpr uint16_t max() { return 255; } };

template <> struct isqrt_limits<int32_t>
{ static constexpr int32_t max() { return 46340; } };

template <> struct isqrt_limits<uint32_t>
{ static constexpr uint32_t max() { return 65535; } };

template <> struct isqrt_limits<int64_t>
{ static constexpr int64_t max() { return 3037000499ll; } };

template <> struct isqrt_limits<uint64_t>
{ static constexpr uint64_t max() { return 4294967295ull; } };

template <> struct isqrt_limits<int128_t>
{ static constexpr uint64_t max() { return 13043817825332782212ull; } };

template <> struct isqrt_limits<uint128_t>
{ static constexpr uint64_t max() { return 18446744073709551615ull; } };

template <typename T>
inline T isqrt(T x)
{
  T r = (T) std::sqrt((double) x);

  constexpr T max_sqrt = isqrt_limits<T>::max();
  r = std::min(r, max_sqrt);

  while (r * r > x)
    r--;
  while (x - r * r > r * 2)
    r++;

  return r;
}

} // namespace

#endif
{'fraction_non_alphanumeric': 0.14862732723256547, 'fraction_numerical': 0.049226885452824234, 'mean_word_length': 3.541547277936963, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 54, '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': '2049045', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1144, 'n_words': 367}