From b63ce0dee9c722a0f541d1cefb00691a46a1cb94 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 11 Sep 2007 17:08:06 +0000 Subject: [PATCH] From Art Tevs, Added log2 function. --- include/osg/Math | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/osg/Math b/include/osg/Math index 7ceca75d2..6128dc9e8 100644 --- a/include/osg/Math +++ b/include/osg/Math @@ -114,6 +114,9 @@ namespace osg { const double PI = 3.14159265358979323846; const double PI_2 = 1.57079632679489661923; const double PI_4 = 0.78539816339744830962; +const double LN_2 = 0.69314718055994530942; +const double INVLN_2 = 1.0 / LN_2; + /** return the minimum of two values, equivalent to std::min. * std::min not used because of STL implementation under IRIX not @@ -191,6 +194,10 @@ inline double RadiansToDegrees(double angle) { return angle*180.0/PI; } inline float round(float v) { return v>=0.0f?floorf(v+0.5f):ceilf(v-0.5f); } inline double round(double v) { return v>=0.0?floor(v+0.5):ceil(v-0.5); } +inline float log2(float v) { return static_cast(log(v)) * INVLN_2; } +inline double log2(double v) { return static_cast(log(v)) * INVLN_2; } +inline int log2(int v) { return static_cast(floorf(log(v) * INVLN_2)); } + #if defined(WIN32) && !defined(__CYGWIN__) && !defined(__MWERKS__) inline bool isNaN(float v) { return _isnan(v)!=0; } inline bool isNaN(double v) { return _isnan(v)!=0; }