diff options
Diffstat (limited to 'src/common/functions.cc')
-rw-r--r-- | src/common/functions.cc | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/common/functions.cc b/src/common/functions.cc new file mode 100644 index 0000000..7152c91 --- /dev/null +++ b/src/common/functions.cc @@ -0,0 +1,48 @@ +/* functions.cc + * This file is part of the Osirion project + */ + +#include "functions.h" + +float min(float a, float b) { + return (a < b ? a : b); +} + +float max(float a, float b) { + return (a > b ? a : b); +} + +int min(int a, int b) { + return (a < b ? a : b); +} + +int max(int a, int b) { + return (a > b ? a : b); +} + +float randomf(const float max) { + return ((float) rand() / (float) RAND_MAX) * max; +} + +unsigned randomi(const unsigned int max) { + return ((unsigned int)(rand() % max)); +} + +float degreesf(float angle) { + float r = angle; + while (r <= -180.0f) + r += 360.0f; + while (r >= 180.0f) + r -= 360.0f; + return r; +} + +float sgnf(float value) +{ + if (value < 0 ) + return -1; + else if (value == 0 ) + return 0; + + return 1; +} |