From 65d5914ecb5c3c8c16722712657a9f16b73962d9 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Tue, 5 Mar 2013 18:10:31 +0700 Subject: Implement llabs(). --- src/library.js | 11 +++++++++++ src/long.js | 11 +++++++++++ 2 files changed, 22 insertions(+) (limited to 'src') diff --git a/src/library.js b/src/library.js index a5166c72..848a2571 100644 --- a/src/library.js +++ b/src/library.js @@ -3670,6 +3670,17 @@ LibraryManager.library = { abs: 'Math.abs', labs: 'Math.abs', +#if USE_TYPED_ARRAYS == 2 + llabs__deps: [function() { Types.preciseI64MathUsed = 1 }], + llabs: function(lo, hi) { + i64Math.abs(lo, hi); + {{{ makeStructuralReturn([makeGetTempDouble(0, 'i32'), makeGetTempDouble(1, 'i32')]) }}}; + }, +#else + llabs: function(lo, hi) { + throw 'unsupported llabs'; + }, +#endif exit__deps: ['_exit'], exit: function(status) { diff --git a/src/long.js b/src/long.js index c3b0e605..c3651bd9 100644 --- a/src/long.js +++ b/src/long.js @@ -1551,6 +1551,17 @@ var i64Math = (function() { // Emscripten wrapper HEAP32[tempDoublePtr>>2] = ret.low_; HEAP32[tempDoublePtr+4>>2] = ret.high_; }, + abs: function(l, h) { + var x = new goog.math.Long(l, h); + var ret; + if (x.isNegative()) { + ret = x.negate(); + } else { + ret = x; + } + HEAP32[tempDoublePtr>>2] = ret.low_; + HEAP32[tempDoublePtr+4>>2] = ret.high_; + }, ensureTemps: function() { if (Wrapper.ensuredTemps) return; Wrapper.ensuredTemps = true; -- cgit v1.2.3-18-g5258