michael@0: /* michael@0: * Copyright 2011 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: #ifndef SkConstexprMath_DEFINED michael@0: #define SkConstexprMath_DEFINED michael@0: michael@0: #include "SkTypes.h" michael@0: #include michael@0: michael@0: template michael@0: struct SK_LOG { michael@0: //! Compile-time constant ceiling(logB(N)). michael@0: static const uintmax_t value = 1 + SK_LOG::value; michael@0: }; michael@0: template michael@0: struct SK_LOG<1, B> { michael@0: static const uintmax_t value = 0; michael@0: }; michael@0: template michael@0: struct SK_LOG<0, B> { michael@0: static const uintmax_t value = 0; michael@0: }; michael@0: michael@0: template michael@0: struct SK_2N1 { michael@0: //! Compile-time constant (2^N)-1. michael@0: static const uintmax_t value = (SK_2N1::value << 1) + 1; michael@0: }; michael@0: template<> michael@0: struct SK_2N1<1> { michael@0: static const uintmax_t value = 1; michael@0: }; michael@0: michael@0: /** Compile-time constant number of base n digits in type t michael@0: if the bits of type t are considered as unsigned base two. michael@0: */ michael@0: #define SK_BASE_N_DIGITS_IN(n, t) (\ michael@0: SK_LOG::value, n>::value\ michael@0: ) michael@0: /** Compile-time constant number of base 10 digits in type t michael@0: if the bits of type t are considered as unsigned base two. michael@0: */ michael@0: #define SK_DIGITS_IN(t) SK_BASE_N_DIGITS_IN(10, (t)) michael@0: michael@0: // Compile-time constant maximum value of two unsigned values. michael@0: template struct SkTUMax { michael@0: static const uintmax_t value = (b < a) ? a : b; michael@0: }; michael@0: michael@0: #endif