/*
͵չʵ
ܶйص㽨ݷʽMathз
*/
Number.implement({

 //
 limit: function(min, max){
  //עȡֵȡСֵ˳ֵ
  return Math.min(max, Math.max(min, this));
 },

 /*
 ɶ룬Ϊ˽JSĸ
 ȸҪľȷŴʹСƣʹMath.round֮ʹС
 ԲֱʹMath.round
 */
 round: function(precision){
  precision = Math.pow(10, precision || 0);
  return Math.round(this * precision) / precision;
 },

 //Ruby wayķʾ
 times: function(fn, bind){
  for (var i = 0; i < this; i++) fn.call(bind, i, this);
 },

 //parseFloatĿݷʽ
 toFloat: function(){
  return parseFloat(this);
 },

 //parseIntĿݷʽ
 toInt: function(base){
  return parseInt(this, base || 10);
 }

});

//ΪtimesΪeachı
Number.alias('times', 'each');

//ΪͽMath󷽷Ŀݷʽ
(function(math){
 var methods = {};
 math.each(function(name){
  if (!Number[name]) methods[name] = function(){
   return Math[name].apply(null, [this].concat($A(arguments)));
  };
 });
 Number.implement(methods);
})(['abs', 'acos', 'asin', 'atan', 'atan2', 'ceil', 'cos', 'exp', 'floor', 'log', 'max', 'min', 'pow', 'sin', 'sqrt', 'tan']);


