glucat  0.12.0
global.h
Go to the documentation of this file.
1 #ifndef _GLUCAT_GLOBAL_H
2 #define _GLUCAT_GLOBAL_H
3 /***************************************************************************
4  GluCat : Generic library of universal Clifford algebra templates
5  global.h : Global declarations
6  -------------------
7  begin : Sun 2001-12-09
8  copyright : (C) 2001-2021 by Paul C. Leopardi
9  ***************************************************************************
10 
11  This library is free software: you can redistribute it and/or modify
12  it under the terms of the GNU Lesser General Public License as published
13  by the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  This library is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU Lesser General Public License for more details.
20 
21  You should have received a copy of the GNU Lesser General Public License
22  along with this library. If not, see <http://www.gnu.org/licenses/>.
23 
24  ***************************************************************************
25  This library is based on a prototype written by Arvind Raja and was
26  licensed under the LGPL with permission of the author. See Arvind Raja,
27  "Object-oriented implementations of Clifford algebras in C++: a prototype",
28  in Ablamowicz, Lounesto and Parra (eds.)
29  "Clifford algebras with numeric and symbolic computations, Birkhauser, 1996."
30  ***************************************************************************
31  See also Arvind Raja's original header comments and references in glucat.h
32  ***************************************************************************/
33 
34 #include "glucat/portability.h"
35 
36 #include <limits>
37 #include <climits>
38 
39 namespace glucat
40 {
41  // References:
42  // [AA]: A. Alexandrescu, "Modern C++ Design", Addison-Wesley, 2001.
43 
45  // Reference: [AA], p. 25
46  template<bool> struct CTAssertion;
47  template<> struct CTAssertion<true> { };
48  #define _GLUCAT_CTAssert(expr, msg) \
49  namespace { struct msg { glucat::CTAssertion<(expr)> ERROR_##msg; }; }
50 
52  // Reference: [AA], pp. 34--37
53  template < typename LHS_T, typename RHS_T >
55  {
56  public:
57  enum { are_same = false };
58  };
59  template < typename T >
60  class compare_types<T, T>
61  {
62  public:
63  enum { are_same = true };
64  };
65 
67  // Reference: [AA], 2.4, p. 29
68  template< bool truth_value >
70  {
71  private:
72  enum { value = truth_value };
73  };
74 
75  // Global types which determine sizes
77  using index_t = int;
79  using set_value_t = unsigned long;
80 
81  // Global constants
83  const double MS_PER_S = 1000.0;
84 
85  // Constants which determine sizes
86 
87  // Bits per unsigned long
88  #if (ULONG_MAX == (4294967295UL))
89  #define _GLUCAT_BITS_PER_ULONG 32
90  #elif (ULONG_MAX == (18446744073709551615UL))
91  #define _GLUCAT_BITS_PER_ULONG 64
92  #elif defined(__WORDSIZE)
93  #define _GLUCAT_BITS_PER_ULONG __WORDSIZE
94  #endif
95 
97  _GLUCAT_CTAssert(std::numeric_limits<unsigned char>::radix == 2, CannotDetermineBitsPerChar)
98 
99 
100  const index_t BITS_PER_CHAR = std::numeric_limits<unsigned char>::digits;
101 
103  const index_t BITS_PER_SET_VALUE = std::numeric_limits<set_value_t>::digits;
104 
105  _GLUCAT_CTAssert(_GLUCAT_BITS_PER_ULONG == BITS_PER_SET_VALUE, BitsPerULongDoesNotMatchSetValueT)
106 
107  // Constants which are determined by size
109  const index_t DEFAULT_LO = -index_t(BITS_PER_SET_VALUE / 2);
112 
114  template< typename LHS_T, typename RHS_T >
115  inline
116  auto
117  pos_mod(LHS_T lhs, RHS_T rhs) -> LHS_T
118  { return lhs > 0? lhs % rhs : (-lhs) % rhs == 0 ? 0 : rhs - (-lhs) % rhs; }
119 
120 }
121 #endif // _GLUCAT_GLOBAL_H
Bool to type.
Definition: global.h:69
const double MS_PER_S
Timing constant: deprecated here - moved to test/timing.h.
Definition: global.h:83
Compile time assertion.
Definition: global.h:46
_GLUCAT_CTAssert(std::numeric_limits< unsigned char >::radix==2, CannotDetermineBitsPerChar) const index_t BITS_PER_CHAR
If radix of unsigned char is not 2, we can&#39;t easily determine number of bits from sizeof...
const index_t BITS_PER_SET_VALUE
Number of bits in set_value_t.
Definition: global.h:103
auto pos_mod(LHS_T lhs, RHS_T rhs) -> LHS_T
Modulo function which works reliably for lhs < 0.
Definition: global.h:117
unsigned long set_value_t
Size of set_value_t should be enough to contain index_set<LO,HI>
Definition: global.h:79
int index_t
Size of index_t should be enough to represent LO, HI.
Definition: global.h:77
Type comparison.
Definition: global.h:54
const index_t DEFAULT_HI
Default highest index in an index set.
Definition: global.h:111