Hi everyone,
In regular Java and other programming languages, this is well known that you can write :
System.out.println(0.1 + 0.2 == 0.3);
which gives false
!!
This is due to floating point precision and how computers store float values : https://0.30000000000000004.com/
Now typing the same in Processing gives this :
System.out.println(0.1 + 0.2); // -> 0.3
So at first I was very intrigued!
But looking at the exported application, I saw the packaged code :
import processing.core.*;
import processing.data.*;
import processing.event.*;
import processing.opengl.*;
import java.util.HashMap;
import java.util.ArrayList;
import java.io.File;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
public class precision extends PApplet {
public void setup() {
System.out.println(0.1f + 0.2f);
noLoop();
}
static public void main(String[] passedArgs) {
String[] appletArgs = new String[] { "precision" };
if (passedArgs != null) {
PApplet.main(concat(appletArgs, passedArgs));
} else {
PApplet.main(appletArgs);
}
}
}
Which shows that Processing is adding the letter f
to each double literal value automatically.
Actually in the Java section it shows that using floats solve this issue.
Thought, this is nice for us :
Is the fact that float values avoid some precision errors the only reason behind Processing changing things behind the scene?
Also how much does the Processing IDE hide code pre processing for us? (I know that it wraps the whole code inside the PApplet
class )