Computer Systems: A Programmer's Perspective (3rd Edition)
Computer Systems: A Programmer's Perspective (3rd Edition)
3rd Edition
ISBN: 9780134092669
Author: Bryant, Randal E. Bryant, David R. O'Hallaron, David R., Randal E.; O'Hallaron, Bryant/O'hallaron
Publisher: PEARSON
bartleby

Videos

Expert Solution & Answer
Book Icon
Chapter 2, Problem 2.89HW

A.

Explanation of Solution

For "C" expression "(float)x==(float)dx":

The given "C" expression is always producing the result as "1". From the expression "(float)x==(float)dx",

  • All double numbers in the given expression are comes from ints.
  • So, when casting from "double" to "float", the value may be rounded because, the precision is lesser.
  • Therefore, both side of expression will be equal.

Program:

A complete program has been developed for the above expression when producing result "1" is shown below.

//Header file

#include <stdio.h>

#include <assert.h>

#include <limits.h>

#include <stdlib

B.

Explanation of Solution

For "C" expression "dx-dy=(double)(x-y)":

  • The given "C" expression does not always produce "1".
  • When the value of "y" is "INT_MIN", the given expression producing the result of "0".

Program:

A complete program has been developed for the above expression when producing result "0" is shown below.

//Header file

#include <stdio.h>

#include <assert.h>

#include <limits.h>

#include <stdlib.h>

//Function definition for part B

int partB(int x, double dx, int y, doubledy)

{

//Return the value

return dx-dy == (double)(x-y);

}

//Main function

int main(intargc, char* argv[])

{

//Assign the value for "x"

int x = rand();

//Assign the value for "y"

int y = rand();

//Converting the value of "x" into double

double dx = (double)x;

//Converting the value of "y" into double

double dy = (double)y;

//Display the value of "x"

printf("%x\n", x);

//Display the value of "y"

printf("%x\n", y);

/* Call function "partB" with checking value using "assert" function */

/* Here producing result as "0", when passing arguments for "x" is "0" and for "y" is "INT_MIN */

assert(!partB(0, (double)(int)0, INT_MIN, (double)(int)INT_MIN));

return 0;

}

The given code is used to return the result for expression "dx-dy=(double)(x-y)"

C.

Explanation of Solution

For "C" expression "(dx+dy)+dz==dx+(dy+dz)":

The given "C" expression is always producing the result as "1". From the given expression, the value of "dx", "dy" and "dz" are all double numbers from "ints".

  • So, the result will be "double" value when adding the numbers in both side of given expression.

Program:

A complete program has been developed for the above expression when producing result "1" is shown below.

//Header file

#include <stdio.h>

#include <assert.h>

#include <limits.h>

#include <stdlib.h>

int partC(double dx, double dy, double dz)

{

//Returns the value

return (dx+dy)+dz == dx+(dy+dz);

}

//Main function

int main(intargc, char* argv[])

