| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 function Module(stdlib) { | 5 function Module(stdlib) { |
| 6 "use asm"; | 6 "use asm"; |
| 7 | 7 |
| 8 var abs = stdlib.Math.abs; | 8 var abs = stdlib.Math.abs; |
| 9 | 9 |
| 10 // f: double -> double | 10 // f: double -> double |
| 11 function f(a) { | 11 function f(a) { |
| 12 a = +a; | 12 a = +a; |
| 13 return +abs(a); | 13 return +abs(a); |
| 14 } | 14 } |
| 15 | 15 |
| 16 // g: unsigned -> double | 16 // g: unsigned -> double |
| 17 function g(a) { | 17 function g(a) { |
| 18 a = a>>>0; | 18 a = a | 0; |
| 19 return +abs(a); | 19 return +abs(+(a >>> 0)); |
| 20 } | 20 } |
| 21 | 21 |
| 22 // h: signed -> double | 22 // h: signed -> double |
| 23 function h(a) { | 23 function h(a) { |
| 24 a = a|0; | 24 a = a|0; |
| 25 return +abs(a); | 25 return +abs(+(a | 0)); |
| 26 } | 26 } |
| 27 | 27 |
| 28 return { f: f, g: g, h: h }; | 28 return { f: f, g: g, h: h }; |
| 29 } | 29 } |
| 30 | 30 |
| 31 var m = Module({ Math: Math }); | 31 var m = Module({ Math: Math }); |
| 32 var f = m.f; | 32 var f = m.f; |
| 33 var g = m.g; | 33 var g = m.g; |
| 34 var h = m.h; | 34 var h = m.h; |
| 35 | 35 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 assertEquals(1, h(1.1)); | 75 assertEquals(1, h(1.1)); |
| 76 assertEquals(1, h(1.5)); | 76 assertEquals(1, h(1.5)); |
| 77 assertEquals(1, h(-1)); | 77 assertEquals(1, h(-1)); |
| 78 assertEquals(1, h(-1.1)); | 78 assertEquals(1, h(-1.1)); |
| 79 assertEquals(1, h(-1.5)); | 79 assertEquals(1, h(-1.5)); |
| 80 | 80 |
| 81 assertEquals(Number.MIN_VALUE, f(Number.MIN_VALUE)); | 81 assertEquals(Number.MIN_VALUE, f(Number.MIN_VALUE)); |
| 82 assertEquals(Number.MIN_VALUE, f(-Number.MIN_VALUE)); | 82 assertEquals(Number.MIN_VALUE, f(-Number.MIN_VALUE)); |
| 83 assertEquals(Number.MAX_VALUE, f(Number.MAX_VALUE)); | 83 assertEquals(Number.MAX_VALUE, f(Number.MAX_VALUE)); |
| 84 assertEquals(Number.MAX_VALUE, f(-Number.MAX_VALUE)); | 84 assertEquals(Number.MAX_VALUE, f(-Number.MAX_VALUE)); |
| OLD | NEW |