Question

4. (10 points) Write a computer code to compute the unit roundoff error (machine epsilon) on a given machine using double precision. You need to compute the smallest positive machine number є such that 1 + є I. (Hint: You can divide the number 1 by 2 repeatedly, each time the division is equivalent to adding a zero before the binary point.) The computer computed machine epsilon number and the code has to be attached to your homework.

Please write in C or C++, professor said it's supposed to be pretty short, like 10 lines, if that helps.  

I also need to have a check for an infinite loop. Thanks in advance!

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

int main() {
   double e = 1;
   while(1+e != 1) {
      e /= 2;
   }
   printf("unit roundoff error is %.50lf\n", e);
   return 0;
}

Output:

unit roundoff error is 0.00000000000000011102230246251565404236316680908203

Add a comment
Know the answer?
Add Answer to:
Please write in C or C++, professor said it's supposed to be pretty short, like 10...
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
  • use python Task 1: Machine Epsilon (10 pts) Machine epsilon e is a characteristic of the...

    use python Task 1: Machine Epsilon (10 pts) Machine epsilon e is a characteristic of the CPU in ones computer. This machine constant is used extensively when writing computer code to help make ones algorithms CPU insensitive. Machine epsilon e is the smallest number e such that 1 +e>1 in floating-point arithmetic. For any smaller value of e, round-off error would return 1+e = 1. Machine epsilon is defined by the formula b-where b is the base number used by...

  • Note: Write the pseudocode separately and the source code separately in java using the loops method...

    Note: Write the pseudocode separately and the source code separately in java using the loops method according to the question. Please make sure there is no errors. Program 0 (Warm up): Gimme a cookie! In the early days of computing, you likely couldn't afford your own computer. Instead, you had to sit at a terminal - which was literally just a monochrome monitor and keyboard that was connected to a big mainframe machine (hidden somewhere in the building). When you...

  • Please help me with this short, matlab/diffy q project.. teacher said it’s supposed to be a short code Matlab Project Recall that we can approximate the time derivative of a function y(t) at time...

    Please help me with this short, matlab/diffy q project.. teacher said it’s supposed to be a short code Matlab Project Recall that we can approximate the time derivative of a function y(t) at time tn as dt ΔΙ This follows from the limit definition of the derivative and gives the approximate slope of the function y(t) at time tn If we think about 'stepping through time from some initial time to a later time in steps of size At, then...

  • Please write below code in C++ using Visual Studio. Write program that uses a class template...

    Please write below code in C++ using Visual Studio. Write program that uses a class template to create a set of items. The program should: 1. add items to the set (there shouldn't be any duplicates) • Example: if your codes is adding three integers, 10, 5, 10, then your program will add only two values 10 and 5 • Hint: Use vectors and vector functions to store the set of items 2. Get the number of items in the...

  • Please write C++ code Description: As a senior software engineer, I would like to determine and...

    Please write C++ code Description: As a senior software engineer, I would like to determine and prove which sorting algorithm is the most efficient between quick sort, merge sort, and heap sort so that I can recommend it to the development team for inclusion in the code base of an upcoming code optimization project. Acceptance Criteria: Well documented, executable C++ source files including classes for each of the aforementioned sorting algorithms. In addition, each sorting algorithm class implementation should be...

  • Help me finish the remaining sections. It's pretty self explanatory on here but i am busy...

    Help me finish the remaining sections. It's pretty self explanatory on here but i am busy with work so i am unable to finish it. The requirements and needed information are included on the pictures. I answered most of the sections but i need requirement 2 and requirement 3 still Cardinal Design, Inc. is a Web site design and consulting firm. The firm uses a job order costing system in which each client is a different job. Cardinal Design assigns...

  • C++ PROGRAM ONLY! For this lab you need to write a program that will read in...

    C++ PROGRAM ONLY! For this lab you need to write a program that will read in two values from a user and output the greatest common divisor (using a recursive implementation of the Euclidean algorithm) to a file. In Lab #3, you implemented this program using an iterative method. Greatest Common Divisor In mathematics, the greatest common divisor (GCD) of two or more integers (when at least one of of them is zero then the larger value is the GCD....

  • *Write a parallel program pie.c in C or C++ (pie.cc) for Linux that computes an approximation of the number π using a se...

    *Write a parallel program pie.c in C or C++ (pie.cc) for Linux that computes an approximation of the number π using a series with N+1 terms.* --The series sum is partitioned in T non-overlapping partial sums, each computed by T separate child processes created with the fork() library function.* --This program demonstrates data parallelism and interprocess communication using pipes. Each child process could perform a (potentially) long computation on a separate CPU (or core). Depending on the computer architecture, the...

  • Please I need help with this c++ code. please show all steps , write comments and...

    Please I need help with this c++ code. please show all steps , write comments and show sample runs. Thank you. 1. The Federal Bureau of Investigation (FBI) has recently changed its Universal Control Numbers (UCN) for identifying individuals who are in the FBI's fingerprint database to an eight-digit base 27 value with a ninth check digit. The digits used are: 0123456789ACDE FHJKLMNPRTVWX Some letters are not used because of possible confusion with other digits: B->8, G->C, I- >1, 0->0,...

  • Professor Dolittle has asked some computer science students to write a program that will help him...

    Professor Dolittle has asked some computer science students to write a program that will help him calculate his final grades. Professor Dolittle gives two midterms and a final exam. Each of these is worth 100 points. In addition, he gives a number of homework assignments during the semester. Each homework assignment is worth 100 points. At the end of the semester, Professor Dolittle wants to calculate the median score on the homework assignments for the semester. He believes that the...

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