Last change
on this file since 761 was
761,
checked in by sam, 10 years ago
|
core: don't explicitly use std:: prefix when the platform may not
recognise it.
|
File size:
1.2 KB
|
Line | |
---|
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 |
---|
7 | // Public License, Version 2, as published by Sam Hocevar. See |
---|
8 | // http://sam.zoy.org/projects/COPYING.WTFPL for more details. |
---|
9 | // |
---|
10 | |
---|
11 | // |
---|
12 | // The Matrix classes |
---|
13 | // ------------------ |
---|
14 | // |
---|
15 | |
---|
16 | #if !defined __LOL_NUMERIC_H__ |
---|
17 | #define __LOL_NUMERIC_H__ |
---|
18 | |
---|
19 | #include <cmath> |
---|
20 | #include <cstdlib> |
---|
21 | #include <stdint.h> |
---|
22 | |
---|
23 | namespace lol |
---|
24 | { |
---|
25 | |
---|
26 | /* Random float value */ |
---|
27 | static inline float RandF() |
---|
28 | { |
---|
29 | using namespace std; |
---|
30 | return (float)rand() / RAND_MAX; |
---|
31 | } |
---|
32 | |
---|
33 | static inline float RandF(float val) |
---|
34 | { |
---|
35 | return RandF() * val; |
---|
36 | } |
---|
37 | |
---|
38 | static inline float RandF(float min, float max) |
---|
39 | { |
---|
40 | return min + RandF() * (max - min); |
---|
41 | } |
---|
42 | |
---|
43 | /* Next power of two. */ |
---|
44 | template <typename T> static inline T PotUp(T val) |
---|
45 | { |
---|
46 | val = val - 1; |
---|
47 | if (sizeof(val) > 4) val = val | ((uint64_t)val >> 32); |
---|
48 | if (sizeof(val) > 2) val = val | ((uint64_t)val >> 16); |
---|
49 | if (sizeof(val) > 1) val = val | ((uint64_t)val >> 8); |
---|
50 | val = val | ((uint64_t)val >> 4); |
---|
51 | val = val | ((uint64_t)val >> 2); |
---|
52 | val = val | ((uint64_t)val >> 1); |
---|
53 | return val + 1; |
---|
54 | } |
---|
55 | |
---|
56 | } /* namespace lol */ |
---|
57 | |
---|
58 | #endif // __LOL_NUMERIC_H__ |
---|
59 | |
---|
Note: See
TracBrowser
for help on using the repository browser.