I need some help how to make this math formula in javascript. i have tried searching but couldn't really find cause i dont even know what ^ is called in English.
Thanks in advance
Math.floor(20*(1.1^(x-10)));
I need some help how to make this math formula in javascript. i have tried searching but couldn't really find cause i dont even know what ^ is called in English.
Thanks in advance
Math.floor(20*(1.1^(x-10)));
Share
Improve this question
edited Aug 1, 2015 at 6:42
user2864740
62.1k15 gold badges158 silver badges229 bronze badges
asked Jan 28, 2013 at 20:44
LilithLilith
613 bronze badges
3
- 3 Here's the Math object documentation. – Pointy Commented Jan 28, 2013 at 20:45
-
5
a^b
does not raisea
to theb
power in JavaScript. You'll want to useMath.pow
. – zzzzBov Commented Jan 28, 2013 at 20:45 -
In English, people generally say
A^B
asA to the Bth power
. In your case,1.1 to the (x minus 10)th power
. See also Exponentiation: en.wikipedia/wiki/Exponentiation – DACrosby Commented Jan 28, 2013 at 20:51
4 Answers
Reset to default 3Math.floor(20*(Math.pow(1.1, (x-10))));
^
is the bitwise XOR
operator - not what you want. Use the Math.pow
function for exponentiation:
Math.floor( 20 * (Math.pow(1.1, x - 10)) );
Set this up in a function so you can use x
for whatever value it may be:
var eq = function(x) {
return Math.floor( 20 * (Math.pow(1.1, x - 10)) );
};
Math.pow()
is what you are looking for.
^
, as used in other languages, is called the power or exponential operator, but in Javascript, it serves a different purpose, it is the bitwise XOR operator.
Math.floor(20*(Math.pow(1.1, x - 10)));