diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-07-15 12:23:08 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-07-15 12:23:08 -0700 |
commit | c20429516e29aa8e75ff1c5aab1e6a796cc79696 (patch) | |
tree | 4fc3f52f9c2f9623c6123f60c01152ea8851549c | |
parent | 85d286d05631104de01826dcab2465b29ca3c358 (diff) |
implement llrint properly; fixes #1380
-rw-r--r-- | src/library.js | 7 | ||||
-rwxr-xr-x | tests/runner.py | 12 |
2 files changed, 17 insertions, 2 deletions
diff --git a/src/library.js b/src/library.js index 24e35178..fb2d990b 100644 --- a/src/library.js +++ b/src/library.js @@ -5735,8 +5735,11 @@ LibraryManager.library = { rintf: 'rint', lrint: 'rint', lrintf: 'rint', - llrint: 'rint', - llrintf: 'rint', + llrint: function(x) { + x = (x < 0) ? -Math.round(-x) : Math.round(x); + {{{ makeStructuralReturn(splitI64('x')) }}}; + }, + llrintf: 'llrint', nearbyint: 'rint', nearbyintf: 'rint', trunc: function(x) { diff --git a/tests/runner.py b/tests/runner.py index 1f6b39f4..0efcce86 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -1981,6 +1981,18 @@ Succeeded! self.do_run(src, "1.0 2.0 -1.0 -2.0 2.0 3.0 -2.0 -3.0 " "1 2 -1 -2 2 2 -2 -2") + def test_llrint(self): + if Settings.USE_TYPED_ARRAYS != 2: return self.skip('requires ta2') + src = r''' + #include <stdio.h> + #include <math.h> + int main() { + printf("%lld\n%lld\n%lld\n%lld\n", llrint(0.1), llrint(0.6), llrint(1.25), llrint(1099511627776.667)); + return 0; + } + ''' + self.do_run(src, '0\n1\n1\n1099511627777\n') + def test_getgep(self): # Generated code includes getelementptr (getelementptr, 0, 1), i.e., GEP as the first param to GEP src = ''' |