473,386 Members | 1,609 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Exponentiation in a Formula

Hi

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 this is not available in Javascript. So, to get this formula to
work in Javascript some other method needs to be used.

I have found examples of how to do Exponentiation, like this:

/************************************************** *********/

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!

Dec 21 '06 #1
8 5646

gr**********@hotmail.com wrote:
Hi

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 this is not available in Javascript. So, to get this formula to
work in Javascript some other method needs to be used.

I have found examples of how to do Exponentiation, like this:

/************************************************** *********/

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!
The caret operator (^) is the bitwise XOR operator in JavaScript. Use
Math.pow for exponents:

Math.pow(2,3)
=8

Dec 22 '06 #2
<gr**********@hotmail.comwrote in message
news:11*********************@79g2000cws.googlegrou ps.com...
Hi

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
result = ((C-D)*A/12)/(1-Math.pow((1+A/12),(-B)))+D*A/12;

-Lost
Dec 22 '06 #3
Hi David

Thanks, I got it now.

The formula I posted previously could translate in JS as...

var A1 = 0.0755;
var B1 = 34;
var C1 = 50000;
var D1 = 22448;

alert(((C1 - D1) * A1 / 12) / (1 - Math.pow((1 + A1 / 12), -B1)) + (D1
* A1 / 12));

Thanks again!
David Golightly wrote:
The caret operator (^) is the bitwise XOR operator in JavaScript. Use
Math.pow for exponents:

Math.pow(2,3)
=8
Dec 22 '06 #4

<gr**********@hotmail.comwrote in message
news:11*********************@79g2000cws.googlegrou ps.com...
Hi

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

There maybe something here that'll help.

http://www.comptechdoc.org/independe.../javamath.html

HTH
Dec 22 '06 #5
<gr**********@hotmail.comwrote in message
news:11*********************@42g2000cwt.googlegrou ps.com...
Hi David

Thanks, I got it now.

The formula I posted previously could translate in JS as...

var A1 = 0.0755;
var B1 = 34;
var C1 = 50000;
var D1 = 22448;

alert(((C1 - D1) * A1 / 12) / (1 - Math.pow((1 + A1 / 12), -B1)) + (D1
* A1 / 12));
result = ((C-D)*A/12)/(1-Math.pow((1+A/12),(-B)))+D*A/12;

That is the exact same thing I wrote (a few minutes before you posted again).

-Lost
Dec 22 '06 #6
Ahhhh -Lost

You nailed it. Unfortunately I sorted it out while you were posting,
wish you posted about 3 mins earlier!

Anyway, thanks a lot, appreciate your input.

-Lost wrote:
<gr**********@hotmail.comwrote in message
news:11*********************@42g2000cwt.googlegrou ps.com...
Hi David

Thanks, I got it now.

The formula I posted previously could translate in JS as...

var A1 = 0.0755;
var B1 = 34;
var C1 = 50000;
var D1 = 22448;

alert(((C1 - D1) * A1 / 12) / (1 - Math.pow((1 + A1 / 12), -B1)) + (D1
* A1 / 12));

result = ((C-D)*A/12)/(1-Math.pow((1+A/12),(-B)))+D*A/12;

That is the exact same thing I wrote (a few minutes before you posted again).

-Lost
Dec 22 '06 #7
In comp.lang.javascript message
<11*********************@79g2000cws.googlegroups.c om>, Thu, 21 Dec 2006
15:24:20, gr**********@hotmail.com wrote:
>
I am trying to figure out how to duplicate a, financial, calculation
that uses the caret, Exponentiation.
In Javascript, X = Base^Expo is actually bitwise exclusive-or, and
X = Math.pow(Base, Expo) exponentiates. Read any relevant book.

It's a good idea to read the newsgroup and its FAQ. See below.

--
(c) John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v6.05 IE 6
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Dec 22 '06 #8
<gr**********@hotmail.comwrote in message
news:11**********************@f1g2000cwa.googlegro ups.com...
Ahhhh -Lost

You nailed it. Unfortunately I sorted it out while you were posting,
wish you posted about 3 mins earlier!

Anyway, thanks a lot, appreciate your input.
Heh. No problem!

-Lost
Dec 22 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jeff Davis | last post by:
I was doing some thinking about exponentiation algorithms along with a friend, and I happened upon some interesting results. Particularly, I was able to outperform the ** operator in at least one...
15
by: Steven T. Hatton | last post by:
Did I mess something along the way, or is there no function in Standard C++ to raise an (unsigned) int to a power of (unsigned) int returning (unsigned) int? I never gave this a second thought...
2
by: David Laub | last post by:
I know there is no C# exponentiation operator. But since the double class is sealed, there seems no way to add the operator override without creating a new class which uses containment (of a...
3
by: James McGivney | last post by:
What is happening here ? long longg = 5; longg = longg + (2 ^ 8); the answer should be 5 + 256 or 261 but at the end of the above operation C# returns longg = 5 + 10 or 15
67
by: carlos | last post by:
Curious: Why wasnt a primitive exponentiation operator not added to C99? And, are there requests to do so in the next std revision? Justification for doing so: C and C++ are increasingly used...
7
by: elventear | last post by:
Hi, I am the in the need to do some numerical calculations that involve real numbers that are larger than what the native float can handle. I've tried to use Decimal, but I've found one main...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.