dojox/math/_base.js

  • Provides:

    • dojox.math._base
  • dojox.math.toRadians

    • type
      Function
    • parameters:
      • n: (typeof Number)
    • source: [view]
         return (n*Math.PI)/180; // Number
    • summary
      Convert the passed number to radians.
    • returns
      Number
  • dojox.math.toDegrees

    • type
      Function
    • parameters:
      • n: (typeof Number)
    • source: [view]
         return (n*180)/Math.PI; // Number
    • summary
      Convert the passed number to degrees.
    • returns
      Number
  • dojox.math.degreesToRadians

    • type
      Function
    • parameters:
      • n: (typeof Number)
    • source: [view]
         return m.toRadians(n); // Number
    • summary
      Deprecated.  Use dojox.math.toRadians.
    • returns
      Number
  • dojox.math.radiansToDegrees

    • type
      Function
    • parameters:
      • n: (typeof Number)
    • source: [view]
         return m.toDegrees(n); // Number
    • summary
      Deprecated.  Use dojox.math.toDegrees.
    • returns
      Number
  • dojox.math._gamma

    • type
      Function
    • parameters:
      • z: (typeof )
    • source: [view]
         var answer = 1; // 0!
         // gamma(n+1) = n * gamma(n)
         while (--z >= 1){
          answer *= z;
         }
         if(z == 0){ return answer; } // normal integer quick return
         if(Math.floor(z) == z){ return NaN; } // undefined at nonpositive integers since sin() below will return 0
         // assert: z < 1, remember this z is really z-1
         if(z == -0.5){ return Math.sqrt(Math.PI); } // popular gamma(1/2)
         if(z < -0.5){ // remember this z is really z-1
          return Math.PI / (Math.sin(Math.PI * (z + 1)) * this._gamma(-z)); // reflection
         }
         // assert: -0.5 < z < 1
         // Spouge approximation algorithm
         var a = 13;
         // c[0] = sqrt(2*PI) / exp(a)
         // var kfact = 1
         // for (var k=1; k < a; k++){
         // c[k] = pow(-k + a, k - 0.5) * exp(-k) / kfact
         // kfact *= -k // (-1)^(k-1) * (k-1)!
         // }
         var c = [ // precomputed from the above algorithm
            5.6658056015186327e-6,
            1.2743717663379679,
           -4.9374199093155115,
            7.8720267032485961,
           -6.6760503749436087,
            3.2525298444485167,
           -9.1852521441026269e-1,
            1.4474022977730785e-1,
           -1.1627561382389853e-2,
            4.0117980757066622e-4,
           -4.2652458386405744e-6,
            6.6651913290336086e-9,
           -1.5392547381874824e-13
          ];
         var sum = c[0];
         for (var k=1; k < a; k++){
          sum += c[k] / (z + k);
         }
         return answer * Math.pow(z + a, z + 0.5) / Math.exp(z) * sum;
    • summary
      Compute the gamma function for the passed number.
      Approximately 14 dijits of precision with non-integers.
    • returns
      normal integer quick return|undefined at nonpositive integers since sin() below will return 0|popular gamma(1/2)|reflection
  • dojox.math.factorial

    • type
      Function
    • parameters:
      • n: (typeof Number)
    • source: [view]
         return this._gamma(n+1); // Number
    • summary
      Return the factorial of n
    • returns
      Number
  • dojox.math.permutations

    • type
      Function
    • parameters:
      • n: (typeof Number)
      • k: (typeof Number)
    • source: [view]
         if(n==0 || k==0){
          return 1;  // Number
         }
         return this.factorial(n) / this.factorial(n-k);
    • summary
      TODO
    • returns
      Number
  • dojox.math.combinations

    • type
      Function
    • parameters:
      • n: (typeof Number)
      • r: (typeof Number)
    • source: [view]
         if(n==0 || r==0){
          return 1;  // Number
         }
         return this.factorial(n) / (this.factorial(n-r) * this.factorial(r)); // Number
    • summary
      TODO
    • returns
      Number
  • dojox.math.bernstein

    • type
      Function
    • parameters:
      • t: (typeof Number)
      • n: (typeof Number)
      • i: (typeof Number)
    • source: [view]
         return this.combinations(n, i) * Math.pow(t, i) * Math.pow(1-t, n-i); // Number
    • summary
      TODO
    • returns
      Number
  • dojox.math.gaussian

    • type
      Function
    • source: [view]
         var k=2;
         do{
          var i=2*Math.random()-1;
          var j=2*Math.random()-1;
          k = i*i+j*j;
         }while(k>=1);
         return i * Math.sqrt((-2*Math.log(k))/k); // Number
    • summary
      Return a random number based on the Gaussian algo.
    • returns
      Number
  • dojox.math.range

    • type
      Function
    • parameters:
      • a: (typeof Number)
      • b: (typeof Number)
      • step: (typeof Number)
    • source: [view]
         if(arguments.length<2){
          b=a,a=0;
         }
         var range=[], s=step||1, i;
         if(s>0){
          for(i=a; i     range.push(i);
          }
         }else{
          if(s<0){
           for(i=a; i>b; i+=s){
            range.push(i);
           }
          }else{
           throw new Error("dojox.math.range: step must not be zero.");
          }
         }
         return range;  // Array
    • summary
      Create a range of numbers based on the parameters.
    • returns
      Array
  • dojox.math.distance

    • type
      Function
    • parameters:
      • a: (typeof Array)
      • b: (typeof Array)
    • source: [view]
         return Math.sqrt(Math.pow(b[0]-a[0],2)+Math.pow(b[1]-a[1],2)); // Number
    • summary
      Calculate the distance between point A and point B
    • returns
      Number
  • dojox.math.midpoint

    • type
      Function
    • parameters:
      • a: (typeof Array)
      • b: (typeof Array)
    • source: [view]
         if(a.length!=b.length){
          console.error("dojox.math.midpoint: Points A and B are not the same dimensionally.", a, b);
         }
         var m=[];
         for(var i=0; i    m[i]=(a[i]+b[i])/2;
         }
         return m; // Array
    • summary
      Calculate the midpoint between points A and B.  A and B may be multidimensional.
    • returns
      Array
  • dojox.math._base

    • type
      Object
    • summary
  • dojox.math

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary