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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 } | 218 } |
219 | 219 |
220 TEST_F(DecimalTest, Ceiling) | 220 TEST_F(DecimalTest, Ceiling) |
221 { | 221 { |
222 EXPECT_EQ(Decimal(1), Decimal(1).ceiling()); | 222 EXPECT_EQ(Decimal(1), Decimal(1).ceiling()); |
223 EXPECT_EQ(Decimal(1), encode(1, -10, Positive).ceiling()); | 223 EXPECT_EQ(Decimal(1), encode(1, -10, Positive).ceiling()); |
224 EXPECT_EQ(Decimal(2), encode(11, -1, Positive).ceiling()); | 224 EXPECT_EQ(Decimal(2), encode(11, -1, Positive).ceiling()); |
225 EXPECT_EQ(Decimal(2), encode(13, -1, Positive).ceiling()); | 225 EXPECT_EQ(Decimal(2), encode(13, -1, Positive).ceiling()); |
226 EXPECT_EQ(Decimal(2), encode(15, -1, Positive).ceiling()); | 226 EXPECT_EQ(Decimal(2), encode(15, -1, Positive).ceiling()); |
227 EXPECT_EQ(Decimal(2), encode(19, -1, Positive).ceiling()); | 227 EXPECT_EQ(Decimal(2), encode(19, -1, Positive).ceiling()); |
| 228 EXPECT_EQ(Decimal(2), encode(151, -2, Positive).ceiling()); |
| 229 EXPECT_EQ(Decimal(2), encode(101, -2, Positive).ceiling()); |
| 230 EXPECT_EQ(Decimal(1), encode(199, -3, Positive).ceiling()); |
| 231 EXPECT_EQ(Decimal(2), encode(199, -2, Positive).ceiling()); |
| 232 EXPECT_EQ(Decimal(3), encode(209, -2, Positive).ceiling()); |
228 | 233 |
229 EXPECT_EQ(Decimal(-1), Decimal(-1).ceiling()); | 234 EXPECT_EQ(Decimal(-1), Decimal(-1).ceiling()); |
230 EXPECT_EQ(Decimal(0), encode(1, -10, Negative).ceiling()); | 235 EXPECT_EQ(Decimal(0), encode(1, -10, Negative).ceiling()); |
231 EXPECT_EQ(Decimal(-1), encode(11, -1, Negative).ceiling()); | 236 EXPECT_EQ(Decimal(-1), encode(11, -1, Negative).ceiling()); |
232 EXPECT_EQ(Decimal(-1), encode(13, -1, Negative).ceiling()); | 237 EXPECT_EQ(Decimal(-1), encode(13, -1, Negative).ceiling()); |
233 EXPECT_EQ(Decimal(-1), encode(15, -1, Negative).ceiling()); | 238 EXPECT_EQ(Decimal(-1), encode(15, -1, Negative).ceiling()); |
234 EXPECT_EQ(Decimal(-1), encode(19, -1, Negative).ceiling()); | 239 EXPECT_EQ(Decimal(-1), encode(19, -1, Negative).ceiling()); |
| 240 EXPECT_EQ(Decimal(-1), encode(151, -2, Negative).ceiling()); |
| 241 EXPECT_EQ(Decimal(-1), encode(101, -2, Negative).ceiling()); |
| 242 EXPECT_EQ(Decimal(0), encode(199, -3, Negative).ceiling()); |
| 243 EXPECT_EQ(Decimal(-1), encode(199, -2, Negative).ceiling()); |
| 244 EXPECT_EQ(Decimal(-2), encode(209, -2, Negative).ceiling()); |
235 } | 245 } |
236 | 246 |
237 TEST_F(DecimalTest, CeilingBigExponent) | 247 TEST_F(DecimalTest, CeilingBigExponent) |
238 { | 248 { |
239 EXPECT_EQ(encode(1, 1000, Positive), encode(1, 1000, Positive).ceiling()); | 249 EXPECT_EQ(encode(1, 1000, Positive), encode(1, 1000, Positive).ceiling()); |
240 EXPECT_EQ(encode(1, 1000, Negative), encode(1, 1000, Negative).ceiling()); | 250 EXPECT_EQ(encode(1, 1000, Negative), encode(1, 1000, Negative).ceiling()); |
241 } | 251 } |
242 | 252 |
243 TEST_F(DecimalTest, CeilingSmallExponent) | 253 TEST_F(DecimalTest, CeilingSmallExponent) |
244 { | 254 { |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
556 } | 566 } |
557 | 567 |
558 TEST_F(DecimalTest, Floor) | 568 TEST_F(DecimalTest, Floor) |
559 { | 569 { |
560 EXPECT_EQ(Decimal(1), Decimal(1).floor()); | 570 EXPECT_EQ(Decimal(1), Decimal(1).floor()); |
561 EXPECT_EQ(Decimal(0), encode(1, -10, Positive).floor()); | 571 EXPECT_EQ(Decimal(0), encode(1, -10, Positive).floor()); |
562 EXPECT_EQ(Decimal(1), encode(11, -1, Positive).floor()); | 572 EXPECT_EQ(Decimal(1), encode(11, -1, Positive).floor()); |
563 EXPECT_EQ(Decimal(1), encode(13, -1, Positive).floor()); | 573 EXPECT_EQ(Decimal(1), encode(13, -1, Positive).floor()); |
564 EXPECT_EQ(Decimal(1), encode(15, -1, Positive).floor()); | 574 EXPECT_EQ(Decimal(1), encode(15, -1, Positive).floor()); |
565 EXPECT_EQ(Decimal(1), encode(19, -1, Positive).floor()); | 575 EXPECT_EQ(Decimal(1), encode(19, -1, Positive).floor()); |
| 576 EXPECT_EQ(Decimal(1), encode(193332, -5, Positive).floor()); |
| 577 EXPECT_EQ(Decimal(12), encode(12002, -3, Positive).floor()); |
566 | 578 |
567 EXPECT_EQ(Decimal(-1), Decimal(-1).floor()); | 579 EXPECT_EQ(Decimal(-1), Decimal(-1).floor()); |
568 EXPECT_EQ(Decimal(-1), encode(1, -10, Negative).floor()); | 580 EXPECT_EQ(Decimal(-1), encode(1, -10, Negative).floor()); |
569 EXPECT_EQ(Decimal(-2), encode(11, -1, Negative).floor()); | 581 EXPECT_EQ(Decimal(-2), encode(11, -1, Negative).floor()); |
570 EXPECT_EQ(Decimal(-2), encode(13, -1, Negative).floor()); | 582 EXPECT_EQ(Decimal(-2), encode(13, -1, Negative).floor()); |
571 EXPECT_EQ(Decimal(-2), encode(15, -1, Negative).floor()); | 583 EXPECT_EQ(Decimal(-2), encode(15, -1, Negative).floor()); |
572 EXPECT_EQ(Decimal(-2), encode(19, -1, Negative).floor()); | 584 EXPECT_EQ(Decimal(-2), encode(19, -1, Negative).floor()); |
| 585 EXPECT_EQ(Decimal(-2), encode(193332, -5, Negative).floor()); |
| 586 EXPECT_EQ(Decimal(-13), encode(12002, -3, Negative).floor()); |
573 } | 587 } |
574 | 588 |
575 TEST_F(DecimalTest, FloorBigExponent) | 589 TEST_F(DecimalTest, FloorBigExponent) |
576 { | 590 { |
577 EXPECT_EQ(encode(1, 1000, Positive), encode(1, 1000, Positive).floor()); | 591 EXPECT_EQ(encode(1, 1000, Positive), encode(1, 1000, Positive).floor()); |
578 EXPECT_EQ(encode(1, 1000, Negative), encode(1, 1000, Negative).floor()); | 592 EXPECT_EQ(encode(1, 1000, Negative), encode(1, 1000, Negative).floor()); |
579 } | 593 } |
580 | 594 |
581 TEST_F(DecimalTest, FloorSmallExponent) | 595 TEST_F(DecimalTest, FloorSmallExponent) |
582 { | 596 { |
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
952 EXPECT_EQ(Decimal(1), (Decimal(9) / Decimal(10)).round()); | 966 EXPECT_EQ(Decimal(1), (Decimal(9) / Decimal(10)).round()); |
953 EXPECT_EQ(Decimal(25), (Decimal(5) / fromString("0.200")).round()); | 967 EXPECT_EQ(Decimal(25), (Decimal(5) / fromString("0.200")).round()); |
954 EXPECT_EQ(Decimal(3), (Decimal(5) / Decimal(2)).round()); | 968 EXPECT_EQ(Decimal(3), (Decimal(5) / Decimal(2)).round()); |
955 EXPECT_EQ(Decimal(1), (Decimal(2) / Decimal(3)).round()); | 969 EXPECT_EQ(Decimal(1), (Decimal(2) / Decimal(3)).round()); |
956 EXPECT_EQ(Decimal(3), (Decimal(10) / Decimal(3)).round()); | 970 EXPECT_EQ(Decimal(3), (Decimal(10) / Decimal(3)).round()); |
957 EXPECT_EQ(Decimal(3), (Decimal(1) / fromString("0.3")).round()); | 971 EXPECT_EQ(Decimal(3), (Decimal(1) / fromString("0.3")).round()); |
958 EXPECT_EQ(Decimal(10), (Decimal(1) / fromString("0.1")).round()); | 972 EXPECT_EQ(Decimal(10), (Decimal(1) / fromString("0.1")).round()); |
959 EXPECT_EQ(Decimal(5), (Decimal(1) / fromString("0.2")).round()); | 973 EXPECT_EQ(Decimal(5), (Decimal(1) / fromString("0.2")).round()); |
960 EXPECT_EQ(Decimal(10), (fromString("10.2") / 1).round()); | 974 EXPECT_EQ(Decimal(10), (fromString("10.2") / 1).round()); |
961 EXPECT_EQ(encode(1234, 100, Positive), encode(1234, 100, Positive).round()); | 975 EXPECT_EQ(encode(1234, 100, Positive), encode(1234, 100, Positive).round()); |
| 976 |
| 977 EXPECT_EQ(Decimal(2), encode(190002, -5, Positive).round()); |
| 978 EXPECT_EQ(Decimal(2), encode(150002, -5, Positive).round()); |
| 979 EXPECT_EQ(Decimal(2), encode(150000, -5, Positive).round()); |
| 980 EXPECT_EQ(Decimal(12), encode(12492, -3, Positive).round()); |
| 981 EXPECT_EQ(Decimal(13), encode(12502, -3, Positive).round()); |
| 982 |
| 983 EXPECT_EQ(Decimal(-2), encode(190002, -5, Negative).round()); |
| 984 EXPECT_EQ(Decimal(-2), encode(150002, -5, Negative).round()); |
| 985 EXPECT_EQ(Decimal(-2), encode(150000, -5, Negative).round()); |
| 986 EXPECT_EQ(Decimal(-12), encode(12492, -3, Negative).round()); |
| 987 EXPECT_EQ(Decimal(-13), encode(12502, -3, Negative).round()); |
962 } | 988 } |
963 | 989 |
964 TEST_F(DecimalTest, RoundSpecialValues) | 990 TEST_F(DecimalTest, RoundSpecialValues) |
965 { | 991 { |
966 EXPECT_EQ(Decimal::infinity(Positive), Decimal::infinity(Positive).round()); | 992 EXPECT_EQ(Decimal::infinity(Positive), Decimal::infinity(Positive).round()); |
967 EXPECT_EQ(Decimal::infinity(Negative), Decimal::infinity(Negative).round()); | 993 EXPECT_EQ(Decimal::infinity(Negative), Decimal::infinity(Negative).round()); |
968 EXPECT_EQ(Decimal::nan(), Decimal::nan().round()); | 994 EXPECT_EQ(Decimal::nan(), Decimal::nan().round()); |
969 } | 995 } |
970 | 996 |
971 TEST_F(DecimalTest, Subtract) | 997 TEST_F(DecimalTest, Subtract) |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1088 EXPECT_DECIMAL_STREQ("0.001", encode(UINT64_C(99999999999999999), -20, Posit
ive)); | 1114 EXPECT_DECIMAL_STREQ("0.001", encode(UINT64_C(99999999999999999), -20, Posit
ive)); |
1089 EXPECT_DECIMAL_STREQ("1e-83", encode(UINT64_C(99999999999999999), -100, Posi
tive)); | 1115 EXPECT_DECIMAL_STREQ("1e-83", encode(UINT64_C(99999999999999999), -100, Posi
tive)); |
1090 } | 1116 } |
1091 | 1117 |
1092 TEST_F(DecimalTest, ToStringSpecialValues) | 1118 TEST_F(DecimalTest, ToStringSpecialValues) |
1093 { | 1119 { |
1094 EXPECT_DECIMAL_STREQ("Infinity", Decimal::infinity(Positive)); | 1120 EXPECT_DECIMAL_STREQ("Infinity", Decimal::infinity(Positive)); |
1095 EXPECT_DECIMAL_STREQ("-Infinity", Decimal::infinity(Negative)); | 1121 EXPECT_DECIMAL_STREQ("-Infinity", Decimal::infinity(Negative)); |
1096 EXPECT_DECIMAL_STREQ("NaN", Decimal::nan()); | 1122 EXPECT_DECIMAL_STREQ("NaN", Decimal::nan()); |
1097 } | 1123 } |
OLD | NEW |