Strange number with fn pow
So I have this loan formula K = (S * (P/100/12)) / (1 - (1 + (P/100/12))^(-Y*12)) and I converted to this
1 2 3 4 5
|
double Prots = (P / 100 / 12);
double Numb = (Y * 12);
double K = (S * Prots) / std::pow(1 - (1 + Prots), (-Numb));
|
But the answer comes out really wierd.
For example if we take S=1200, Y=P=2, the K should be around 51.05, but I get 4.22085e-67.
What is wrong?
You haven't shown the declaration of P, Y or S.
If P is an int
, you're going to be doing integer division at line 2.
What is the type of P, Y, S?
Edit:
(1 - (1 + (P/100/12))^(-Y*12)) ||: (P/100/12) = A
(1 - (1 + A)^(-Y*12)) ||: (-Y*12) = B
(1 - (1 + A)^B) ||: (1 + A) = C
(1 - C^B)
(1 - std::pow( C, B )) |
but you have:
Last edited on
P, Y, S are all double
1 2 3 4 5 6 7
|
#include <iostream>
#include <cmath>
int main()
{
double S, P, Y;
}
|
I also tried with float, but with that, answer changed to 0.
Last edited on
Topic archived. No new replies allowed.