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 879 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 } | 890 } |
891 | 891 |
892 TEST_F(DecimalTest, RealWorldExampleRangeStepUpStepDown) | 892 TEST_F(DecimalTest, RealWorldExampleRangeStepUpStepDown) |
893 { | 893 { |
894 EXPECT_DECIMAL_STREQ("1e+38", stepUp("0", "1E38", "1", "1E38", 9)); | 894 EXPECT_DECIMAL_STREQ("1e+38", stepUp("0", "1E38", "1", "1E38", 9)); |
895 EXPECT_DECIMAL_STREQ("1e+38", stepDown("0", "1E38", "1", "1E38", 9)); | 895 EXPECT_DECIMAL_STREQ("1e+38", stepDown("0", "1E38", "1", "1E38", 9)); |
896 } | 896 } |
897 | 897 |
898 TEST_F(DecimalTest, Remainder) | 898 TEST_F(DecimalTest, Remainder) |
899 { | 899 { |
900 EXPECT_EQ(encode(9, -1, Negative), encode(21, -1, Positive).remainder(3)); | 900 EXPECT_EQ(encode(21, -1, Positive), encode(21, -1, Positive).remainder(3)); |
901 EXPECT_EQ(Decimal(1), Decimal(10).remainder(3)); | 901 EXPECT_EQ(Decimal(1), Decimal(10).remainder(3)); |
| 902 EXPECT_EQ(Decimal(1), Decimal(10).remainder(-3)); |
902 EXPECT_EQ(encode(1, 0, Negative), Decimal(-10).remainder(3)); | 903 EXPECT_EQ(encode(1, 0, Negative), Decimal(-10).remainder(3)); |
| 904 EXPECT_EQ(Decimal(-1), Decimal(-10).remainder(-3)); |
903 EXPECT_EQ(encode(2, -1, Positive), encode(102, -1, Positive).remainder(1)); | 905 EXPECT_EQ(encode(2, -1, Positive), encode(102, -1, Positive).remainder(1)); |
904 EXPECT_EQ(encode(1, -1, Positive), Decimal(10).remainder(encode(3, -1, Posit
ive))); | 906 EXPECT_EQ(encode(1, -1, Positive), Decimal(10).remainder(encode(3, -1, Posit
ive))); |
905 EXPECT_EQ(encode(3, -1, Negative), encode(36, -1, Positive).remainder(encode
(13, -1, Positive))); | 907 EXPECT_EQ(Decimal(1), encode(36, -1, Positive).remainder(encode(13, -1, Posi
tive))); |
906 EXPECT_EQ(encode(1, 87, Positive), (encode(1234, 100, Positive).remainder(De
cimal(3)))); | 908 EXPECT_EQ(encode(1, 87, Positive), (encode(1234, 100, Positive).remainder(De
cimal(3)))); |
| 909 EXPECT_EQ(Decimal(500), (Decimal(500).remainder(1000))); |
| 910 EXPECT_EQ(Decimal(-500), (Decimal(-500).remainder(1000))); |
907 } | 911 } |
908 | 912 |
909 TEST_F(DecimalTest, RemainderBigExponent) | 913 TEST_F(DecimalTest, RemainderBigExponent) |
910 { | 914 { |
911 EXPECT_EQ(encode(0, 1022, Positive), encode(1, 1022, Positive).remainder(enc
ode(1, 0, Positive))); | 915 EXPECT_EQ(encode(0, 1022, Positive), encode(1, 1022, Positive).remainder(enc
ode(1, 0, Positive))); |
912 EXPECT_EQ(encode(0, 1022, Positive), encode(1, 1022, Positive).remainder(enc
ode(1, 1022, Positive))); | 916 EXPECT_EQ(encode(0, 1022, Positive), encode(1, 1022, Positive).remainder(enc
ode(1, 1022, Positive))); |
913 EXPECT_EQ(Decimal::infinity(Positive), encode(1, 1022, Positive).remainder(e
ncode(1, -1000, Positive))); | 917 EXPECT_EQ(Decimal::infinity(Positive), encode(1, 1022, Positive).remainder(e
ncode(1, -1000, Positive))); |
914 } | 918 } |
915 | 919 |
916 TEST_F(DecimalTest, RemainderSmallExponent) | 920 TEST_F(DecimalTest, RemainderSmallExponent) |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1083 EXPECT_DECIMAL_STREQ("0.001", encode(UINT64_C(99999999999999999), -20, Posit
ive)); | 1087 EXPECT_DECIMAL_STREQ("0.001", encode(UINT64_C(99999999999999999), -20, Posit
ive)); |
1084 EXPECT_DECIMAL_STREQ("1e-83", encode(UINT64_C(99999999999999999), -100, Posi
tive)); | 1088 EXPECT_DECIMAL_STREQ("1e-83", encode(UINT64_C(99999999999999999), -100, Posi
tive)); |
1085 } | 1089 } |
1086 | 1090 |
1087 TEST_F(DecimalTest, ToStringSpecialValues) | 1091 TEST_F(DecimalTest, ToStringSpecialValues) |
1088 { | 1092 { |
1089 EXPECT_DECIMAL_STREQ("Infinity", Decimal::infinity(Positive)); | 1093 EXPECT_DECIMAL_STREQ("Infinity", Decimal::infinity(Positive)); |
1090 EXPECT_DECIMAL_STREQ("-Infinity", Decimal::infinity(Negative)); | 1094 EXPECT_DECIMAL_STREQ("-Infinity", Decimal::infinity(Negative)); |
1091 EXPECT_DECIMAL_STREQ("NaN", Decimal::nan()); | 1095 EXPECT_DECIMAL_STREQ("NaN", Decimal::nan()); |
1092 } | 1096 } |
OLD | NEW |