Nodejs Number Calculate setInCirclesetInCircle(lower, upper)

Here you can find the source of setInCirclesetInCircle(lower, upper)

Method Source Code

Number.prototype.setInCircle = function setInCircle(lower, upper){
   /**// w w w . j a va  2  s.c o m
    * Function Number.prototype.setInCircle
    * @name: Number.prototype.setInCircle
    * @version: 0.9
    * @author: Korbinian Kapsner
    * @last modify: 04.08.2009
    * @description: "zw?t" eine Zahl in einen Ring, Bsp: Winkel -60? == 300?
    * @parameter:
    *   lower: untere Grenze
    *   upper: obere Grenze
    *
    */

   var zahl = this;
   if (lower === upper){
      return lower;
   }
   if (lower > upper){
      var l = lower;
      lower = upper;
      upper = l;
   }
   var diff = Math.abs(upper - lower);
   while (zahl < lower){
      zahl += diff;
   }
   while (zahl > upper){
      zahl -= diff;
   }
   return zahl;
};

})();

Related

  1. rotate()
    Number.prototype.rotate = Number.prototype.rotate || function () {
      return Math.floor((this / 10) + ((this % 10) * Math.pow(10, exports.digitLength(this) - 1)));
    };
    
  2. safeDivideBy(x)
    Number.prototype.safeDivideBy = function(x) {
        var result = this.valueOf() / x;
        if(result === Infinity) {
            return 0;
        else {
            return result;
    
  3. send(method)
    Number.prototype.send = function(method) {
      return this[method].call();
    };
    
  4. separatorsseparators()
    Number.prototype.separators = function separators(){
      var string = this.toString();
      var x      = string.split('.');
      var x1     = x[0];
      var x2     = x.length > 1 ? '.' + x[1] : '';
      var regex  = /(\d+)(\d{3})/;
      while (regex.test(x1)) {
          x1 = x1.replace(regex, '$1' + ',' + '$2');
      return x1 + x2;
    };
    
  5. set(key, value)
    'use strict';
    const assert = require('assert');
    const nan = Symbol('NaN');
    const define = Object.defineProperty;
    Number.prototype[nan] = Object.create(null);
    Number.prototype.set = function (key, value) {
      if (null == this || !isNaN(this)) { return this; }
      const space = this[nan];
      const accessor = {
    ...
    
  6. setInRangesetInRange(lower, upper)
    Number.prototype.setInRange = function setInRange(lower, upper){
      if (typeof lower === "undefined" || lower === null){
        lower = this;
      if (typeof upper === "undefined" || upper === null){
        upper = this;
      lower = parseFloat(lower) || 0;
      upper = parseFloat(upper) || 0;
    ...
    
  7. sigFig(precision)
    'use strict'
    Number.prototype.sigFig = function(precision){
        if( !precision ) precision = 2;
        var d = Math.pow(10, precision);
        return ( parseInt( this.valueOf() * d) / d ).toFixed(precision);
    };
    
  8. simEq(number, digits)
    DEFAULT_DIGIT = 5;
    Number.prototype.simEq = function(number, digits) {
      digits = digits == undefined ? DEFAULT_DIGIT : digits;
      var n1 = this.toFixed(digits);
      var n2 = number.toFixed(digits);
      if (n1 == -0)
        n1 = 0;
      if (n2 == -0)
        n2 = 0;
    ...
    
  9. sin()
    Number.prototype.sin = function() {
        return Math.sin(this);