OSDN Git Service

modified: utilsrc/src/Admin/Makefile
[eos/others.git] / utiltools / X86MAC64 / cuda / include / thrust / detail / numeric_traits.h
1 /*
2  *  Copyright 2008-2012 NVIDIA Corporation
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16
17 #pragma once
18
19 #include <thrust/detail/type_traits.h>
20 #include <limits>
21
22 //#include <stdint.h> // for intmax_t (not provided on MSVS 2005)
23
24 namespace thrust
25 {
26
27 namespace detail
28 {
29
30 // XXX good enough for the platforms we care about
31 typedef long long intmax_t;
32
33 template<typename Number>
34   struct is_signed
35     : integral_constant<bool, std::numeric_limits<Number>::is_signed>
36 {}; // end is_signed
37
38
39 template<typename T>
40   struct num_digits
41     : eval_if<
42         std::numeric_limits<T>::is_specialized,
43         integral_constant<
44           int,
45           std::numeric_limits<T>::digits
46         >,
47         integral_constant<
48           int,
49           sizeof(T) * std::numeric_limits<unsigned char>::digits - (is_signed<T>::value ? 1 : 0)  
50         >
51       >::type
52 {}; // end num_digits
53
54
55 template<typename Integer>
56   struct integer_difference
57     //: eval_if<
58     //    sizeof(Integer) >= sizeof(intmax_t),
59     //    eval_if<
60     //      is_signed<Integer>::value,
61     //      identity_<Integer>,
62     //      identity_<intmax_t>
63     //    >,
64     //    eval_if<
65     //      sizeof(Integer) < sizeof(std::ptrdiff_t),
66     //      identity_<std::ptrdiff_t>,
67     //      identity_<intmax_t>
68     //    >
69     //  >
70 {
71   private:
72     // XXX workaround a pedantic warning in old versions of g++
73     //     which complains about &&ing with a constant value
74     template<bool x, bool y>
75       struct and_
76     {
77       static const bool value = false;
78     };
79
80     template<bool y>
81       struct and_<true,y>
82     {
83       static const bool value = y;
84     };
85
86   public:
87     typedef typename
88       eval_if<
89         and_<
90           std::numeric_limits<Integer>::is_signed,
91           // digits is the number of no-sign bits
92           (!std::numeric_limits<Integer>::is_bounded || (int(std::numeric_limits<Integer>::digits) + 1 >= num_digits<intmax_t>::value))
93         >::value,
94         identity_<Integer>,
95         eval_if<
96           int(std::numeric_limits<Integer>::digits) + 1 < num_digits<signed int>::value,
97           identity_<signed int>,
98           eval_if<
99             int(std::numeric_limits<Integer>::digits) + 1 < num_digits<signed long>::value,
100             identity_<signed long>,
101             identity_<intmax_t>
102           >
103         >
104       >::type type;
105 }; // end integer_difference
106
107
108 template<typename Number>
109   struct numeric_difference
110     : eval_if<
111       is_integral<Number>::value,
112       integer_difference<Number>,
113       identity_<Number>
114     >
115 {}; // end numeric_difference
116
117
118 template<typename Number>
119 __host__ __device__
120 typename numeric_difference<Number>::type
121 numeric_distance(Number x, Number y)
122 {
123   typedef typename numeric_difference<Number>::type difference_type;
124   return difference_type(y) - difference_type(x);
125 } // end numeric_distance
126
127 } // end detail
128
129 } // end thrust
130