📄 toolsmath.h
字号:
#ifndef ToolsMath_h
#define ToolsMath_h
#include "math.h"
#include <stdlib.h>
/*
This "SOFTWARE" is a free software.
You are allowed to download, use, modify and redistribute this software.
The software is provided "AS IS" without warranty of any kind.
Copyright: University of Koblenz-Landau, Dirk Balthasar
*/
/**
\author Dirk Balthasar, 2002, private
*/
namespace tools
{
/// arg*arg
template <class Type>
Type square(Type arg)
{
return arg*arg;
}
/// Return the maximum
template<class t>
t Max(t A, t B)
{
return ((A)>(B)?(A):(B));
}
/// Return the minximum
template<class t>
t Min(t A, t B)
{
return ((A)<(B)?(A):(B));
}
/// n.x -> n if x < 0.5, n+1 if y >= 0.5
inline int round(double d)
{
return (int)floor(d + 0.5);
}
/// random number between [0..1]
inline float Rand()
{
return (float)rand()/(float)RAND_MAX;
}
inline unsigned int CyclePos(int pos, int cycle)
{
if (pos < 0) return (cycle + pos % cycle) % cycle; // second modulo needed if pos == n * -cycle
else
if (pos >= cycle) return pos % cycle;
else
return pos;
}
inline int CycleDiff(int StartPoint, int GoalPoint, int Cycle)
{
if (StartPoint <= GoalPoint)
if (abs (GoalPoint-StartPoint) < abs(GoalPoint-(StartPoint+Cycle)))
return (GoalPoint-StartPoint);
else
return (GoalPoint-(StartPoint+Cycle));
else
if (abs(GoalPoint-StartPoint)<abs(GoalPoint-(StartPoint-Cycle)))
return (GoalPoint-StartPoint);
else
return (GoalPoint-(StartPoint-Cycle));
}
};
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -