2

I have some calculation in javascript that includes exponentiation.

Can any of you say why does this sentence return value 1???

        alert ((0.03+1)^(271/365)-1);

Thanks

InspiredBy
  • 4,271
  • 6
  • 40
  • 67
Ilya Libin
  • 1,576
  • 2
  • 17
  • 39

2 Answers2

10

The ^ is actually a bitwise XOR operator. You're looking for Math.pow():

alert(Math.pow((0.03+1), (271/365))-1);
bfavaretto
  • 71,580
  • 16
  • 111
  • 150
1

Math.pow( (0.03+1), ((271/365)-1) ) will give you a result of 0.9924164970995866

couzzi
  • 6,316
  • 3
  • 24
  • 40
  • I interpreted the original expression differently, with -1 being applied after exponentiation. Then the result would be `0.022188992012574182`. Not sure which of us is correct? – bfavaretto Mar 26 '13 at 22:22
  • Hmm, fair point. My assumption was OP intended everything after the caret to be the part of the exponent. That *does* change things quite a bit though, you are correct! – couzzi Mar 26 '13 at 22:33