| 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 3145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3156 // 0 but less than 1, chosen randomly. | 3156 // 0 but less than 1, chosen randomly. |
| 3157 static Object* Runtime_Math_random(Arguments args) { | 3157 static Object* Runtime_Math_random(Arguments args) { |
| 3158 NoHandleAllocation ha; | 3158 NoHandleAllocation ha; |
| 3159 ASSERT(args.length() == 0); | 3159 ASSERT(args.length() == 0); |
| 3160 | 3160 |
| 3161 // To get much better precision, we combine the results of two | 3161 // To get much better precision, we combine the results of two |
| 3162 // invocations of random(). The result is computed by normalizing a | 3162 // invocations of random(). The result is computed by normalizing a |
| 3163 // double in the range [0, RAND_MAX + 1) obtained by adding the | 3163 // double in the range [0, RAND_MAX + 1) obtained by adding the |
| 3164 // high-order bits in the range [0, RAND_MAX] with the low-order | 3164 // high-order bits in the range [0, RAND_MAX] with the low-order |
| 3165 // bits in the range [0, 1). | 3165 // bits in the range [0, 1). |
| 3166 double lo = static_cast<double>(random()) / (RAND_MAX + 1.0); | 3166 double lo = static_cast<double>(random()) * (1.0 / (RAND_MAX + 1.0)); |
| 3167 double hi = static_cast<double>(random()); | 3167 double hi = static_cast<double>(random()); |
| 3168 double result = (hi + lo) / (RAND_MAX + 1.0); | 3168 double result = (hi + lo) * (1.0 / (RAND_MAX + 1.0)); |
| 3169 ASSERT(result >= 0 && result < 1); | 3169 ASSERT(result >= 0 && result < 1); |
| 3170 return Heap::AllocateHeapNumber(result); | 3170 return Heap::AllocateHeapNumber(result); |
| 3171 } | 3171 } |
| 3172 | 3172 |
| 3173 | 3173 |
| 3174 static Object* Runtime_Math_round(Arguments args) { | 3174 static Object* Runtime_Math_round(Arguments args) { |
| 3175 NoHandleAllocation ha; | 3175 NoHandleAllocation ha; |
| 3176 ASSERT(args.length() == 1); | 3176 ASSERT(args.length() == 1); |
| 3177 | 3177 |
| 3178 CONVERT_DOUBLE_CHECKED(x, args[0]); | 3178 CONVERT_DOUBLE_CHECKED(x, args[0]); |
| (...skipping 2693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5872 } else { | 5872 } else { |
| 5873 // Handle last resort GC and make sure to allow future allocations | 5873 // Handle last resort GC and make sure to allow future allocations |
| 5874 // to grow the heap without causing GCs (if possible). | 5874 // to grow the heap without causing GCs (if possible). |
| 5875 Counters::gc_last_resort_from_js.Increment(); | 5875 Counters::gc_last_resort_from_js.Increment(); |
| 5876 Heap::CollectAllGarbage(); | 5876 Heap::CollectAllGarbage(); |
| 5877 } | 5877 } |
| 5878 } | 5878 } |
| 5879 | 5879 |
| 5880 | 5880 |
| 5881 } } // namespace v8::internal | 5881 } } // namespace v8::internal |
| OLD | NEW |