18
18
19
19
#include < algorithm>
20
20
#include < cstdint>
21
+ #include < limits>
21
22
#include < vector>
22
23
23
24
#include " absl/base/casts.h"
@@ -141,7 +142,7 @@ class MathUtil {
141
142
// rounding_value must be greater than zero.
142
143
template <typename IntType>
143
144
static IntType RoundUpTo (IntType input_value, IntType rounding_value) {
144
- static_assert (MathLimits <IntType>::kIsInteger ,
145
+ static_assert (std::numeric_limits <IntType>::is_integer ,
145
146
" RoundUpTo() operation type is not integer" );
146
147
DCHECK_GE (input_value, 0 );
147
148
DCHECK_GT (rounding_value, 0 );
@@ -161,19 +162,21 @@ class MathUtil {
161
162
// 1. If x is NaN, the result is zero.
162
163
//
163
164
// 2. If the truncated form of x is above the representable range of IntOut,
164
- // the result is MathLimits <IntOut>::kMax .
165
+ // the result is std::numeric_limits <IntOut>::max() .
165
166
//
166
167
// 3. If the truncated form of x is below the representable range of IntOut,
167
- // the result is MathLimits <IntOut>::kMin .
168
+ // the result is std::numeric_limits <IntOut>::lowest() .
168
169
//
169
170
// Note that cases #2 and #3 cover infinities as well as finite numbers.
170
171
//
171
172
// The range of FloatIn must include the range of IntOut, otherwise
172
173
// the results are undefined.
173
174
template <class IntOut , class FloatIn >
174
175
static IntOut SafeCast (FloatIn x) {
175
- COMPILE_ASSERT (!MathLimits<FloatIn>::kIsInteger , FloatIn_is_integer);
176
- COMPILE_ASSERT (MathLimits<IntOut>::kIsInteger , IntOut_is_not_integer);
176
+ COMPILE_ASSERT (!std::numeric_limits<FloatIn>::is_integer,
177
+ FloatIn_is_integer);
178
+ COMPILE_ASSERT (std::numeric_limits<IntOut>::is_integer,
179
+ IntOut_is_not_integer);
177
180
COMPILE_ASSERT (std::numeric_limits<IntOut>::radix == 2 , IntOut_is_base_2);
178
181
179
182
// Special case NaN, for which the logic below doesn't work.
@@ -182,13 +185,14 @@ class MathUtil {
182
185
}
183
186
184
187
// Negative values all clip to zero for unsigned results.
185
- if (!MathLimits <IntOut>::kIsSigned && x < 0 ) {
188
+ if (!std::numeric_limits <IntOut>::is_signed && x < 0 ) {
186
189
return 0 ;
187
190
}
188
191
189
192
// Handle infinities.
190
193
if (MathLimits<FloatIn>::IsInf (x)) {
191
- return x < 0 ? MathLimits<IntOut>::kMin : MathLimits<IntOut>::kMax ;
194
+ return x < 0 ? std::numeric_limits<IntOut>::lowest ()
195
+ : std::numeric_limits<IntOut>::max ();
192
196
}
193
197
194
198
// Set exp such that x == f * 2^exp for some f with |f| in [0.5, 1.0),
@@ -207,7 +211,8 @@ class MathUtil {
207
211
}
208
212
209
213
// Handle numbers with magnitude >= 2^N.
210
- return x < 0 ? MathLimits<IntOut>::kMin : MathLimits<IntOut>::kMax ;
214
+ return x < 0 ? std::numeric_limits<IntOut>::lowest ()
215
+ : std::numeric_limits<IntOut>::max ();
211
216
}
212
217
213
218
// --------------------------------------------------------------------
@@ -218,15 +223,17 @@ class MathUtil {
218
223
// return type. In those cases, Round has undefined
219
224
// behavior. SafeRound returns 0 when the argument is
220
225
// NaN, and returns the closest possible integer value otherwise (i.e.
221
- // MathLimits <IntOut>::kMax for large positive values, and
222
- // MathLimits <IntOut>::kMin for large negative values).
226
+ // std::numeric_limits <IntOut>::max() for large positive values, and
227
+ // std::numeric_limits <IntOut>::lowest() for large negative values).
223
228
// The range of FloatIn must include the range of IntOut, otherwise
224
229
// the results are undefined.
225
230
// --------------------------------------------------------------------
226
231
template <class IntOut , class FloatIn >
227
232
static IntOut SafeRound (FloatIn x) {
228
- COMPILE_ASSERT (!MathLimits<FloatIn>::kIsInteger , FloatIn_is_integer);
229
- COMPILE_ASSERT (MathLimits<IntOut>::kIsInteger , IntOut_is_not_integer);
233
+ COMPILE_ASSERT (!std::numeric_limits<FloatIn>::is_integer,
234
+ FloatIn_is_integer);
235
+ COMPILE_ASSERT (std::numeric_limits<IntOut>::is_integer,
236
+ IntOut_is_not_integer);
230
237
231
238
if (MathLimits<FloatIn>::IsNaN (x)) {
232
239
return 0 ;
0 commit comments