Wrox Programmer Forums > Java Help Floating Point Accuracy
 |
 Java Basics General beginning Java language questions that don't fit in one of the more specific forums. Please specify what version.
 Welcome to the p2p.wrox.com Forums. You are currently viewing the Java Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com

January 28th, 2007, 12:35 AM
 righty Registered User Join Date: Jan 2007 Posts: 1 Thanks: 0 Thanked 0 Times in 0 Posts
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.

 Similar Threads Thread Thread Starter Forum Replies Last Post Floating toolbar in WPF mani85 C# 0 August 6th, 2007 03:37 AM Formating Floating point atoyot Visual Basic 2005 Basics 2 April 26th, 2006 08:36 PM Comparing floating point variables patpicos BOOK: Beginning Java 2, JDK 5 Edition 0 February 1st, 2005 12:37 AM Sum function accuracy problem nuthib Crystal Reports 1 June 21st, 2004 02:12 AM A weird problem with floating point ? tzecheung Javascript 1 June 25th, 2003 06:32 AM