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

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 var DOUBLE_ZERO = 1.0 - 1.0;
Michael Starzinger 2015/06/23 16:56:25 As discussed offline: This doesn't yield a boxed d
6 var SMI_ZERO = 0;
7 var MINUS_ZERO = -0.0;
8
9 function max1(a, b) {
10 a = +a;
11 b = +b;
12 return +(a < b ? b : a);
13 }
14
15 function max2(a, b) {
16 a = +a;
17 b = +b;
18 return a < b ? b : a;
19 }
20
21 for (f of [max1, max2]) {
22 for (var i = 0; i < 5; i++) {
23 assertEquals(4, f(3, 4));
24 assertEquals(4, f(4, 3));
25 assertEquals(4.3, f(3.3, 4.3));
26 assertEquals(4.4, f(4.4, 3.4));
27
28 assertEquals(Infinity, 1 / f(SMI_ZERO, MINUS_ZERO));
29 assertEquals(Infinity, 1 / f(DOUBLE_ZERO, MINUS_ZERO));
30 assertEquals(-Infinity, 1 / f(MINUS_ZERO, SMI_ZERO));
31 assertEquals(-Infinity, 1 / f(MINUS_ZERO, DOUBLE_ZERO));
32
33 assertEquals(NaN, f(NaN, NaN));
34 assertEquals(3, f(3, NaN));
35 assertEquals(NaN, f(NaN, 3));
36 }
37 }
38
39 function max3(a, b) {
40 a = +a;
41 b = +b;
42 return +(a > b ? a : b);
43 }
44
45 function max4(a, b) {
46 a = +a;
47 b = +b;
48 return a > b ? a : b;
49 }
50
51 for (f of [max3, max4]) {
52 for (var i = 0; i < 5; i++) {
53 assertEquals(4, f(3, 4));
54 assertEquals(4, f(4, 3));
55 assertEquals(4.3, f(3.3, 4.3));
56 assertEquals(4.4, f(4.4, 3.4));
57
58 assertEquals(-Infinity, 1 / f(SMI_ZERO, MINUS_ZERO));
59 assertEquals(-Infinity, 1 / f(DOUBLE_ZERO, MINUS_ZERO));
60 assertEquals(Infinity, 1 / f(MINUS_ZERO, SMI_ZERO));
61 assertEquals(Infinity, 1 / f(MINUS_ZERO, DOUBLE_ZERO));
62
63 assertEquals(NaN, f(NaN, NaN));
64 assertEquals(NaN, f(3, NaN));
65 assertEquals(3, f(NaN, 3));
66 }
67 }
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