OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 function Module(stdlib) { |
| 6 "use asm"; |
| 7 |
| 8 var abs = stdlib.Math.abs; |
| 9 |
| 10 // f: double -> double |
| 11 function f(a) { |
| 12 a = +a; |
| 13 return abs(a); |
| 14 } |
| 15 |
| 16 // g: unsigned -> double |
| 17 function g(a) { |
| 18 a = a>>>0; |
| 19 return abs(a); |
| 20 } |
| 21 |
| 22 // h: signed -> double |
| 23 function h(a) { |
| 24 a = a|0; |
| 25 return abs(a); |
| 26 } |
| 27 |
| 28 return { f: f, g: g, h: h }; |
| 29 } |
| 30 |
| 31 var m = Module({ Math: Math }); |
| 32 var f = m.f; |
| 33 var g = m.g; |
| 34 var h = m.h; |
| 35 |
| 36 assertTrue(isNaN(f(NaN))); |
| 37 assertTrue(isNaN(f(undefined))); |
| 38 assertTrue(isNaN(f(function() {}))); |
| 39 |
| 40 assertEquals("Infinity", String(1/f(0))); |
| 41 assertEquals("Infinity", String(1/f(-0))); |
| 42 assertEquals("Infinity", String(f(Infinity))); |
| 43 assertEquals("Infinity", String(f(-Infinity))); |
| 44 |
| 45 assertEquals(0, f(0)); |
| 46 assertEquals(0.1, f(0.1)); |
| 47 assertEquals(0.5, f(0.5)); |
| 48 assertEquals(0.1, f(-0.1)); |
| 49 assertEquals(0.5, f(-0.5)); |
| 50 assertEquals(1, f(1)); |
| 51 assertEquals(1.1, f(1.1)); |
| 52 assertEquals(1.5, f(1.5)); |
| 53 assertEquals(1, f(-1)); |
| 54 assertEquals(1.1, f(-1.1)); |
| 55 assertEquals(1.5, f(-1.5)); |
| 56 |
| 57 assertEquals(0, g(0)); |
| 58 assertEquals(0, g(0.1)); |
| 59 assertEquals(0, g(0.5)); |
| 60 assertEquals(0, g(-0.1)); |
| 61 assertEquals(0, g(-0.5)); |
| 62 assertEquals(1, g(1)); |
| 63 assertEquals(1, g(1.1)); |
| 64 assertEquals(1, g(1.5)); |
| 65 assertEquals(4294967295, g(-1)); |
| 66 assertEquals(4294967295, g(-1.1)); |
| 67 assertEquals(4294967295, g(-1.5)); |
| 68 |
| 69 assertEquals(0, h(0)); |
| 70 assertEquals(0, h(0.1)); |
| 71 assertEquals(0, h(0.5)); |
| 72 assertEquals(0, h(-0.1)); |
| 73 assertEquals(0, h(-0.5)); |
| 74 assertEquals(1, h(1)); |
| 75 assertEquals(1, h(1.1)); |
| 76 assertEquals(1, h(1.5)); |
| 77 assertEquals(1, h(-1)); |
| 78 assertEquals(1, h(-1.1)); |
| 79 assertEquals(1, h(-1.5)); |
| 80 |
| 81 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)); |
| 84 assertEquals(Number.MAX_VALUE, f(-Number.MAX_VALUE)); |
OLD | NEW |