Assume that x is a variable of type int Will the operation x
Assume that x is a variable of type int.
Will the operation:
x == (int) (double) x
always evaluate to 1 (true)?
Select one:
a. no, because casting an int to a double may cause rounding
b. yes, because the value of int x can be represented in a double exactly
c. no, because a double can\'t represent an int exactly
Question 2
Not yet answered
Points out of 1.00
Flag question
Question text
Assume that x is a variable of type int.
Will the operation:
x == (int) (float) x
always evaluate to 1 (true)?
Select one:
a. no, because a float doesn\'t have enough precision to represent all values of an int exactly
b. yes, because the value of int x can be represented in a float exactly
c. yes, because the compiler will simply ignore the two casts
Question 3
Not yet answered
Points out of 1.00
Flag question
Question text
Assume that f is a variable of type float.
Will the operation:
f == (float) (double) f
always evaluate to 1 (true)?
Select one:
a. yes, because the compiler will simply ignore the two casts
b. yes, because a double has greater range of representable values and precision (significant bits) than a float
c. no, because of rounding
Question 4
Not yet answered
Points out of 1.00
Flag question
Question text
Assuming the following:
int x = random(); //set x to some random int
int y = random();
double dx = (double) x;
double dy = (double) y;
Will the operation:
(dx - dy) == (double) (x - y)
always result in 1 (true)?
Select one:
a. yes, because the compiler will cast x and y to doubles before subtraction
b. no, because x - y may cause an overflow and dx - dy will not
c. no, because of rounding
Question 5
Not yet answered
Points out of 1.00
Flag question
Question text
Assuming the following:
int x = random(); //set x to some random int
int y = random();
int z = random();
double dx = (double) x;
double dy = (double) y;
double dz = (double) z;
Will the operation:
(dx + dy) + dz == dx + (dy + dz)
always result in 1 (true)?
Select one:
a. no, because depending upon the order of operations an overflow may occur
b. yes, because the values range between TMIN and TMAX thus no computation will result in overflow
c. no, because of rounding
Question 6
Not yet answered
Points out of 1.00
Flag question
Question text
Assuming the following:
int x = random(); //set x to some random int
int y = random();
int z = random();
double dx = (double) x;
double dy = (double) y;
double dz = (double) z;
Will the operation:
(dx * dy) * dz == dx * (dy * dz)
always result in 1 (true)?
Select one:
a. yes, because the values range between TMIN and TMAX thus no computation will result in overflow
b. no, because of rounding or possiblity of overflow
Question 7
Not yet answered
Points out of 1.00
Flag question
Question text
Assuming the following:
int x = random(); //set x to some random int
int y = random();
double dx = (double) x;
double dy = (double) y;
Will the operation:
dx / dx == dy / dy
always result in 1 (true)?
Select one:
a. no, because one of the results could be positive or negative infinity (division by 0)
b. yes, each will always result in 1.0
Select one:
a. Hex = 3BB0, M = 123/128, E = -1, V = 123 * 2-7
b. Hex = 3BB0, M = 123/64, E = -1, V = 123 * 2-7
c. Hex = 3BB0, M = 123/128, E = -2, V = 123 * 2-7
d. Hex = 3BB0, M = 123/64, E = -1, V = 123 * 2-6
e. Hex = 3BB0, M = 123/64, E = -2, V = 123 * 2-7
Question 14
Not yet answered
Points out of 1.00
Flag question
Question text
Using IEEE standard for 32-bit floating point, give the hex representation for -10.375. (You\'ll convert into binary using the technique described in your book and then convert the binary to hex -- 8 hex digits, no spaces.)
Answer:
Question 15
Not yet answered
Points out of 1.00
Flag question
Question text
Using IEEE standard for 32-bit floating point, give the hex representation for .75. (You\'ll convert into binary using the technique described in your book and then convert the binary to hex -- 8 hex digits, no spaces.)
Answer:
Solution
Question 1:
b. yes, because the value of int x can be represented in a double exactly.
Question 2:
b. yes, because the value of int x can be represented in a float exactly.
Question 3:
b. yes, because a double has greater range of representable values and precision (significant bits) than a float
Question 4:
a. yes, because the compiler will cast x and y to doubles before subtraction.
Question 5:
b. yes, because the values range between TMIN and TMAX thus no computation will result in overflow.
Question 6:
a. yes, because the values range between TMIN and TMAX thus no computation will result in overflow.
Question 7:
b. yes, each will always result in 1.0



