yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.0
fastlog.h
Go to the documentation of this file.
1/*=====================================================================*
2 * Copyright (C) 2011 Paul Mineiro *
3 * All rights reserved. *
4 * *
5 * Redistribution and use in source and binary forms, with *
6 * or without modification, are permitted provided that the *
7 * following conditions are met: *
8 * *
9 * * Redistributions of source code must retain the *
10 * above copyright notice, this list of conditions and *
11 * the following disclaimer. *
12 * *
13 * * Redistributions in binary form must reproduce the *
14 * above copyright notice, this list of conditions and *
15 * the following disclaimer in the documentation and/or *
16 * other materials provided with the distribution. *
17 * *
18 * * Neither the name of Paul Mineiro nor the names *
19 * of other contributors may be used to endorse or promote *
20 * products derived from this software without specific *
21 * prior written permission. *
22 * *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND *
24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, *
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES *
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER *
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, *
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES *
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE *
31 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR *
32 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
33 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT *
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE *
36 * POSSIBILITY OF SUCH DAMAGE. *
37 * *
38 * Contact: Paul Mineiro <paul@mineiro.com> *
39 *=====================================================================*/
40
41#ifndef __FAST_LOG_H_
42#define __FAST_LOG_H_
43
44#include <stdint.h>
45
46namespace YODA {
47 namespace Utils {
48 static inline float
49 fastlog2 (float x)
50 {
51 union { float f; uint32_t i; } vx = { x };
52 union { uint32_t i; float f; } mx = { (vx.i & 0x007FFFFF) | 0x3f000000 };
53 float y = vx.i;
54 y *= 1.1920928955078125e-7f;
55
56 return y - 124.22551499f
57 - 1.498030302f * mx.f
58 - 1.72587999f / (0.3520887068f + mx.f);
59 }
60
61 static inline float
62 fasterlog2 (float x)
63 {
64 union { float f; uint32_t i; } vx = { x };
65 float y = vx.i;
66 y *= 1.1920928955078125e-7f;
67 return y - 126.94269504f;
68 }
69 }
70}
71#endif // __FAST_LOG_H_
Anonymous namespace to limit visibility.