source:trunk/src/numeric.h@758Tweet

Last change on this file since 758 was 758, checked in by sam, 10 years ago

ps3: start a minimal PS3 port using PSGL, but not CG yet.

File size: 1.2 KB
RevLine
[293]1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11//
12// The Matrix classes
13// ------------------
14//
15
[748]16#if !defined __LOL_NUMERIC_H__
17#define __LOL_NUMERIC_H__
[293]18
19#include <cmath>
20#include <cstdlib>
[296]21#include <stdint.h>
[293]22
[686]23namespace lol
24{
25
[293]26/* Random float value */
27static inline float RandF()
28{
[758]29    return (float)std::rand() / RAND_MAX;
[293]30}
31
32static inline float RandF(float val)
33{
34    return RandF() * val;
35}
36
37static inline float RandF(float min, float max)
38{
39    return min + RandF() * (max - min);
40}
41
42/* Next power of two. */
43template <typename T> static inline T PotUp(T val)
44{
45    val = val - 1;
46    if (sizeof(val) > 4) val = val | ((uint64_t)val >> 32);
47    if (sizeof(val) > 2) val = val | ((uint64_t)val >> 16);
48    if (sizeof(val) > 1) val = val | ((uint64_t)val >> 8);
49    val = val | ((uint64_t)val >> 4);
50    val = val | ((uint64_t)val >> 2);
51    val = val | ((uint64_t)val >> 1);
52    return val + 1;
53}
54
[686]55} /* namespace lol */
56
[748]57#endif // __LOL_NUMERIC_H__
[293]58
Note: See TracBrowser for help on using the repository browser.