How can you represent mathematical constant "e" as a value in JavaScript?
views:
228answers:
7+1 for the fastest gun! :)
Daniel Vassallo
2010-04-27 11:47:55
Only just..... :)
Tim Down
2010-04-27 11:50:47
+3
A:
Answer was too short, so here is a much much longer version.
Math.E
Kristoffer S Hansen
2010-04-27 11:46:54
+2
A:
JavaScript provides many mathematical constants that can be accessed from the Math object
.
The one you want is Math.E
codaddict
2010-04-27 11:47:34
+8
A:
Other ways include:
Math.exp(1)
Approximations:
3-sqrt(5/63)
or
(Math.PI^4 + Math.PI^5)^(1/6)
which are good to 7 digits
and
163^(32/163)
which is good to 6 digits
gd047
2010-04-27 12:38:03
+1 Approximations are good to know. The OP probably didn't know about Math.E, so he was probably looking for something along this line originally.
Danny
2010-04-27 12:50:01
A:
e is represented by Math.E. But if your intention is to compute e^x, don't write Math.E^x. Use Math.exp(x) instead. It wouldn't be the first time someone has asked for e when they really want exp.