OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 Decimal minimum; | 44 Decimal minimum; |
45 Decimal step; | 45 Decimal step; |
46 | 46 |
47 DecimalStepRange(const Decimal& minimum, | 47 DecimalStepRange(const Decimal& minimum, |
48 const Decimal& maximum, | 48 const Decimal& maximum, |
49 const Decimal& step) | 49 const Decimal& step) |
50 : maximum(maximum), minimum(minimum), step(step) {} | 50 : maximum(maximum), minimum(minimum), step(step) {} |
51 | 51 |
52 Decimal ClampValue(Decimal value) const { | 52 Decimal ClampValue(Decimal value) const { |
53 const Decimal result = minimum + ((value - minimum) / step).Round() * step; | 53 const Decimal result = minimum + ((value - minimum) / step).Round() * step; |
54 ASSERT(result.IsFinite()); | 54 DCHECK(result.IsFinite()); |
55 return result > maximum ? result - step : result; | 55 return result > maximum ? result - step : result; |
56 } | 56 } |
57 }; | 57 }; |
58 | 58 |
59 class DecimalTest : public ::testing::Test { | 59 class DecimalTest : public ::testing::Test { |
60 protected: | 60 protected: |
61 using Sign = Decimal::Sign; | 61 using Sign = Decimal::Sign; |
62 static const Sign kPositive = Decimal::kPositive; | 62 static const Sign kPositive = Decimal::kPositive; |
63 static const Sign kNegative = Decimal::kNegative; | 63 static const Sign kNegative = Decimal::kNegative; |
64 | 64 |
(...skipping 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1152 Encode(UINT64_C(99999999999999999), -100, kPositive)); | 1152 Encode(UINT64_C(99999999999999999), -100, kPositive)); |
1153 } | 1153 } |
1154 | 1154 |
1155 TEST_F(DecimalTest, ToStringSpecialValues) { | 1155 TEST_F(DecimalTest, ToStringSpecialValues) { |
1156 EXPECT_DECIMAL_STREQ("Infinity", Decimal::Infinity(kPositive)); | 1156 EXPECT_DECIMAL_STREQ("Infinity", Decimal::Infinity(kPositive)); |
1157 EXPECT_DECIMAL_STREQ("-Infinity", Decimal::Infinity(kNegative)); | 1157 EXPECT_DECIMAL_STREQ("-Infinity", Decimal::Infinity(kNegative)); |
1158 EXPECT_DECIMAL_STREQ("NaN", Decimal::Nan()); | 1158 EXPECT_DECIMAL_STREQ("NaN", Decimal::Nan()); |
1159 } | 1159 } |
1160 | 1160 |
1161 } // namespace blink | 1161 } // namespace blink |
OLD | NEW |