[Assorted-commits] SF.net SVN: assorted:[1488] cpp-commons/trunk/src/commons/math.h
Brought to you by:
yangzhang
From: <yan...@us...> - 2009-10-14 18:05:00
|
Revision: 1488 http://assorted.svn.sourceforge.net/assorted/?rev=1488&view=rev Author: yangzhang Date: 2009-10-14 18:04:49 +0000 (Wed, 14 Oct 2009) Log Message: ----------- added math.h Added Paths: ----------- cpp-commons/trunk/src/commons/math.h Added: cpp-commons/trunk/src/commons/math.h =================================================================== --- cpp-commons/trunk/src/commons/math.h (rev 0) +++ cpp-commons/trunk/src/commons/math.h 2009-10-14 18:04:49 UTC (rev 1488) @@ -0,0 +1,20 @@ +#ifndef COMMONS_MATH_H +#define COMMONS_MATH_H + +#include <cmath> + +namespace commons { + + using namespace std; + + /* Round to integer. See also boost/math/special_functions/round.hpp. */ + template<typename T> + T round(T x) { return floor(x + .5); } + + /* Round number n to d decimal points. */ + template<typename T, typename U> + T round(T n, U d) { return floor(n / pow(.1, d) + .5) * pow(.1, d); } + +} + +#endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |