//
// Copyright (c) 2018-2021 INRIA
//

#pragma once

// IWYU pragma: private, include "pinocchio/math.hpp"

#ifdef PINOCCHIO_LSP
  #undef PINOCCHIO_LSP
  #include "pinocchio/math.hpp"
#endif // PINOCCHIO_LSP

namespace pinocchio
{

  ///
  /// \brief Helper struct to retrieve some useful information for a Taylor series
  ///        expansion according to the a given Scalar type.
  ///
  /// \tparam Scalar the Scalar type of the Taylor series expansion.
  ///
  template<typename Scalar>
  struct TaylorSeriesExpansion
  {
    ///
    /// \brief Computes the expected tolerance of the argument of a Taylor series expansion for a
    /// certain degree
    ///        according to the machine precision of the given input Scalar.
    ///
    /// \tparam degree the degree of the Taylor series expansion.
    ///
    template<int degree>
    static Scalar precision()
    {
      static Scalar value =
        math::pow(std::numeric_limits<Scalar>::epsilon(), Scalar(1) / Scalar(degree + 1));
      return value;
    }

    static Scalar precision(const int degree)
    {
      return math::pow(std::numeric_limits<Scalar>::epsilon(), Scalar(1) / Scalar(degree + 1));
    }
  }; // struct TaylorSeriesExpansion

} // namespace pinocchio
