mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-14 08:45:36 +08:00
committed by
Mathew Sutcliffe
parent
229d7c6068
commit
978f3c88e5
@@ -10,124 +10,124 @@
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Math
|
||||
{
|
||||
|
||||
/*!
|
||||
* \brief Math utils
|
||||
*/
|
||||
class CMath
|
||||
{
|
||||
public:
|
||||
|
||||
/*!
|
||||
* \brief Calculates the hypotenuse of x and y without overflow
|
||||
* \param x
|
||||
* \param y
|
||||
* \return
|
||||
*/
|
||||
static double hypot(double x, double y);
|
||||
|
||||
/*!
|
||||
* \brief Calculates the square of x
|
||||
* \param x
|
||||
* \return
|
||||
*/
|
||||
static inline double square(double x)
|
||||
namespace Math
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Calculates x to the power of three
|
||||
* \param x
|
||||
* \return
|
||||
*/
|
||||
static inline double cubic(const double x)
|
||||
{
|
||||
return x * x * x;
|
||||
}
|
||||
/*!
|
||||
* \brief Math utils
|
||||
*/
|
||||
class CMath
|
||||
{
|
||||
public:
|
||||
|
||||
/*!
|
||||
* \brief Calculates the real cubic root
|
||||
* \param x
|
||||
* \return
|
||||
*/
|
||||
static double cubicRootReal(double x);
|
||||
/*!
|
||||
* \brief Calculates the hypotenuse of x and y without overflow
|
||||
* \param x
|
||||
* \param y
|
||||
* \return
|
||||
*/
|
||||
static double hypot(double x, double y);
|
||||
|
||||
/*!
|
||||
* \brief Utility round method
|
||||
* \param value
|
||||
* \param digits
|
||||
* \return
|
||||
*/
|
||||
static double round(double value, int digits);
|
||||
/*!
|
||||
* \brief Calculates the square of x
|
||||
* \param x
|
||||
* \return
|
||||
*/
|
||||
static inline double square(double x)
|
||||
{
|
||||
return x * x;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Round by given epsilon, e.g.
|
||||
* \param value
|
||||
* \param epsilon
|
||||
* \return
|
||||
*/
|
||||
static double roundEpsilon(double value, double epsilon);
|
||||
/*!
|
||||
* \brief Calculates x to the power of three
|
||||
* \param x
|
||||
* \return
|
||||
*/
|
||||
static inline double cubic(const double x)
|
||||
{
|
||||
return x * x * x;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Nearest integer not greater in magnitude than value, correcting for epsilon
|
||||
* \param value
|
||||
* \param epsilon
|
||||
*/
|
||||
static inline double trunc(double value, double epsilon = 1e-10)
|
||||
{
|
||||
return value < 0 ? ceil(value - epsilon) : floor(value + epsilon);
|
||||
}
|
||||
/*!
|
||||
* \brief Calculates the real cubic root
|
||||
* \param x
|
||||
* \return
|
||||
*/
|
||||
static double cubicRootReal(double x);
|
||||
|
||||
/*!
|
||||
* \brief Fractional part of value
|
||||
* \param value
|
||||
*/
|
||||
static inline double fract(double value)
|
||||
{
|
||||
double unused;
|
||||
return modf(value, &unused);
|
||||
}
|
||||
/*!
|
||||
* \brief Utility round method
|
||||
* \param value
|
||||
* \param digits
|
||||
* \return
|
||||
*/
|
||||
static double round(double value, int digits);
|
||||
|
||||
/*!
|
||||
* \brief PI
|
||||
* \return
|
||||
*/
|
||||
static const double &PIHALF()
|
||||
{
|
||||
static double pi = 2.0 * qAtan(1.0);
|
||||
return pi;
|
||||
}
|
||||
/*!
|
||||
* \brief Round by given epsilon, e.g.
|
||||
* \param value
|
||||
* \param epsilon
|
||||
* \return
|
||||
*/
|
||||
static double roundEpsilon(double value, double epsilon);
|
||||
|
||||
/*!
|
||||
* \brief PI
|
||||
* \return
|
||||
*/
|
||||
static const double &PI()
|
||||
{
|
||||
static double pi = 4.0 * qAtan(1.0);
|
||||
return pi;
|
||||
}
|
||||
/*!
|
||||
* \brief Nearest integer not greater in magnitude than value, correcting for epsilon
|
||||
* \param value
|
||||
* \param epsilon
|
||||
*/
|
||||
static inline double trunc(double value, double epsilon = 1e-10)
|
||||
{
|
||||
return value < 0 ? ceil(value - epsilon) : floor(value + epsilon);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief PI * 2
|
||||
* \return
|
||||
*/
|
||||
static const double &PI2()
|
||||
{
|
||||
static double pi2 = 8.0 * qAtan(1.0);
|
||||
return pi2;
|
||||
}
|
||||
/*!
|
||||
* \brief Fractional part of value
|
||||
* \param value
|
||||
*/
|
||||
static inline double fract(double value)
|
||||
{
|
||||
double unused;
|
||||
return modf(value, &unused);
|
||||
}
|
||||
|
||||
private:
|
||||
/*!
|
||||
* \brief Deleted
|
||||
*/
|
||||
CMath();
|
||||
};
|
||||
/*!
|
||||
* \brief PI
|
||||
* \return
|
||||
*/
|
||||
static const double &PIHALF()
|
||||
{
|
||||
static double pi = 2.0 * qAtan(1.0);
|
||||
return pi;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
/*!
|
||||
* \brief PI
|
||||
* \return
|
||||
*/
|
||||
static const double &PI()
|
||||
{
|
||||
static double pi = 4.0 * qAtan(1.0);
|
||||
return pi;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief PI * 2
|
||||
* \return
|
||||
*/
|
||||
static const double &PI2()
|
||||
{
|
||||
static double pi2 = 8.0 * qAtan(1.0);
|
||||
return pi2;
|
||||
}
|
||||
|
||||
private:
|
||||
/*!
|
||||
* \brief No objects, just static
|
||||
*/
|
||||
CMath();
|
||||
};
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user