Last active
October 25, 2019 09:20
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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