Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: test/mjsunit/compiler/optimize_max.js

Issue 1199053011: Add mjsunit tests for optimization of float min/max. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | test/mjsunit/compiler/optimize_min.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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: --allow-natives-syntax
6
7 var DOUBLE_ZERO = %AllocateHeapNumber();
8 var SMI_ZERO = 0;
9 var MINUS_ZERO = -0.0;
10
11 function max1(a, b) {
12 a = +a;
13 b = +b;
14 return +(a < b ? b : a);
15 }
16
17 function max2(a, b) {
18 a = +a;
19 b = +b;
20 return a < b ? b : a;
21 }
22
23 for (f of [max1, max2]) {
24 for (var i = 0; i < 5; i++) {
25 assertEquals(4, f(3, 4));
26 assertEquals(4, f(4, 3));
27 assertEquals(4.3, f(3.3, 4.3));
28 assertEquals(4.4, f(4.4, 3.4));
29
30 assertEquals(Infinity, 1 / f(SMI_ZERO, MINUS_ZERO));
31 assertEquals(Infinity, 1 / f(DOUBLE_ZERO, MINUS_ZERO));
32 assertEquals(-Infinity, 1 / f(MINUS_ZERO, SMI_ZERO));
33 assertEquals(-Infinity, 1 / f(MINUS_ZERO, DOUBLE_ZERO));
34
35 assertEquals(NaN, f(NaN, NaN));
36 assertEquals(3, f(3, NaN));
37 assertEquals(NaN, f(NaN, 3));
38 }
39 }
40
41 function max3(a, b) {
42 a = +a;
43 b = +b;
44 return +(a > b ? a : b);
45 }
46
47 function max4(a, b) {
48 a = +a;
49 b = +b;
50 return a > b ? a : b;
51 }
52
53 for (f of [max3, max4]) {
54 for (var i = 0; i < 5; i++) {
55 assertEquals(4, f(3, 4));
56 assertEquals(4, f(4, 3));
57 assertEquals(4.3, f(3.3, 4.3));
58 assertEquals(4.4, f(4.4, 3.4));
59
60 assertEquals(-Infinity, 1 / f(SMI_ZERO, MINUS_ZERO));
61 assertEquals(-Infinity, 1 / f(DOUBLE_ZERO, MINUS_ZERO));
62 assertEquals(Infinity, 1 / f(MINUS_ZERO, SMI_ZERO));
63 assertEquals(Infinity, 1 / f(MINUS_ZERO, DOUBLE_ZERO));
64
65 assertEquals(NaN, f(NaN, NaN));
66 assertEquals(NaN, f(3, NaN));
67 assertEquals(3, f(NaN, 3));
68 }
69 }
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/compiler/optimize_min.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698