var Nums = {};//Namespace for function working with numbers Nums.SaveFloatPoint = function(){ this.errVal = 0; } Nums.SaveFloatPoint.prototype.add = function(value){ var err = (Math.abs(value) - Math.floor(Math.abs(value))) * value.signOf(); var val = Math.floor(Math.abs(value)) * value.signOf(); this.errVal += err; if(Math.abs(this.errVal) >= 1){ val += value.signOf(); this.errVal -= value.signOf(); } return val; } Nums.SaveFloatPoint.prototype.refresh = function(){ this.errVal = 0; } Nums.Slide = function(from, to, step_num){ var value = 0; var arr = [from + value]; var len = to - from; var step = len / step_num; var saveFloat = new this.SaveFloatPoint(); while(Math.abs(value) < Math.abs(len)){ value += saveFloat.add(step); arr.push(from + value); } if(arr.length > step_num + 1){ arr.pop(); arr[arr.length - 1] = to; } return arr; } Nums.__hex_nums = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"]; Nums.Hex2Dec = function(hex){ var num = 0; var splitted = hex.split('').invert(); splitted.each(function(n, index){ num += this.__hex_nums.indexOf(n) * (16).power(index); }.bind(this)); return Number(num); } Nums.Dec2Hex = function(dec){ } Nums.toString = function(){ var str = " object Nums: " for(var i in this){ if(i != "toString"){ str += "\n"; str += typeof this[i] + " " + i + " :: "; } } return str; } Nums.Positive = function(val){ this.val = 0; this.onzero = new DOMEvent(); this.add(val); } Nums.Positive.prototype.add = function(val){ this.val = Nums.Positive._check(this.val + val); if(this.val <= 0){ this.onzero.fire(); } return this.val; } Nums.Positive.prototype.toString = function(){ return this.val; } Nums.Positive._check = function(val){ if(!val){ return 0; } return val >= 0 ? val : 0; }