| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 result = static_cast<uint32_t>(big_result); | 64 result = static_cast<uint32_t>(big_result); |
| 65 } | 65 } |
| 66 if (static_cast<int32_t>(exponent_bits) < 0) { | 66 if (static_cast<int32_t>(exponent_bits) < 0) { |
| 67 return (0 - result); | 67 return (0 - result); |
| 68 } else { | 68 } else { |
| 69 return result; | 69 return result; |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 | 73 |
| 74 void RunOneTruncationTestWithTest(ConvertDToIFunc func, | 74 void RunOneTruncationTestWithTest(ConvertDToICallWrapper callWrapper, |
| 75 ConvertDToIFunc func, |
| 75 double from, | 76 double from, |
| 76 double raw) { | 77 double raw) { |
| 77 uint64_t to = static_cast<int64_t>(raw); | 78 uint64_t to = static_cast<int64_t>(raw); |
| 78 int result = (*func)(from); | 79 int result = (*callWrapper)(func, from); |
| 79 CHECK_EQ(static_cast<int>(to), result); | 80 CHECK_EQ(static_cast<int>(to), result); |
| 80 } | 81 } |
| 81 | 82 |
| 82 | 83 |
| 84 int32_t DefaultCallWrapper(ConvertDToIFunc func, |
| 85 double from) { |
| 86 return (*func)(from); |
| 87 } |
| 88 |
| 89 |
| 83 // #define NaN and Infinity so that it's possible to cut-and-paste these tests | 90 // #define NaN and Infinity so that it's possible to cut-and-paste these tests |
| 84 // directly to a .js file and run them. | 91 // directly to a .js file and run them. |
| 85 #define NaN (OS::nan_value()) | 92 #define NaN (OS::nan_value()) |
| 86 #define Infinity (std::numeric_limits<double>::infinity()) | 93 #define Infinity (std::numeric_limits<double>::infinity()) |
| 87 #define RunOneTruncationTest(p1, p2) RunOneTruncationTestWithTest(func, p1, p2) | 94 #define RunOneTruncationTest(p1, p2) \ |
| 95 RunOneTruncationTestWithTest(callWrapper, func, p1, p2) |
| 96 |
| 88 | 97 |
| 89 void RunAllTruncationTests(ConvertDToIFunc func) { | 98 void RunAllTruncationTests(ConvertDToIFunc func) { |
| 99 RunAllTruncationTests(DefaultCallWrapper, func); |
| 100 } |
| 101 |
| 102 |
| 103 void RunAllTruncationTests(ConvertDToICallWrapper callWrapper, |
| 104 ConvertDToIFunc func) { |
| 90 RunOneTruncationTest(0, 0); | 105 RunOneTruncationTest(0, 0); |
| 91 RunOneTruncationTest(0.5, 0); | 106 RunOneTruncationTest(0.5, 0); |
| 92 RunOneTruncationTest(-0.5, 0); | 107 RunOneTruncationTest(-0.5, 0); |
| 93 RunOneTruncationTest(1.5, 1); | 108 RunOneTruncationTest(1.5, 1); |
| 94 RunOneTruncationTest(-1.5, -1); | 109 RunOneTruncationTest(-1.5, -1); |
| 95 RunOneTruncationTest(5.5, 5); | 110 RunOneTruncationTest(5.5, 5); |
| 96 RunOneTruncationTest(-5.0, -5); | 111 RunOneTruncationTest(-5.0, -5); |
| 97 RunOneTruncationTest(NaN, 0); | 112 RunOneTruncationTest(NaN, 0); |
| 98 RunOneTruncationTest(Infinity, 0); | 113 RunOneTruncationTest(Infinity, 0); |
| 99 RunOneTruncationTest(-NaN, 0); | 114 RunOneTruncationTest(-NaN, 0); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 121 | 136 |
| 122 RunOneTruncationTest(9.6714111686030497e+24, -2147483648.0); | 137 RunOneTruncationTest(9.6714111686030497e+24, -2147483648.0); |
| 123 RunOneTruncationTest(-9.6714111686030497e+24, -2147483648.0); | 138 RunOneTruncationTest(-9.6714111686030497e+24, -2147483648.0); |
| 124 RunOneTruncationTest(9.6714157802890681e+24, -2147483648.0); | 139 RunOneTruncationTest(9.6714157802890681e+24, -2147483648.0); |
| 125 RunOneTruncationTest(-9.6714157802890681e+24, -2147483648.0); | 140 RunOneTruncationTest(-9.6714157802890681e+24, -2147483648.0); |
| 126 } | 141 } |
| 127 | 142 |
| 128 #undef NaN | 143 #undef NaN |
| 129 #undef Infinity | 144 #undef Infinity |
| 130 #undef RunOneTruncationTest | 145 #undef RunOneTruncationTest |
| OLD | NEW |