source: cpp/PrintFloat/MathDragon4.h @ 932

Last change on this file since 932 was 834, checked in by Maciej Komosinski, 6 years ago

Renamed Math.h to MathDragon4.h because the <math.h> name clash is unfortunate (and caused problems with C++Builder and filename case-insensitive Windows)

File size: 1.9 KB
Line 
1/******************************************************************************
2  Copyright (c) 2014 Ryan Juckett
3  http://www.ryanjuckett.com/
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14     claim that you wrote the original software. If you use this software
15     in a product, an acknowledgment in the product documentation would be
16     appreciated but is not required.
17 
18  2. Altered source versions must be plainly marked as such, and must not be
19     misrepresented as being the original software.
20 
21  3. This notice may not be removed or altered from any source
22     distribution.
23******************************************************************************/
24
25#ifndef RJ__Math_h
26#define RJ__Math_h
27
28#include "Standard.h"
29
30//******************************************************************************
31// Get the log base 2 of a 32-bit unsigned integer.
32// http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup
33//******************************************************************************
34tU32 LogBase2( tU32 val );
35
36//******************************************************************************
37// Get the log base 2 of a 64-bit unsigned integer.
38//******************************************************************************
39inline tU32 LogBase2( tU64 val )
40{
41    tU64 temp;
42 
43    temp = val >> 32;
44    if (temp)
45        return 32 + LogBase2((tU32)temp);
46 
47    return LogBase2((tU32)val);
48}
49
50#endif
Note: See TracBrowser for help on using the repository browser.