Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

For each of the following, assume that we are using a system with single-precisi

ID: 658921 • Letter: F

Question

For each of the following, assume that we are using a system with single-precision (32-bit) floating point numbers (floats) in IEEE format, double-precision (64-bit) doubles in IEEE format, and 32-bit integers. Which of the following evaluate to true for all argument values? (Circle each that is always true).

int x = ..
short y = ..
float f = ..
double d = ..

a) x == (int)(float) x
b) x == (int)(double) x
c) f == (float)(double) f
d) d == (float) d
e) d == -(-d)
f) 3/4 == 3.0/4
g) (double) 3/4 == 3/4.0
h) y == (short)(int) y
i) x == (int)(short) x

Explanation / Answer

a) x == (int)(float) x ---> true
b) x == (int)(double) x ---> false
c) f == (float)(double) f ---> false
d) d == (float) d ---> true
e) d == -(-d) ---> true
f) 3/4 == 3.0/4 ---> false
g) (double) 3/4 == 3/4.0 ---> true
h) y == (short)(int) y ---> false
i) x == (int)(short) x ---> true