Question

We are running programs on a machine where values of type int have a 32-bit two’s-complement...

We are running programs on a machine where values of type int have a 32-bit two’s-complement representation. Values of type float use the 32-bit IEEE format, and values of type double use the 64-bit IEEE format. We generate arbitrary integer values x, y, and z, and convert them to values of type double as follows:

/* Create some arbitrary values */

int x = random();

int y = random();

int z = random();

/* Convert to double */

double dx = (double) x;

double dy = (double) y;

double dz = (double) z;

For each of the following C expressions, you are to indicate whether or not the expression always yields 1. If it always yields 1, describe the underlying mathematical principles. Otherwise, give an example of arguments that make it yield 0. Note that you cannot use an IA32 machine running gcc to test your answers, since it would use the 80-bit extended-precision representation for both float and double.

In addition, one or more of these expressions requires the use of –fwrapv. Explain which ones require this assumption and why.

A. (float) x == (float) dx

B. dx – dy == (double) (x – y)

C. (dx + dy) + dz == dx + (dy + dz)

D. (dx * dy) * dz == dx * (dy * dz)

E. dx/dx = dz/dz

0 0
Add a comment Improve this question Transcribed image text
Answer #1

A. It yields 1 as float(x) rounds off the value of x and float(dx) also rounds off the value of dx which are equal so the statement is true and returns 1

B.IIt yields 0 as dx-dy==double(x-y) is not a correct statement as if x>y then double(x-y) yields negative value which may result is signed overflow

C.IIt yields 1 as associative law is applicable over addition for these datatypes

D. It is false so yields 0 because there may be a problem of overflow as in the case of precision like if dx=123.4566 and dy=192.1728 and dz=max value of double then the multiplication is not possible

E.Returns 0.since the statement is false when dx=0 and dz=1 because dx/dx yields undefined or garbage value.

-fwrapv is used as a flag for generating traps for signed overflow

Here in the above expression B is used with flag -fwrapv as signed subraction overflow and D is used for signed multiplication overflow

Add a comment
Know the answer?
Add Answer to:
We are running programs on a machine where values of type int have a 32-bit two’s-complement...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • So far I have this code but I'm not sure if it's right or how to...

    So far I have this code but I'm not sure if it's right or how to finish it. #include "distance.h" #include <iostream> #include <iomanip> #include <string> using namespace std; Distance::Distance() { feet = 0; miles = 0; yards = 0; inches = 0; } Distance::Distance(int inch) {    } Distance::Distance(int m, int y, int f, double i) { if(m < 0 || y < 0 || f < 0) { feet = 0; miles = 0; yards = 0; }...

  • The following are screen grabs of the provided files Thanks so much for your help, and have a n...

    The following are screen grabs of the provided files Thanks so much for your help, and have a nice day! My Java Programming Teacher Gave me this for practice before the exam, butI can't get it to work, and I need a working version to discuss with my teacher ASAP, and I would like to sleep at some point before the exam. Please Help TEST QUESTION 5: Tamagotchi For this question, you will write a number of classes that you...

  • This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation...

    This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...

  • Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C -...

    Question 1 An array is NOT: A - Made up of different data types. B - Subscripted by integers. C - A consecutive group of memory chunks. D - None of the choices. Question 2 How many times is the body of the loop executed? int i=1; while(true) { cout << i; if(++i==5) break; } A - Forever B - 4 C - 5 D - 6 E - 0 Question 3 What is wrong with the following piece of...

  • could you please help me with this problem, also I need a little text so I...

    could you please help me with this problem, also I need a little text so I can understand how you solved the problem? import java.io.File; import java.util.Scanner; /** * This program lists the files in a directory specified by * the user. The user is asked to type in a directory name. * If the name entered by the user is not a directory, a * message is printed and the program ends. */ public class DirectoryList { public static...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT