summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-06-08 16:19:27 +1000
committerdaurnimator <quae@daurnimator.com>2017-06-08 16:19:27 +1000
commit5975411b8bed04b6bddf638b28af80a5932e79e5 (patch)
treeb307cc4a178a39ad69e7729958ea964e0ec622a3 /src
parent95c45661d7ba298fad34cb348c454ac1ee5f4f56 (diff)
downloadfengari-5975411b8bed04b6bddf638b28af80a5932e79e5.tar.gz
fengari-5975411b8bed04b6bddf638b28af80a5932e79e5.tar.bz2
fengari-5975411b8bed04b6bddf638b28af80a5932e79e5.zip
src/lvm.js: Optimise LEnum and LTnum for our number representation
Diffstat (limited to 'src')
-rw-r--r--src/lvm.js50
1 files changed, 10 insertions, 40 deletions
diff --git a/src/lvm.js b/src/lvm.js
index a4985d7c..8256557 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -799,46 +799,20 @@ const tonumber = function(o) {
return false;
};
+/*
+** Return 'l < r', for numbers.
+** As fengari uses javascript numbers for both floats and integers and has
+** correct semantics, we can just compare values.
+*/
const LTnum = function(l, r) {
- if (l.ttisinteger()) {
- if (r.ttisinteger())
- return l.value < r.value ? 1 : 0;
- else
- return LTintfloat(l.value, r.value);
- } else {
- if (r.ttisfloat())
- return l.value < r.value ? 1 : 0;
- else if (isNaN(l.value))
- return 0;
- else
- return !LEintfloat(r.value, l.value);
- }
+ return l.value < r.value;
};
+/*
+** Return 'l <= r', for numbers.
+*/
const LEnum = function(l, r) {
- if (l.ttisinteger()) {
- if (r.ttisinteger())
- return l.value <= r.value ? 1 : 0;
- else
- return LEintfloat(l.value, r.value);
- } else {
- if (r.ttisfloat())
- return l.value <= r.value ? 1 : 0;
- else if (isNaN(l.value))
- return false;
- else
- return !LTintfloat(r.value, l.value);
- }
-};
-
-const LEintfloat = function(l, r) {
- // TODO: LEintfloat
- return l <= r ? 1 : 0;
-};
-
-const LTintfloat = function(l, r) {
- // TODO: LTintfloat
- return l < r ? 1 : 0;
+ return l.value <= r.value;
};
/*
@@ -1096,10 +1070,6 @@ const settable = function(L, t, key, val) {
};
-module.exports.LEintfloat = LEintfloat;
-module.exports.LEnum = LEnum;
-module.exports.LTintfloat = LTintfloat;
-module.exports.LTnum = LTnum;
module.exports.RA = RA;
module.exports.RB = RB;
module.exports.RC = RC;