Help Floating Point Accuracy
hi, im new to java and was wondering if anyone can help me. im my lab im suppose to do this:
So we have:
+ 1.875 x 22 = 7.5f, which is a floating point number that can be represented exactly in Java.
Assume that 12.36f is represented as 01000001010001011100001010001111. This bit pattern is not exactly 12.36, but it is very close. As a float can only hold 32 bits, many numbers cannot be represented exactly, and this can introduce errors in calculations. Using the rules described above, write a program to compute the decimal number that the bit pattern for 12.36f actually corresponds to. It will not be exactly 12.36, but very close. Your program does not have to be interactive. It only needs to be able to compute the decimal number for the above bit pattern. Since you are computing the error contained in floats, should you use floats or doubles to perform your calculation? Print out your result.
Next, compute the percentage error of the value just computed from the actual value. As your computed value represents the "approximate" value, should you use doubles or floats to represent the actual value, which you need in order to compute the percentage error? Print the percentage error.
Over the course of the semester, you may encounter strange output that is related to the fact that many numbers cannot be represented exactly. To see what this strange output might look like, add a few more statements to your program. Declare a float and give it the value 12.36f. Print the result. Now add 100.2f and then immediately subtract 100.2f. Print the result. Write a paragraph describing your strange output and speculate as to why you get what you get.
i dont need someone to do it for me. i just want someone to explain to me what im suppose to do. or some samples of what it wants me to do. i just need someone to guide me through this. any help would be greatly appreciated. thank you.
|All times are GMT +5.5. The time now is 12:12.|