OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 // least significant non-fractional bits in the low 32 bits of the | 68 // least significant non-fractional bits in the low 32 bits of the |
69 // double, and reading them from there. | 69 // double, and reading them from there. |
70 const double k2Pow52 = 4503599627370496.0; | 70 const double k2Pow52 = 4503599627370496.0; |
71 bool negative = x < 0; | 71 bool negative = x < 0; |
72 if (negative) { | 72 if (negative) { |
73 x = -x; | 73 x = -x; |
74 } | 74 } |
75 if (x < k2Pow52) { | 75 if (x < k2Pow52) { |
76 x += k2Pow52; | 76 x += k2Pow52; |
77 uint32_t result; | 77 uint32_t result; |
| 78 #ifndef V8_TARGET_BIG_ENDIAN |
78 Address mantissa_ptr = reinterpret_cast<Address>(&x); | 79 Address mantissa_ptr = reinterpret_cast<Address>(&x); |
| 80 #else |
| 81 Address mantissa_ptr = reinterpret_cast<Address>(&x) + kIntSize; |
| 82 #endif |
79 // Copy least significant 32 bits of mantissa. | 83 // Copy least significant 32 bits of mantissa. |
80 OS::MemCopy(&result, mantissa_ptr, sizeof(result)); | 84 OS::MemCopy(&result, mantissa_ptr, sizeof(result)); |
81 return negative ? ~result + 1 : result; | 85 return negative ? ~result + 1 : result; |
82 } | 86 } |
83 // Large number (outside uint32 range), Infinity or NaN. | 87 // Large number (outside uint32 range), Infinity or NaN. |
84 return 0x80000000u; // Return integer indefinite. | 88 return 0x80000000u; // Return integer indefinite. |
85 } | 89 } |
86 | 90 |
87 | 91 |
88 inline double DoubleToInteger(double x) { | 92 inline double DoubleToInteger(double x) { |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
695 SLOW_ASSERT(buffer_pos < kBufferSize); | 699 SLOW_ASSERT(buffer_pos < kBufferSize); |
696 buffer[buffer_pos] = '\0'; | 700 buffer[buffer_pos] = '\0'; |
697 | 701 |
698 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); | 702 double converted = Strtod(Vector<const char>(buffer, buffer_pos), exponent); |
699 return (sign == NEGATIVE) ? -converted : converted; | 703 return (sign == NEGATIVE) ? -converted : converted; |
700 } | 704 } |
701 | 705 |
702 } } // namespace v8::internal | 706 } } // namespace v8::internal |
703 | 707 |
704 #endif // V8_CONVERSIONS_INL_H_ | 708 #endif // V8_CONVERSIONS_INL_H_ |
OLD | NEW |