blob: 05794f4bb21fcfd20f4f6877e12dfcb44bedc1a1 [file] [log] [blame]
Ben Murdochda12d292016-06-02 14:46:10 +01001// Copyright 2016 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Flags: --max-semi-space-size=1 --allow-natives-syntax
6
7var test_id = 0;
8
9function testCeil(expect, input) {
10 var test = new Function('n',
11 '"' + (test_id++) + '";return Math.ceil(n)');
12 assertEquals(expect, test(input));
13 assertEquals(expect, test(input));
14 assertEquals(expect, test(input));
15 %OptimizeFunctionOnNextCall(test);
16 assertEquals(expect, test(input));
17
18 var test_double_input = new Function(
19 'n',
20 '"' + (test_id++) + '";return Math.ceil(+n)');
21 assertEquals(expect, test_double_input(input));
22 assertEquals(expect, test_double_input(input));
23 assertEquals(expect, test_double_input(input));
24 %OptimizeFunctionOnNextCall(test_double_input);
25 assertEquals(expect, test_double_input(input));
26
27 var test_double_output = new Function(
28 'n',
29 '"' + (test_id++) + '";return Math.ceil(n) + -0.0');
30 assertEquals(expect, test_double_output(input));
31 assertEquals(expect, test_double_output(input));
32 assertEquals(expect, test_double_output(input));
33 %OptimizeFunctionOnNextCall(test_double_output);
34 assertEquals(expect, test_double_output(input));
35
36 var test_via_floor = new Function(
37 'n',
38 '"' + (test_id++) + '";return -Math.floor(-n)');
39 assertEquals(expect, test_via_floor(input));
40 assertEquals(expect, test_via_floor(input));
41 assertEquals(expect, test_via_floor(input));
42 %OptimizeFunctionOnNextCall(test_via_floor);
43 assertEquals(expect, test_via_floor(input));
44
45 if (input <= 0) {
46 var test_via_trunc = new Function(
47 'n',
48 '"' + (test_id++) + '";return Math.trunc(n)');
49 assertEquals(expect, test_via_trunc(input));
50 assertEquals(expect, test_via_trunc(input));
51 assertEquals(expect, test_via_trunc(input));
52 %OptimizeFunctionOnNextCall(test_via_trunc);
53 assertEquals(expect, test_via_trunc(input));
54 }
55}
56
57function test() {
58 testCeil(0, 0);
59 testCeil(+0, +0);
60 testCeil(-0, -0);
61 testCeil(1, 0.49999);
62 testCeil(1, 0.6);
63 testCeil(1, 0.5);
64 testCeil(-0, -0.1);
65 testCeil(-0, -0.5);
66 testCeil(-0, -0.6);
67 testCeil(-1, -1.6);
68 testCeil(-0, -0.50001);
69 testCeil(Infinity, Infinity);
70 testCeil(-Infinity, -Infinity);
71}
72
73
74// Test in a loop to cover the custom IC and GC-related issues.
75for (var i = 0; i < 10; i++) {
76 test();
77 new Array(i * 10000);
78}