math - How to write Mathematical formula with "^" (caret) in JavaScript? - Stack Overflow

I need some help how to make this math formula in javascript. i have tried searching but couldn't

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 raise a to the b power in JavaScript. You'll want to use Math.pow. – zzzzBov Commented Jan 28, 2013 at 20:45
  • In English, people generally say A^B as A 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
Add a ment  | 

4 Answers 4

Reset to default 3
Math.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)));

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745634304a4637295.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信