Arithmetic limitations
Expect the unexpected:
byte count = 91; // o.K.
int i = 91;
byte count2 = i; // Compile error: Incompatible types
// Required: byte Found: int
byte points = 130; // Compile error: Incompatible types
// Required: byte Found: intWhy not generally using float / double in favour of
seemingly more limited byte, short, int, long for
arithmetics?
| Code | |
|---|---|
| Result | float value: 999999984306749400 double value: 1000000002000000000 Exact value: 1000000002000000001 |
| Code | // Trying to represent 0.1F // Meaning of »%12.10f«: Print 10 fractional digits within a 12 character field System.out.format("%12.10f\n", Float.intBitsToFloat(0b111101110011001100110011001100)); // ↑ // There is nothing in between // ↓ System.out.format("%12.10f\n", Float.intBitsToFloat(0b111101110011001100110011001101)); |
|---|---|
| Result | 2.099999905 (too small) 2.100000143 (too big) |
Figure 105.
FloatConverter 