[Pkg-javascript-commits] [less.js] 25/50: add comment, make + clearer by changing to Number constructor

Jonas Smedegaard dr at jones.dk
Mon Oct 26 23:22:37 UTC 2015


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag v1.7.1
in repository less.js.

commit 6214b0f93c90b5f519bb9fc04a2e25f1cc8eec5f
Author: Luke Page <luke.a.page at gmail.com>
Date:   Tue May 6 06:27:55 2014 +0100

    add comment, make + clearer by changing to Number constructor
---
 lib/less/functions.js | 43 ++++++++++++++++++++++---------------------
 1 file changed, 22 insertions(+), 21 deletions(-)

diff --git a/lib/less/functions.js b/lib/less/functions.js
index f44e295..42d1bb2 100644
--- a/lib/less/functions.js
+++ b/lib/less/functions.js
@@ -302,7 +302,7 @@ tree.functions = {
                 continue;
             }
             currentUnified = current.unit.toString() === "" && unitClone !== undefined ? new(tree.Dimension)(current.value, unitClone).unify() : current.unify();
-            unit = currentUnified.unit.toString() === "" && unitStatic !== undefined ? unitStatic : currentUnified.unit.toString();			
+            unit = currentUnified.unit.toString() === "" && unitStatic !== undefined ? unitStatic : currentUnified.unit.toString();
             unitStatic = unit !== "" && unitStatic === undefined || unit !== "" && order[0].unify().unit.toString() === "" ? unit : unitStatic;
             unitClone = unit !== "" && unitClone === undefined ? current.unit.toString() : unitClone;
             j = values[""] !== undefined && unit !== "" && unit === unitStatic ? values[""] : values[unit];
@@ -392,12 +392,12 @@ tree.functions = {
     },
     shade: function(color, amount) {
         return this.mix(this.rgb(0, 0, 0), color, amount);
-    },   
+    },
     extract: function(values, index) {
-        index = index.value - 1; // (1-based index)       
+        index = index.value - 1; // (1-based index)
         // handle non-array values as an array of length 1
         // return 'undefined' if index is invalid
-        return Array.isArray(values.value) 
+        return Array.isArray(values.value)
             ? values.value[index] : Array(values)[index];
     },
     length: function(values) {
@@ -583,15 +583,15 @@ tree._mime = {
 
 var mathFunctions = {
  // name,  unit
-    ceil:  null, 
-    floor: null, 
-    sqrt:  null, 
+    ceil:  null,
+    floor: null,
+    sqrt:  null,
     abs:   null,
-    tan:   "", 
-    sin:   "", 
+    tan:   "",
+    sin:   "",
     cos:   "",
-    atan:  "rad", 
-    asin:  "rad", 
+    atan:  "rad",
+    asin:  "rad",
     acos:  "rad"
 };
 
@@ -616,19 +616,19 @@ function colorBlend(mode, color1, color2) {
     var ab = color1.alpha, cb, // backdrop
         as = color2.alpha, cs, // source
         ar, cr, r = [];        // result
-        
+
     ar = as + ab * (1 - as);
     for (var i = 0; i < 3; i++) {
         cb = color1.rgb[i] / 255;
         cs = color2.rgb[i] / 255;
         cr = mode(cb, cs);
         if (ar) {
-            cr = (as * cs + ab * (cb 
+            cr = (as * cs + ab * (cb
                 - as * (cb + cs - cr))) / ar;
         }
         r[i] = cr * 255;
     }
-    
+
     return new(tree.Color)(r, ar);
 }
 
@@ -638,7 +638,7 @@ var colorBlendMode = {
     },
     screen: function(cb, cs) {
         return cb + cs - cb * cs;
-    },   
+    },
     overlay: function(cb, cs) {
         cb *= 2;
         return (cb <= 1)
@@ -651,7 +651,7 @@ var colorBlendMode = {
             e = 1;
             d = (cb > 0.25) ? Math.sqrt(cb)
                 : ((16 * cb - 12) * cb + 4) * cb;
-        }            
+        }
         return cb - (1 - 2 * cs) * e * (d - cb);
     },
     hardlight: function(cb, cs) {
@@ -698,25 +698,25 @@ tree.defaultFunc = {
 
 function initFunctions() {
     var f, tf = tree.functions;
-    
+
     // math
     for (f in mathFunctions) {
         if (mathFunctions.hasOwnProperty(f)) {
             tf[f] = _math.bind(null, Math[f], mathFunctions[f]);
         }
     }
-    
+
     // color blending
     for (f in colorBlendMode) {
         if (colorBlendMode.hasOwnProperty(f)) {
             tf[f] = colorBlend.bind(null, colorBlendMode[f]);
         }
     }
-    
+
     // default
     f = tree.defaultFunc;
     tf["default"] = f.eval.bind(f);
-    
+
 } initFunctions();
 
 function hsla(color) {
@@ -750,7 +750,8 @@ function clamp(val) {
 
 tree.fround = function(env, value) {
     var p = env && env.numPrecision;
-    return (p == null) ? value : +(value + 2e-16).toFixed(p);
+    //add "epsilon" to ensure numbers like 1.000000005 (represented as 1.000000004999....) are properly rounded...
+    return (p == null) ? value : Number((value + 2e-16).toFixed(p));
 };
 
 tree.functionCall = function(env, currentFileInfo) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git



More information about the Pkg-javascript-commits mailing list