From 5975411b8bed04b6bddf638b28af80a5932e79e5 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Thu, 8 Jun 2017 16:19:27 +1000 Subject: src/lvm.js: Optimise LEnum and LTnum for our number representation --- src/lvm.js | 50 ++++++++++---------------------------------------- 1 file 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; -- cgit v1.2.3-70-g09d2