We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › natural E constant
Page Index Toggle Pages: 1
natural E constant? (Read 2516 times)
natural E constant?
Apr 21st, 2005, 11:40am
 
Is there any E constant, or an exp() function?
Re: natural E constant?
Reply #1 - Apr 21st, 2005, 3:40pm
 
Since Processing sits on top of Java, you can always snag these from Math, but you'll have to remember to cast them to float for most Processing purposes (I believe they're double by default).

For example:
Code:
float E = (float) Math.E; 



I also tried the following, but I was informed (by the compiler) that exp already exists as a final method in PApplet. Oops.  Looks like we surfaced an undocumented method.

Code:

float exp(float a) {
return (float) Math.exp(a);
}


Perhaps we need to throw that one in with the rest of the mathematics docs.
Re: natural E constant?
Reply #2 - Apr 21st, 2005, 4:02pm
 
Thanks!

Don't you think it would be a good idea to have the E constant the same way as HALF_PI, PI and TWO_PI, is there a reason for not having it that way?

And thanks for pointing out about the hidden exp() function.  I think it would be a good idea to document it as you say, in the complete reference.
Re: natural E constant?
Reply #3 - Apr 21st, 2005, 4:45pm
 
E is a tricky one.  You're unlikely to want a variable called PI which isn't 3.141..., but E isn't so safe.  If you need E, try this:

Code:

float E = exp(1);

Page Index Toggle Pages: 1