Tracing Signed Measurement Conversions

A positioning controller uses the following C function to convert a signed displacement in millimetres into an integer count. Determine the integer actually returned for each displacement in the table. Enter exact integers; trace the implementation without replacing its conversion with a different rounding rule.


C
int displacement_count(double displacement_mm) {
    return (int)(displacement_mm / 0.25);
}


All listed displacements and the divisor are exactly representable in binary floating point, and every result is within the range of int.

Displacement (mm)Returned integer
-0.875
-0.25
-0.125
0.125
0.625
0.75

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Implementation of Algorithms Using C Questions: