| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 53 // least significant non-fractional bits in the low 32 bits of the | 53 // least significant non-fractional bits in the low 32 bits of the |
| 54 // double, and reading them from there. | 54 // double, and reading them from there. |
| 55 const double k2Pow52 = 4503599627370496.0; | 55 const double k2Pow52 = 4503599627370496.0; |
| 56 bool negative = x < 0; | 56 bool negative = x < 0; |
| 57 if (negative) { | 57 if (negative) { |
| 58 x = -x; | 58 x = -x; |
| 59 } | 59 } |
| 60 if (x < k2Pow52) { | 60 if (x < k2Pow52) { |
| 61 x += k2Pow52; | 61 x += k2Pow52; |
| 62 uint32_t result; | 62 uint32_t result; |
| 63 #ifdef BIG_ENDIAN_FLOATING_POINT | |
| 64 Address mantissa_ptr = reinterpret_cast<Address>(&x) + kIntSize; | |
| 65 #else | |
| 66 Address mantissa_ptr = reinterpret_cast<Address>(&x); | 63 Address mantissa_ptr = reinterpret_cast<Address>(&x); |
| 67 #endif | |
| 68 // Copy least significant 32 bits of mantissa. | 64 // Copy least significant 32 bits of mantissa. |
| 69 memcpy(&result, mantissa_ptr, sizeof(result)); | 65 memcpy(&result, mantissa_ptr, sizeof(result)); |
| 70 return negative ? ~result + 1 : result; | 66 return negative ? ~result + 1 : result; |
| 71 } | 67 } |
| 72 // Large number (outside uint32 range), Infinity or NaN. | 68 // Large number (outside uint32 range), Infinity or NaN. |
| 73 return 0x80000000u; // Return integer indefinite. | 69 return 0x80000000u; // Return integer indefinite. |
| 74 } | 70 } |
| 75 | 71 |
| 76 | 72 |
| 77 static inline double DoubleToInteger(double x) { | 73 static inline double DoubleToInteger(double x) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 101 if (!isfinite(x) || x == 0) return 0; | 97 if (!isfinite(x) || x == 0) return 0; |
| 102 if (x < 0 || x >= two32) x = modulo(x, two32); | 98 if (x < 0 || x >= two32) x = modulo(x, two32); |
| 103 x = (x >= 0) ? floor(x) : ceil(x) + two32; | 99 x = (x >= 0) ? floor(x) : ceil(x) + two32; |
| 104 return (int32_t) ((x >= two31) ? x - two32 : x); | 100 return (int32_t) ((x >= two31) ? x - two32 : x); |
| 105 } | 101 } |
| 106 | 102 |
| 107 | 103 |
| 108 } } // namespace v8::internal | 104 } } // namespace v8::internal |
| 109 | 105 |
| 110 #endif // V8_CONVERSIONS_INL_H_ | 106 #endif // V8_CONVERSIONS_INL_H_ |
| OLD | NEW |