snoopy/include/math.h

31 lines
608 B
C
Raw Permalink Normal View History

2020-06-06 19:18:20 +02:00
#pragma once
#include <cmath>
const double infinity = std::numeric_limits<double>::infinity();
const double pi = 3.1415926535897932385;
inline double degrees_to_radians(double degrees)
{
return degrees * pi / 180;
}
2020-06-06 22:11:09 +02:00
inline double random_double()
{
// returns a random real in [0,1)
return rand() / (RAND_MAX + 1.0);
}
inline double random_double(double min, double max)
{
// returns a random real in [min,max)
return min + (max-min)*random_double();
}
inline double clamp(double x, double min, double max)
{
if (x < min) return min;
if (x > max) return max;
return x;
}