SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Aug 2002
    Posts
    168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Calculation Using Exponentiation

    I am trying to figure out how to duplicate a, financial, calculation that uses the caret, Exponentiation.

    Here's the formula...

    A = 0.0755
    B = 34
    C = 50000
    D = 22448

    result = ((C-D)*A/12)/(1-(1+A/12)^(-B))+D*A/12

    It calculates loan repayments based on interest rate (A), number of payments (B), total loan amount (C) and a residual amount (D).

    This calculation will work when the caret (Exponentiation) is used, however Javascript doesn't use that.

    I have found examples of how to do Exponentiation, like this:
    Code:
    function powmod(base,exp,modulus)
    {
     var accum=1, i=0, basepow2=base;
     while ((exp>>i)>0)
     {
      if(((exp>>i) & 1) == 1){accum = (accum*basepow2) % modulus;};
      basepow2 = (basepow2*basepow2) % modulus;
      i++;
     };
     return accum;
    }
    This function comes from here http://www.math.umbc.edu/~campbell/N...pt.html#PowMod (some handy stuff there) but I can't replicate the calculation I have posted using a function like that.

    Anyone know how to do this?

    Thanks!

  2. #2
    SitePoint Guru
    Join Date
    Apr 2006
    Posts
    802
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Math.pow(n,p)
    n is the number to be raised to a power
    p is the power(exponent)

    Math.pow(10,3) returns 1000

  3. #3
    SitePoint Member El Fuego's Avatar
    Join Date
    Dec 2006
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So here we get

    n = ((C-D)*A/12)/(1-(1+A/12)

    p = (-B))+D*A/12

    --------------
    El Fuego
    --------------


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •