Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10742


Ignore:
Timestamp:
Nov 1, 2015, 2:52:04 PM (8 years ago)
Author:
landauf
Message:

use constexpr for some math functions and constants

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/cpp11_v2/src/libraries/util/Math.h

    r9939 r10742  
    7373    namespace math
    7474    {
    75         const float twoPi   = 6.283185482025146484375f;     ///< PI * 2
    76         const float pi      = 3.1415927410125732421875f;    ///< PI
    77         const float pi_2    = 1.57079637050628662109375f;   ///< PI / 2
    78         const float pi_4    = 0.785398185253143310546875f;  ///< PI / 4
    79         const float e       = 2.718281269073486328125f;     ///< e
    80         const float sqrt2   = 1.41421353816986083984375f;   ///< sqrt(2)
    81         const float sqrt2_2 = 0.707106769084930419921875f;  ///< sqrt(2) / 2
     75        constexpr float twoPi   = 6.283185482025146484375f;     ///< PI * 2
     76        constexpr float pi      = 3.1415927410125732421875f;    ///< PI
     77        constexpr float pi_2    = 1.57079637050628662109375f;   ///< PI / 2
     78        constexpr float pi_4    = 0.785398185253143310546875f;  ///< PI / 4
     79        constexpr float e       = 2.718281269073486328125f;     ///< e
     80        constexpr float sqrt2   = 1.41421353816986083984375f;   ///< sqrt(2)
     81        constexpr float sqrt2_2 = 0.707106769084930419921875f;  ///< sqrt(2) / 2
    8282    }
    8383
     
    104104    */
    105105    template <typename T>
    106     inline T sgn(T x)
     106    constexpr inline T sgn(T x)
    107107    {
    108108        return (x >= 0) ? (T)1 : (T)-1;
     
    116116    */
    117117    template <typename T>
    118     inline T clamp(T x, T min, T max)
    119     {
    120         if (x < min)
    121             return min;
    122 
    123         if (x > max)
    124             return max;
    125 
    126         return x;
     118    constexpr inline T clamp(T x, T min, T max)
     119    {
     120        return x < min ? min : (x > max ? max : x);
    127121    }
    128122
     
    131125    */
    132126    template <typename T>
    133     inline T square(T x)
     127    constexpr inline T square(T x)
    134128    {
    135129        return x*x;
     
    140134    */
    141135    template <typename T>
    142     inline T cube(T x)
     136    constexpr inline T cube(T x)
    143137    {
    144138        return x*x*x;
Note: See TracChangeset for help on using the changeset viewer.