OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/base/bits.h" | 5 #include "src/base/bits.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "src/base/logging.h" | 9 #include "src/base/logging.h" |
10 | 10 |
(...skipping 30 matching lines...) Expand all Loading... |
41 if (rhs == -1) return -lhs; | 41 if (rhs == -1) return -lhs; |
42 return lhs / rhs; | 42 return lhs / rhs; |
43 } | 43 } |
44 | 44 |
45 | 45 |
46 int32_t SignedMod32(int32_t lhs, int32_t rhs) { | 46 int32_t SignedMod32(int32_t lhs, int32_t rhs) { |
47 if (rhs == 0 || rhs == -1) return 0; | 47 if (rhs == 0 || rhs == -1) return 0; |
48 return lhs % rhs; | 48 return lhs % rhs; |
49 } | 49 } |
50 | 50 |
| 51 |
| 52 int64_t FromCheckedNumeric(const CheckedNumeric<int64_t> value) { |
| 53 if (value.IsValid()) |
| 54 return value.ValueUnsafe(); |
| 55 |
| 56 // We could return max/min but we don't really expose what the maximum delta |
| 57 // is. Instead, return max/(-max), which is something that clients can reason |
| 58 // about. |
| 59 // TODO(rvargas) crbug.com/332611: don't use internal values. |
| 60 int64_t limit = std::numeric_limits<int64_t>::max(); |
| 61 if (value.validity() == internal::RANGE_UNDERFLOW) |
| 62 limit = -limit; |
| 63 return value.ValueOrDefault(limit); |
| 64 } |
| 65 |
51 } // namespace bits | 66 } // namespace bits |
52 } // namespace base | 67 } // namespace base |
53 } // namespace v8 | 68 } // namespace v8 |
OLD | NEW |