46 lines
978 B
C++
46 lines
978 B
C++
// Copyright 2007 Georgia Institute of Technology. All rights reserved.
|
|
// ABSOLUTELY NOT FOR DISTRIBUTION
|
|
/**
|
|
* @file math.h
|
|
*
|
|
* Includes all basic FASTlib non-vector math utilities.
|
|
*/
|
|
|
|
#ifndef MATH_MATH_H
|
|
#define MATH_MATH_H
|
|
|
|
#include "discrete.h"
|
|
#include "kernel.h"
|
|
#include "geometry.h"
|
|
|
|
/**
|
|
* Namespace with a variety of math routines.
|
|
*/
|
|
namespace math {
|
|
/** Squares a number. */
|
|
template<typename T>
|
|
inline T Sqr(T v) {
|
|
return v * v;
|
|
}
|
|
|
|
/**
|
|
* Forces a number to be non-negative, turning negative numbers into zero.
|
|
*
|
|
* Avoids branching costs (yes, we've discovered measurable improvements).
|
|
*/
|
|
inline double ClampNonNegative(double d) {
|
|
return (d + fabs(d)) / 2;
|
|
}
|
|
|
|
/**
|
|
* Forces a number to be non-positive, turning positive numbers into zero.
|
|
*
|
|
* Avoids branching costs (yes, we've discovered measurable improvements).
|
|
*/
|
|
inline double ClampNonPositive(double d) {
|
|
return (d - fabs(d)) / 2;
|
|
}
|
|
};
|
|
|
|
#endif
|