summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/compiler/math-ceil.js
blob: 8caa184e453a5995e42b0a284725aba480035e1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --allow-natives-syntax

// Ensure that the typing rule for Math.ceil deals correctly with
// inputs in the range (-1.0,0.0), which are mapped to -0.
(function() {
  function foo(x) {
    // Arrange x such that TurboFan infers type PlainNumber \/ NaN.
    x = +x;
    x = Math.abs(x) - 1.0;
    return Object.is(-0, Math.ceil(x));
  }

  %PrepareFunctionForOptimization(foo);
  assertFalse(foo(1.5));
  assertTrue(foo(0.5));
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo(1.5));
  assertTrue(foo(0.5));
})();

// Ensure that the typing rule for Math.ceil deals correctly with
// NaN inputs, which are mapped to NaN.
(function() {
  function foo(x) {
    // Arrange x such that TurboFan infers type PlainNumber \/ NaN.
    x = +x;
    x = Math.abs(x) - 1.0;
    return Object.is(NaN, Math.ceil(x));
  }

  %PrepareFunctionForOptimization(foo);
  assertFalse(foo(1.5));
  assertTrue(foo(NaN));
  %OptimizeFunctionOnNextCall(foo);
  assertFalse(foo(1.5));
  assertTrue(foo(NaN));
})();