+ 1

Why does alert(3^(-2)) not output 1/9th?

In JavaScript, if you type in: alert(3^(-2)); output = -3 In a calculator: 3^(-2) like you'd expect, output = 1/9th Why does JavaScript not give that output?

22nd Jun 2017, 5:51 PM
Maart
Maart - avatar
4 Réponses
+ 16
alert(Math.pow(3,-2))
22nd Jun 2017, 6:05 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 16
^ (carret) is the bitwise XOR operator...
22nd Jun 2017, 6:06 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 4
Of course, forgot about that, thanks!
22nd Jun 2017, 6:16 PM
Maart
Maart - avatar
+ 2
In programming the '^' is used for something else..... Use Math.pow(3,-2) instead
26th Jun 2017, 8:17 AM
Prabhakar Dev
Prabhakar Dev - avatar