1958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Copyright 2014 the V8 project authors. All rights reserved. 2958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// Use of this source code is governed by a BSD-style license that can be 3958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier// found in the LICENSE file. 4958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier 5958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernierfunction Module(stdlib) { 6958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier "use asm"; 7958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier 8958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier var floor = stdlib.Math.floor; 9958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier 10958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier // f: double -> float 11958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier function f(a) { 12958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier a = +a; 13958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier return floor(a); 14958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier } 15958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier 16958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier return { f: f }; 17958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier} 18958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier 19958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Berniervar f = Module({ Math: Math }).f; 20958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier 21958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierassertTrue(isNaN(f(NaN))); 22958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierassertTrue(isNaN(f(undefined))); 23958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierassertTrue(isNaN(f(function() {}))); 24958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier 25958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierassertEquals(0, f(0)); 26958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierassertEquals(+0, f(+0)); 27958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierassertEquals(-0, f(-0)); 28958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierassertEquals(0, f(0.49999)); 29958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierassertEquals(+0, f(0.6)); 30958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierassertEquals(+0, f(0.5)); 31958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierassertEquals(-1, f(-0.1)); 32958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierassertEquals(-1, f(-0.5)); 33958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierassertEquals(-1, f(-0.6)); 34958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierassertEquals(-2, f(-1.6)); 35958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierassertEquals(-1, f(-0.50001)); 36958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily Bernier 37958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierassertEquals("Infinity", String(f(Infinity))); 38958fae7ec3f466955f8e5b50fa5b8d38b9e91675Emily BernierassertEquals("-Infinity", String(f(-Infinity))); 39