- Testing the move of MooTools2 Core.js in MooTools1 Core.js.
[mootools/dkf.git] / Source / Native / Number.js
blob4e853890e0b768872dd66cd7d41797b2063787ed
1 /*
2 ---
4 script: Number.js
6 description: Contains Number Prototypes like limit, round, times, and ceil.
8 license: MIT-style license.
10 requires:
11 - /Native
12 - /Utils
14 provides: [Number]
16 ...
19 Number.implement({
21         limit: function(min, max){
22                 return Math.min(max, Math.max(min, this));
23         },
25         round: function(precision){
26                 precision = Math.pow(10, precision || 0);
27                 return Math.round(this * precision) / precision;
28         },
30         times: function(fn, bind){
31                 for (var i = 0; i < this; i++) fn.call(bind, i, this);
32         },
34         toFloat: function(){
35                 return parseFloat(this);
36         },
38         toInt: function(base){
39                 return parseInt(this, base || 10);
40         }
42 });
44 Number.alias('times', 'each');
46 (function(math){
47         var methods = {};
48         math.each(function(name){
49                 if (!Number[name]) methods[name] = function(){
50                         return Math[name].apply(null, [this].concat($A(arguments)));
51                 };
52         });
53         Number.implement(methods);
54 })(['abs', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'exp', 'floor', 'log', 'max', 'min', 'pow', 'sin', 'sqrt', 'tan']);