All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Macros Pages
fast_exp.hpp
Go to the documentation of this file.
1 //=======================================================================
2 // Copyright (c) 2013 Piotr Wygocki
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
16 #ifndef PAAL_FAST_EXP_HPP
17 #define PAAL_FAST_EXP_HPP
18 
19 #include <cstdint>
20 #include <cmath>
21 
22 namespace paal {
23 
31 inline float fast_pow2(float p) {
32  float clipp = (p < -126) ? -126.0f : p;
33  union {
34  uint32_t i;
35  float f;
36  } v = { static_cast<uint32_t>((1 << 23) * (clipp + 126.94269504f)) };
37  return v.f;
38 }
39 
47 inline float fast_exp(float p) {
48  static const float multiplier = 1 / std::log(2);
49  return fast_pow2(multiplier * p);
50 }
51 }
52 
53 #endif // PAAL_FAST_EXP_HPP
float fast_exp(float p)
fast power of e.
Definition: fast_exp.hpp:47
float fast_pow2(float p)
fast Power of 2
Definition: fast_exp.hpp:31