File: DivideByZero.java

package info (click to toggle)
checker-framework-java 3.2.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 23,104 kB
  • sloc: java: 145,916; xml: 839; sh: 518; makefile: 404; perl: 26
file content (75 lines) | stat: -rw-r--r-- 2,710 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package value;

import org.checkerframework.common.value.qual.BottomVal;
import org.checkerframework.common.value.qual.DoubleVal;
import org.checkerframework.common.value.qual.IntVal;

public class DivideByZero {
    void divideNoException(@DoubleVal(1.0) float f, @DoubleVal(1.0) double d, @IntVal(1) int i) {
        @DoubleVal(Float.POSITIVE_INFINITY) float a = f / 0;
        @DoubleVal(Double.POSITIVE_INFINITY) double b = d / 0l;
        @DoubleVal(Double.POSITIVE_INFINITY) double c = i / 0.0;
        @DoubleVal(Float.POSITIVE_INFINITY) float e = i / 0.0f;

        // :: error: (assignment.type.incompatible)
        @BottomVal float a2 = f / 0;
        // :: error: (assignment.type.incompatible)
        @BottomVal double b2 = d / 0L;
        // :: error: (assignment.type.incompatible)
        @BottomVal double c2 = i / 0.0;
        // :: error: (assignment.type.incompatible)
        @BottomVal float e2 = i / 0.0f;
    }

    void remainderNoException(@DoubleVal(1.0) float f, @DoubleVal(1.0) double d, @IntVal(1) int i) {
        @DoubleVal(Float.NaN) float a = f % 0;
        @DoubleVal(Double.NaN) double b = d % 0L;
        @DoubleVal(Double.NaN) double c = i % 0.0;
        @DoubleVal(Float.NaN) float e = i % 0.0f;

        // :: error: (assignment.type.incompatible)
        @BottomVal float a2 = f % 0;
        // :: error: (assignment.type.incompatible)
        @BottomVal double b2 = d % 0l;
        // :: error: (assignment.type.incompatible)
        @BottomVal double c2 = i % 0.0;
        // :: error: (assignment.type.incompatible)
        @BottomVal float e2 = i % 0.0f;
    }

    void integerDivision(
            @IntVal(1) long l,
            @IntVal(1) int i,
            @IntVal(0) byte bZero,
            @IntVal(0) short sZero,
            @IntVal(0L) long lZero,
            @IntVal(0) int iZero) {
        @BottomVal long a = l / bZero;
        @BottomVal long b = l / sZero;
        @BottomVal long c = l / iZero;
        @BottomVal long d = l / lZero;

        @BottomVal long e = i / bZero;
        @BottomVal long f = i / sZero;
        @BottomVal long g = i / iZero;
        @BottomVal long h = i / lZero;
    }

    void integerRemainder(
            @IntVal(1) long l,
            @IntVal(1) int i,
            @IntVal(0) byte bZero,
            @IntVal(0) short sZero,
            @IntVal(0L) long lZero,
            @IntVal(0) int iZero) {
        @BottomVal long a = l % bZero;
        @BottomVal long b = l % sZero;
        @BottomVal long c = l % iZero;
        @BottomVal long d = l % lZero;

        @BottomVal long e = i % bZero;
        @BottomVal long f = i % sZero;
        @BottomVal long g = i % iZero;
        @BottomVal long h = i % lZero;
    }
}