36#ifndef LIB2GEOM_SEEN_MATH_UTILS_H
37#define LIB2GEOM_SEEN_MATH_UTILS_H
43#include <boost/math/special_functions/fpclassify.hpp>
51template <
class T>
inline int sgn(
const T& x) {
52 return (x < 0 ? -1 : (x > 0 ? 1 : 0) );
57template <
class T>
inline T
sqr(
const T& x) {
return x * x;}
58template <
class T>
inline T
cube(
const T& x) {
return x * x * x;}
63template <
class T>
inline const T&
between (
const T& min,
const T& max,
const T& x)
64 {
return (
min < x) && (
max > x); }
79 double const multiplier = ::pow(10.0, p);
80 return ::round( x * multiplier ) / multiplier;
89inline void sincos(
double angle,
double &sin_,
double &cos_) {
110 if constexpr (
N == 0) {
113 std::array<int, N> exponents;
114 std::array<double, N> mantissas;
116 for (
size_t i = 0; i <
N; i++) {
117 mantissas[i] = std::frexp(values[i], &exponents[i]);
118 average += exponents[i];
121 for (
size_t i = 0; i <
N; i++) {
122 values[i] = std::ldexp(mantissas[i], exponents[i] - average);
Various utility functions.
SBasisN< n > cos(LinearN< n > bo, int k)
void sincos(double angle, double &sin_, double &cos_)
Simultaneously compute a sine and a cosine of the same angle.
int sgn(const T &x)
Sign function - indicates the sign of a numeric type.
MultiDegree< n > max(MultiDegree< n > const &p, MultiDegree< n > const &q)
Returns the maximal degree appearing in the two arguments for each variables.
const T & between(const T &min, const T &max, const T &x)
Between function - returns true if a number x is within a range: (min < x) && (max > x).
double decimal_round(double x, int p)
Returns x rounded to the nearest multiple of .
int rescale_homogenous(std::array< double, N > &values)
Scale the doubles in the passed array to make them "reasonably large".
Piecewise< SBasis > min(SBasis const &f, SBasis const &g)
Return the more negative of the two functions pointwise.
SBasisN< n > sin(LinearN< n > bo, int k)