| 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 6579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6590 // to make fuzz-natives test happy. | 6590 // to make fuzz-natives test happy. |
| 6591 return args[0]; | 6591 return args[0]; |
| 6592 } | 6592 } |
| 6593 | 6593 |
| 6594 HeapNumber* number = reinterpret_cast<HeapNumber*>(args[0]); | 6594 HeapNumber* number = reinterpret_cast<HeapNumber*>(args[0]); |
| 6595 | 6595 |
| 6596 double value = number->value(); | 6596 double value = number->value(); |
| 6597 int exponent = number->get_exponent(); | 6597 int exponent = number->get_exponent(); |
| 6598 int sign = number->get_sign(); | 6598 int sign = number->get_sign(); |
| 6599 | 6599 |
| 6600 // We compare with kSmiValueSize - 3 because (2^30 - 0.1) has exponent 29 and | 6600 if (exponent < -1) { |
| 6601 // should be rounded to 2^30, which is not smi. | 6601 // Number in range ]-0.5..0.5[. These always round to +/-zero. |
| 6602 if (!sign && exponent <= kSmiValueSize - 3) { | 6602 if (sign) return isolate->heap()->minus_zero_value(); |
| 6603 return Smi::FromInt(0); |
| 6604 } |
| 6605 |
| 6606 // We compare with kSmiValueSize - 2 because (2^30 - 0.1) has exponent 29 and |
| 6607 // should be rounded to 2^30, which is not smi (for 31-bit smis, similar |
| 6608 // agument holds for 32-bit smis). |
| 6609 if (!sign && exponent < kSmiValueSize - 2) { |
| 6603 return Smi::FromInt(static_cast<int>(value + 0.5)); | 6610 return Smi::FromInt(static_cast<int>(value + 0.5)); |
| 6604 } | 6611 } |
| 6605 | 6612 |
| 6606 // If the magnitude is big enough, there's no place for fraction part. If we | 6613 // If the magnitude is big enough, there's no place for fraction part. If we |
| 6607 // try to add 0.5 to this number, 1.0 will be added instead. | 6614 // try to add 0.5 to this number, 1.0 will be added instead. |
| 6608 if (exponent >= 52) { | 6615 if (exponent >= 52) { |
| 6609 return number; | 6616 return number; |
| 6610 } | 6617 } |
| 6611 | 6618 |
| 6612 if (sign && value >= -0.5) return isolate->heap()->minus_zero_value(); | 6619 if (sign && value >= -0.5) return isolate->heap()->minus_zero_value(); |
| (...skipping 5355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11968 } else { | 11975 } else { |
| 11969 // Handle last resort GC and make sure to allow future allocations | 11976 // Handle last resort GC and make sure to allow future allocations |
| 11970 // to grow the heap without causing GCs (if possible). | 11977 // to grow the heap without causing GCs (if possible). |
| 11971 isolate->counters()->gc_last_resort_from_js()->Increment(); | 11978 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 11972 isolate->heap()->CollectAllGarbage(false); | 11979 isolate->heap()->CollectAllGarbage(false); |
| 11973 } | 11980 } |
| 11974 } | 11981 } |
| 11975 | 11982 |
| 11976 | 11983 |
| 11977 } } // namespace v8::internal | 11984 } } // namespace v8::internal |
| OLD | NEW |