It’s doing integer division in the first example as this is the default type for a numeric literal. Try changing it to -1.0/9
(or 1d/9d
– the d suffix indicates a double
) and you should get the same answer.
More Related Contents:
- Division of integers in Java [duplicate]
- Retain precision with double in Java
- Floating point arithmetic not producing exact results [duplicate]
- How many significant digits do floats and doubles have in java?
- Why does integer division code give the wrong answer? [duplicate]
- Convert float to double without losing precision
- When should I use the “strictfp” keyword in java?
- How to convert float to int with Java
- How to check that a string is parseable to a double? [duplicate]
- comparing float/double values using == operator
- Why does (360 / 24) / 60 = 0 … in Java
- Java: Why do you need to specify an ‘f’ in a float literal? [duplicate]
- Why is Double.MIN_VALUE in not negative
- What is the difference between the float and integer data type when the size is the same?
- Double calculation producing odd result [duplicate]
- Why converting from float to double changes the value?
- Do any JVM’s JIT compilers generate code that uses vectorized floating point instructions?
- How can I handle precision error with float in Java?
- Meaning of delta or epsilon argument of assertEquals for double values
- Why does changing the sum order returns a different result?
- How to get the decimal part of a float?
- Why is Java’s Double.compare(double, double) implemented the way it is?
- How do Java runtimes targeting pre-SSE2 processors implement floating-point basic operations?
- Are the bit patterns of NaNs really hardware-dependent?
- Why is comparing floats inconsistent in Java?
- Long float-number output shows letters
- How can I convert integer into float in Java?
- How to convert pcm samples in byte array as floating point numbers in the range -1.0 to 1.0 and back?
- Is checking a double for equality ever safe?
- What is float in Java?