Could someone explain this textbook example regarding float fl(x)

In summary, the conversation is about finding the fl(x) for 9.4 in binary. The process involves rounding to the nearest rule and discarding the infinite tail, resulting in a binary number that is then converted back to decimal. The final result is 9.4 + 0.2 x 2^-49, which is achieved by adding a digit that amounts to 2^-49 to the truncated bit pattern. This explains how fl(9.4) is equal to 9.4 + 0.2 x 2^-49 without using a computer.
  • #1
catsarebad
72
0
Hi,

okay here's the problem:

*find fl(x) for 9.4*

and here's how it's done

9.4 in binary is 1001.0110 0110 0110 since
9 = 1001
.4 = .0110 0110 0110... (basically, 0110 repeating)

next using Rounding to Nearest Rule (see top on picture) we get what a binary number (boxed in black in the picture below)

I understand how to do upto here perfectly however I do not understand what happens after that.

I'm confused by pretty much the entire thing that follows after "discarding the infinite tail". I do not understand how fl(9.4) turns out to be 9.4 + 0.2 x 2^(-49) (shown in red box in the picture).

could anyone provide explanation for this?

the book has another example similar to this but i couldn't follow either of them. i hope someone can explain me the basics of what is happening here.

http://i.imgur.com/IOpfVjm.jpg

(image not embedded because it is too big and breaks the thread)
 
Technology news on Phys.org
  • #2
long story short, I'm trying to figure out how

fl(9.4) = 9.4 + 0.2 x 2^(-49)

without using computer
 
  • #3
I'll take a stab at it:
The binary representation of 9.4 is standardized so that the leading digit before the decimal point is 1. That is how it will be stored in the computer and it let's you know how much will be truncated. The truncated part is a bit pattern that amounts to 0.4x(2^-48). The fl rule for rounding adds a digit that amounts to 2^-49. So the final bit pattern amounts to

9.4 + rounded - truncated = 9.4 + 2^-49 - 0.4 x (2^-48).

The rest is arithmetic.
 
Last edited:

What is a float in programming?

A float is a data type in programming that represents a decimal number with a fractional component. It is commonly used to store and manipulate numbers with decimal points.

What does the term "fl(x)" mean in this context?

In this context, "fl(x)" is a mathematical notation that represents a floating-point number. It is used to indicate that the value of x is a floating-point number.

Can you give an example of how float fl(x) is used in a textbook?

Sure, let's say a textbook example asks you to write a program that calculates the average of two numbers, one of which is a floating-point number. In this case, the program may prompt the user to input two numbers, and then use the "fl" function to convert the second number into a floating-point number. The resulting code may look like this:
float num1 = 5;
float num2 = fl(7); //converts 7 into a floating-point number
float average = (num1 + num2) / 2;
cout << "The average is: " << average;

Why is it important to use float fl(x) instead of just a regular number?

Using float fl(x) allows for more precise calculations when working with decimal numbers. In some programming languages, like C++, regular numbers are treated as integers and therefore cannot handle decimal points. Using float fl(x) ensures that the computer recognizes the number as a floating-point number and performs accurate calculations.

Are there any potential issues with using float fl(x) in programming?

Yes, there are some potential issues to keep in mind when using float fl(x). One issue is that floating-point numbers have limited precision, which means that they may not be able to accurately represent certain decimal values. Additionally, performing arithmetic operations on floating-point numbers may also result in rounding errors. It's important to be aware of these potential issues and use caution when working with floating-point numbers in programming.

Similar threads

Replies
13
Views
504
  • Linear and Abstract Algebra
Replies
2
Views
1K
  • Feedback and Announcements
Replies
1
Views
417
  • General Discussion
Replies
4
Views
665
  • Science and Math Textbooks
Replies
1
Views
2K
  • Quantum Physics
Replies
1
Views
1K
  • Special and General Relativity
Replies
16
Views
1K
  • Calculus and Beyond Homework Help
Replies
4
Views
4K
Replies
1
Views
745
  • Programming and Computer Science
Replies
4
Views
3K
Back
Top