{

//Assign the value for "x"

int x = rand();

//Assign the value for "y"

int y = rand();

//Assign the value for "z"

int z = rand();

//Converting the value of "x" into double

double dx = (double)x;

//Converting the value of "y" into double

double dy = (double)y;

//Converting the value of "z" into double

double dz = (double)z;

//Display the value of "x"

printf("%x\n", x);

//Display the value of "y"

printf("%x\n", y);

//Display the value of "z"

printf(

D.

Explanation of Solution

For "C" expression "(dx*dy)*dz==dx*(dy*dz)":

  • The given "C" expression does not always produce "1".
  • When multiplying three "double" numbers, the results from both side of expression is different that is not equal.
    • Since, the precedence of the multiplication.
    • There are two multiplication operation in each side of given expression
      • The multiply operator "*" performs a left to right associativity.
      • Consider the left side of expression "(dx*dy)*dz".
        • In this expression "dx*dy" is calculated first and then multiplied with "dz".
      • Consider the right side of expression "dx*(dy*dz)".
        • In this expression "dx" is multiplied with"dy*dz".
    • So, calculation of any one side of given expressionoccurs to yield a rounding error in result.
      • Because, if a value in it simple, it can’t be denoted by a floating point value.

Program:

A complete program has been developed for the above expression when producing result "0" is shown below.

//Header file

#include <stdio.h>

#include <assert.h>

#include <limits.h>

#include <stdlib

E.

Explanation of Solution

For "C" expression "dx/dx==dz/dz":

  • The given "C" expression does not always produce "1".
  • When "dx" is not equal to "0" and "dz" value is equal to "0", the given expression producing the result of "0".
    • That is the expression of both side are not equals.

Program:

A complete program has been developed for the above expression when producing result "0" is shown below.

//Header file

#include <stdio.h>

#include <assert.h>

#include <limits.h>

#include <stdlib.h>

//Function definition

int partE(double dx, double dz)

{

//Returns the value

return dx/dx == dz/dz;

}

//Main function

int main(int argc, char* argv[])

{

//Assign the value for "x"

int x = rand();

//Assign the value for "z"

int z = rand();

//Converting the value of "x" into double

double dx = (double)x;

//Converting the value of "z" into double

double dz = (double)z;

//Display the value of "x"

printf("%x\n", x);

//Display the value of "z"

printf("%x\n", z);

/* Call function "partE" with checking value using "assert" function */

assert(partE(dx, (double)(int)0));

return 0;

}

The given code is used to return the value of expression "dx/dx==dz/dz"

Blurred answer
Students have asked these similar questions
You are tasked with developing a portable system that can be worn to collect health and fitness data. The challenge is to integrate all functions into the smaller form of an ear clip. The device should include heart rate, movement and temperature sensor and wireless communication with a mobile app. Draw a diagram- hardware architecture of the system- including the selection of suitable sensors, communication modules, and an energy-efficient microcontroller. (visualize the components and their connections)
Draw out an example of 3 systems using Lamport’s logical clock and explain the steps in words.
"Systems have become very powerful and sophisticated, providing quality information fordecisions that enable the firm to coordinate both internally and externally."With reference to the above statement compare the operations of any three data gatheringsystems today’s organisations use to aid decision making.

Chapter 2 Solutions

Computer Systems: A Programmer's Perspective (3rd Edition)

Chapter 2.1, Problem 2.11PP Chapter 2.1, Problem 2.12PP Chapter 2.1, Problem 2.13PP Chapter 2.1, Problem 2.14PP Chapter 2.1, Problem 2.15PP Chapter 2.1, Problem 2.16PP Chapter 2.2, Problem 2.17PP Chapter 2.2, Problem 2.18PP Chapter 2.2, Problem 2.19PP Chapter 2.2, Problem 2.20PP Chapter 2.2, Problem 2.21PP Chapter 2.2, Problem 2.22PP Chapter 2.2, Problem 2.23PP Chapter 2.2, Problem 2.24PP Chapter 2.2, Problem 2.25PP Chapter 2.2, Problem 2.26PP Chapter 2.3, Problem 2.27PP Chapter 2.3, Problem 2.28PP Chapter 2.3, Problem 2.29PP Chapter 2.3, Problem 2.30PP Chapter 2.3, Problem 2.31PP Chapter 2.3, Problem 2.32PP Chapter 2.3, Problem 2.33PP Chapter 2.3, Problem 2.34PP Chapter 2.3, Problem 2.35PP Chapter 2.3, Problem 2.36PP Chapter 2.3, Problem 2.37PP Chapter 2.3, Problem 2.38PP Chapter 2.3, Problem 2.39PP Chapter 2.3, Problem 2.40PP Chapter 2.3, Problem 2.41PP Chapter 2.3, Problem 2.42PP Chapter 2.3, Problem 2.43PP Chapter 2.3, Problem 2.44PP Chapter 2.4, Problem 2.45PP Chapter 2.4, Problem 2.46PP Chapter 2.4, Problem 2.47PP Chapter 2.4, Problem 2.48PP Chapter 2.4, Problem 2.49PP Chapter 2.4, Problem 2.50PP Chapter 2.4, Problem 2.51PP Chapter 2.4, Problem 2.52PP Chapter 2.4, Problem 2.53PP Chapter 2.4, Problem 2.54PP Chapter 2, Problem 2.55HW Chapter 2, Problem 2.56HW Chapter 2, Problem 2.57HW Chapter 2, Problem 2.58HW Chapter 2, Problem 2.59HW Chapter 2, Problem 2.60HW Chapter 2, Problem 2.61HW Chapter 2, Problem 2.62HW Chapter 2, Problem 2.63HW Chapter 2, Problem 2.64HW Chapter 2, Problem 2.65HW Chapter 2, Problem 2.66HW Chapter 2, Problem 2.67HW Chapter 2, Problem 2.68HW Chapter 2, Problem 2.69HW Chapter 2, Problem 2.70HW Chapter 2, Problem 2.71HW Chapter 2, Problem 2.72HW Chapter 2, Problem 2.73HW Chapter 2, Problem 2.74HW Chapter 2, Problem 2.75HW Chapter 2, Problem 2.76HW Chapter 2, Problem 2.77HW Chapter 2, Problem 2.78HW Chapter 2, Problem 2.79HW Chapter 2, Problem 2.80HW Chapter 2, Problem 2.81HW Chapter 2, Problem 2.82HW Chapter 2, Problem 2.83HW Chapter 2, Problem 2.84HW Chapter 2, Problem 2.85HW Chapter 2, Problem 2.86HW Chapter 2, Problem 2.87HW Chapter 2, Problem 2.88HW Chapter 2, Problem 2.89HW Chapter 2, Problem 2.90HW Chapter 2, Problem 2.91HW Chapter 2, Problem 2.92HW Chapter 2, Problem 2.93HW Chapter 2, Problem 2.94HW Chapter 2, Problem 2.95HW Chapter 2, Problem 2.96HW Chapter 2, Problem 2.97HW

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
The angle θ that will cause motion of one of the blocks and the friction forces under each of the blocks.

INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)

The value of n and C in Taylor’s tool life equation for each case.

Degarmo's Materials And Processes In Manufacturing

Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    C++ for Engineers and Scientists
    Computer Science
    ISBN:9781133187844
    Author:Bronson, Gary J.
    Publisher:Course Technology Ptr
    Text book image
    C++ Programming: From Problem Analysis to Program...
    Computer Science
    ISBN:9781337102087
    Author:D. S. Malik
    Publisher:Cengage Learning
    Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
    Text book image
    Systems Architecture
    Computer Science
    ISBN:9781305080195
    Author:Stephen D. Burd
    Publisher:Cengage Learning
    Text book image
    Programming Logic & Design Comprehensive
    Computer Science
    ISBN:9781337669405
    Author:FARRELL
    Publisher:Cengage
    CPP Function Parameters | Returning Values from Functions | C++ Video Tutorial; Author: LearningLad;https://www.youtube.com/watch?v=WqukJuBnLQU; License: Standard YouTube License, CC-BY