admin管理员组文章数量:1317909
im using chrome with this code:
var startbet = 1;
var shot = 0;
var bet = startbet * 2^shot;
n^0=n in this case
it should be equal to 1 regardless of n
is this an error with javascript or do some people beleive to the power of 0 should be handled diffrently?
im using chrome with this code:
var startbet = 1;
var shot = 0;
var bet = startbet * 2^shot;
n^0=n in this case
it should be equal to 1 regardless of n
is this an error with javascript or do some people beleive to the power of 0 should be handled diffrently?
Share Improve this question edited Sep 24, 2012 at 6:36 Gaby_64 asked Sep 24, 2012 at 5:54 Gaby_64Gaby_64 777 bronze badges 4-
What does "n^0=n in this case" mean? You haven't said anything about
bet
,startbet
orshot
. You need to clarify your question - at the moment it's unanswerable. – Jon Skeet Commented Sep 24, 2012 at 5:55 -
What is the value of
startbet
and what is the end value ofbet
that you're getting? – Dai Commented Sep 24, 2012 at 5:55 - @Jon Skeet 2^0=2, 3^0=3, 4^0=4, i thought ^ meant 'to the power of' like in the windows calculator – Gaby_64 Commented Sep 24, 2012 at 6:39
- @user1693548: You mean that's the Javascript behaviour - it wasn't clear what you expected vs what the actual behaviour was. – Jon Skeet Commented Sep 24, 2012 at 7:20
2 Answers
Reset to default 9In Javascript, the ^
operator is bitwise XOR, not exponent.
As Mikhail says, you have to use Math.pow() to pute exponents.
I think you need to use Math.pow instead
本文标签: exponentjavascript power of 0 odd resultStack Overflow
版权声明:本文标题:exponent - javascript power of 0 odd result? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742029315a2416145.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论