最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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)));
发布评论

评论列表(0)

  1. 暂无评论