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 › 1.4901161E-8 as output etc
Page Index Toggle Pages: 1
1.4901161E-8 as output etc? (Read 553 times)
1.4901161E-8 as output etc?
Mar 17th, 2010, 2:55pm
 
I get things like 1.4901161E-8 in the output, is that correct or is there something wrong with my syntax?

Code:
float yShift = 0;
float step = 0.1;
float dir = 1;

for(int i = 0; i < 400; i++){
yShift += step*dir;
if(yShift > 1 || yShift < 0.0){
dir = -dir;;
}
println(yShift);
}
Re: 1.4901161E-8 as output etc?
Reply #1 - Mar 17th, 2010, 3:17pm
 
nope, everything is fine. never typed some really large numbers on your calculator in school? Smiley
Re: 1.4901161E-8 as output etc?
Reply #2 - Mar 17th, 2010, 6:02pm
 
clankill3r wrote on Mar 17th, 2010, 2:55pm:
I get things like 1.4901161E-8 in the output, is that correct or is there something wrong with my syntax

1.4901161E-8 is:

1.4901161 * 10^(-8), which is:

0.000000014901161

It's normal.  Floating point numbers get rounded from time to time in odd places, so if you do a long string of operations that should add up to zero, sometimes it won't come out to exactly zero.
Re: 1.4901161E-8 as output etc?
Reply #3 - Mar 18th, 2010, 1:09am
 
in school all i got on my calculator was a E in the end and i thought that was for error.

thx Smiley
Page Index Toggle Pages: 1