Skip to content

Instantly share code, notes, and snippets.

@cruzer45
Last active October 25, 2019 09:20
Show Gist options
  • Save cruzer45/3fb091203640d0aa4488e702fb6b9f3c to your computer and use it in GitHub Desktop.
Save cruzer45/3fb091203640d0aa4488e702fb6b9f3c to your computer and use it in GitHub Desktop.
A file demonstrating some mathematical errors while using Java Primitives. See it in action here https://repl.it/repls/ClientsidePinkChords
class Main {
public static void testWithFloats() {
System.out.println("testWithFloats\n");
float a = 0.1f;
float b = 0.1f;
float c = 0.1f;
float d = a + b + c;
float e = d * 3;
float f = d * 100000;
System.out.println("a + b + c = d = " + d);
System.out.println("e = " + e);
System.out.println("f = " + f);
System.out.println("");
}
public static void testWithDoubles() {
System.out.println("testWithDoubles\n");
double a = 0.1;
double b = 0.1;
double c = 0.1;
double d = a + b + c;
double e = d * 3;
double f = d * 100000;
System.out.println("a + b + c = d = " + d);
System.out.println("e = " + e);
System.out.println("f = " + f);
System.out.println("");
}
public static void main(String[] args) {
testWithFloats();
testWithDoubles();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment