Arithmetic limitations

Expect the unexpected:

Figure 101. Strange things I Slide presentation
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: int

Figure 102. Strange things II Slide presentation
final int i = 91;

byte count = i;   //  o.K.

Why not generally using float / double in favour of seemingly more limited byte, short, int, long for arithmetics?

Figure 103. Limited precision Slide presentation
float float2Power31 = Integer.MAX_VALUE + 1f; // (2^31 - 1) + 1 == 2^31

float float2Power63 = 2 * float2Power31 * float2Power31; // 2^63
float float2Power63_minus_one = float2Power63 - 1f; // 2^63 - 1

System.out.format( "   Float value: %f\n", float2Power63_minus_one); // Value near 2^63 - 1
System.out.println("Expected value: "   +  Long.MAX_VALUE);// Exact value 2^63 - 1

Result:

   Float value:  9223372036854776000.000000
Expected value:  9223372036854775807
------------------------------------------
    Difference:                  193

Figure 104. Nearest float to 2.1F Slide presentation
// Trying to represent 2.1F
// Print 9 fractional digits

System.out.format("%.9f\n", Float.intBitsToFloat(0b0_10000000_00001100110011001100110));
System.out.format("%.9f\n", Float.intBitsToFloat(0b0_10000000_00001100110011001100111));
2.099999905
2.100000143

Figure 105. FloatConverter Slide presentation
FloatConverter