The following algorithm (attributed to Clever Moler) estimates machine precision (eps): a = 4.0/3.0; b = a − 1.0; c = b + b + b; eps = abs(c − 1.0). Implement the program twice with single and double precision variable types and report the value of eps for both single and double precision.
IF YOU HAVE ANY DOUBTS COMMENT BELOW I WILL BE THERE TO HELP YOU
ANSWER:
CODE:
// EPS.java
public class EPS {
public static void main(String[] args) {
// finding eps using single precision (float) variables
float a = (float) (4.0 / 3.0);
float b = (float) (a - 1.0);
float c = b + b + b;
float result = (float) (c - 1.0);
float eps1 = Math.abs(result);
System.out.println("eps for single precision variables: " + eps1);
// finding eps using double precision (float) variables
double x = 4.0 / 3.0;
double y = x - 1.0;
double z = y + y + y;
double eps2 = Math.abs(z - 1.0);
System.out.println("eps for double precision variables: " + eps2);
}
}
/*OUTPUT*/
eps for single precision variables: 1.1920929E-7
eps for double precision variables: 2.220446049250313E-16
RATE THUMBSUP PLEASE
THANKS
The following algorithm (attributed to Clever Moler) estimates machine precision (eps): a = 4.0/3.0; b =...
1. What happens in the Java Virtual Machine (JVM) when the following line is processed? MyClass n = new MyClass(); A. Nothing, the line is skipped, since no parameters are defined B. An object of type MyClass is created, no reference is created C. A reference to an object of type MyClass is created, no object is created D. Both a reference and an object of type MyClass are created 2. Which of the following is true? A. A single...
Create a program (in C, not C++) called lab3.c that declares the following variables and displays their values: Declare a character variable with value 'a', and display the character using printf with %c format. Then add a second printf that displays the character with a %d format. Declare a short int variable with a value set to the maximum value of a short int (the maximum value for whatever machine I happen to use to grade your assignment - so...
Create a program using Visual Studio 2017 called dataExercise.c that declares the following variables and displays their values: 1. Declare a character variable with value 'a', and display the character using printf with a %c format. Then add a second printf that displays the character with a %d format. 2. Declare a short int variable with a value set to the maximum value of a short int (the maximum value for whatever machine I happen to use to grade your...
Write a C program that computes Pi with the approximation algorithm that I introduced in class. I want you to write the program in two different ways: The first version will add up the first 28284277 elements of the approximation series in a simple for loop. I ask you to put the code into a function with this signature: float get_pi_for(void); The second version will break out of a while loop depending on whether a pair of adjacent elements (remember...
Implement the algorithm maxArray, discussed in Section 2.4.3, as
a C++ function.
Make sure the following requirements are met.
Program must compile and run.
maxArray function must be a recursive template function.
Add a main function to test the maxArray function so that you
have a complete program.
Test the maxArray function on two arrays of different
types.
Name the program maxarray.cpp. Make sure the following
requirements are met.
2.4.3 Finding the Largest Value in a Sorted or Unsorted Array...
Part 1: Implement a singly linked list -------------------------------------- (a) Your job is to implement a generic singly linked list that can hold any data type. The interface has been specified and provided to you in a header file called mylist.h. So your job is to write mylist.c that implements each function whose prototype is included in mylist.h. Specifically, you are asked to write the following functions: struct Node *addFront(struct List *list, void *data) void traverseList(struct List *list, void (*f)(void *))...
Needing Help with b and c. Required information [The following information applies to the questions displayed below.] Clarke Corporation manufactures three products (X-1, X-2, and X-3) utilizing, in one of the processes, a single machine for all products. Data on the individual products follow. X-1 X-2 X-3 Price per unit $156 $256 $512 Variable cost per unit $78 $139 $296 Machine hours per unit 1.0 2.5 4.0 Maximum units demand per period 370,000 178,000 ...
The following variables have been declared and assigned values: integer a = 10, integer b = 2, float c =4.0, float d=3.0. State the value of the variable after each statement is executed. Part a: c = a / b + d / b – (b – a) c =__________________ Part b: a = (b > a) a =__________________ Part c: d = d + b d =__________________ Part d: a = b / d + a + b /...
The following financial information is given for Hilton & Marriott: Hilton Marriott Closing Stock Price, October 8, 2002 10.54 27.46 EPS (actual for 2001) 0.45 0.92 EPS (forecast for 2002) 0.51 1.83 Dividend per share 0.08 0.28 5 year forecast earnings growth rate 15.1% 15.7% Common shares outstanding (thousands) 376,025 241,801 Given the October 8 stock prices: a. Based on actual EPS Marriott has a higher PE than Hilton b. Based on either actual or forecast EPS, Marriott has a...
In C code 1. Write and submit the algorithm OR flowchart to indicate you understand the problem 2. Create a project and name the source code lastname_firstname_prog5.c 3. Use the prog5.c as a guide, copy/ paste into your project source code *** build run and test, the outline code - You will need to declare an integer variable called again and initialize it 4. Add the function prototype and implement the function definition for the Greeting function 5. Add the...