What are Floating Point Numbers? An Explanation with Examples

Click For Summary

Discussion Overview

The discussion revolves around the concept of floating point numbers, particularly in the context of computer programming and numerical methods. Participants seek to understand the definition, representation, and implications of using floating point numbers in calculations.

Discussion Character

  • Exploratory
  • Technical explanation
  • Homework-related

Main Points Raised

  • Some participants describe floating point numbers as a way to represent a wider range of numbers, including exponents.
  • It is noted that in a computer programming context, floating point numbers can refer to any number with a decimal value, contrasting with integers.
  • Participants emphasize that floating point numbers are stored as approximations, which can lead to issues with equality testing and precision in calculations.
  • Some participants mention specific examples of floating point numbers that can be stored exactly, while others highlight the potential for roundoff error in calculations.
  • There are discussions about the importance of handling floating point numbers correctly in programming and the need for further study on numerical computing.
  • A participant requests recommendations for a numerical methods book to better understand floating point representation and error calculations.
  • Examples from MATLAB are provided to illustrate roundoff error and the concept of machine epsilon.

Areas of Agreement / Disagreement

Participants express varying levels of understanding and agreement on the implications of floating point numbers, particularly regarding their representation and the challenges they pose in programming. The discussion remains unresolved on some technical aspects, such as the best practices for handling floating point comparisons.

Contextual Notes

Limitations include the lack of consensus on specific numerical methods or textbooks, and the discussion reflects a range of experiences and knowledge levels among participants regarding floating point numbers.

Who May Find This Useful

This discussion may be useful for students in computer programming or numerical methods courses, as well as those interested in understanding the implications of floating point arithmetic in computing.

SherlockOhms
Messages
309
Reaction score
0
So, I'm not 100% sure if this is actually in the correct forum or whether it should be under Mathematics. Anyway, our lecturer told us that we'd soon cover "Floating Point Numbers". Could someone give me a basic, somewhat simple explanation of what these are? Possibly with a few examples. Just so I have an idea of what to expect. Thanks!
 
Technology news on Phys.org
SherlockOhms said:
So, I'm not 100% sure if this is actually in the correct forum or whether it should be under Mathematics. Anyway, our lecturer told us that we'd soon cover "Floating Point Numbers". Could someone give me a basic, somewhat simple explanation of what these are? Possibly with a few examples. Just so I have an idea of what to expect. Thanks!

It's a way to represent a wider range of numbers -- basically including exponents in the representation:

http://en.wikipedia.org/wiki/Floating_point

:smile:
 
If your class is a Computer Science / Programming class, a floating point number could refer to any number with a decimal value. 1 is an integer, 1.0 can be considered a float. This is crucial to understand for computer programming. If it is not for a computer programming class, then the aforementioned post by berkeman provides a good link to wikipedia's definition on floating point numbers.



Gary
 
Right, I think I've got it. Sort of anyway. Thanks for the help. I guess I'll just have to wait and see what the lecturer is going to show us. Thanks again.
 
Don't you have a textbook or other recommended reference source?
 
Nope. Not yet anyway. There's no recommended text for the course and we only began last Monday. Things will become clearer over the next few weeks.
 
SherlockOhms said:
Nope. Not yet anyway. There's no recommended text for the course and we only began last Monday. Things will become clearer over the next few weeks.

Surely you DO know what kind of class you are in, no? Is it a computer science class, a physics class, a math class, what?
 
Of course. Never said I didn't. It's a computer programming class with numerical methods involved.
 
SherlockOhms said:
Of course. Never said I didn't. It's a computer programming class with numerical methods involved.

Then read post #3
 
  • #10
MrTheBard said:
If your class is a Computer Science / Programming class, a floating point number could refer to any number with a decimal value. 1 is an integer, 1.0 can be considered a float. This is crucial to understand for computer programming. If it is not for a computer programming class, then the aforementioned post by berkeman provides a good link to wikipedia's definition on floating point numbers.



Gary

A key thing to remember about floating point numbers, as used in computers, is that they are stored as approximations, unlike integers which can be represented exactly. Thus, one must never test two numbers of type float for equality (as in does "x = y", where both are floating point numbers), because even if they are so closely approximated that both print out as having a value of, say 1.3, the equality test might still fail.

Further, because of how they are stored, it is possible to have issues with overflow and loss of precision when doing calculations with them (depending on the order in which computations are done to the numbers, for example). To learn about these things, read a book on numerical computing (or wait until your professor covers them).

Handling floating point numbers correctly in programming is an important topic, and may take some time to learn.
 
  • Like
Likes   Reactions: 1 person
  • #11
harborsparrow said:
A key thing to remember about floating point numbers, as used in computers, is that they are stored as approximations, unlike integers which can be represented exactly.
Most floating point numbers are stored as approximations, but some are stored exactly, such as 1.5, 3.75, and -4.875. Any number whose fractional part is made up of a finite sum of powers of 1/2 (within limits based on the size of the mantissa) is stored exactly.
harborsparrow said:
Thus, one must never test two numbers of type float for equality (as in does "x = y", where both are floating point numbers), because even if they are so closely approximated that both print out as having a value of, say 1.3, the equality test might still fail.

Further, because of how they are stored, it is possible to have issues with overflow and loss of precision when doing calculations with them (depending on the order in which computations are done to the numbers, for example). To learn about these things, read a book on numerical computing (or wait until your professor covers them).

Handling floating point numbers correctly in programming is an important topic, and may take some time to learn.
 
  • #12
harborsparrow said:
Thus, one must never test two numbers of type float for equality (as in does "x = y", where both are floating point numbers), because even if they are so closely approximated that both print out as having a value of, say 1.3, the equality test might still fail.

And remember in C at least, the check four equality would be "x == y", since == is a comparison and = is an assignment. Too easy to get those mixed up... :smile:
 
  • Like
Likes   Reactions: 1 person
  • #13
Thanks for all the info, guys.
 
  • #14
I, for one, am not a guy. But I'll take the thank you generically.
 
  • #15
'Twas meant generically.
 
  • #16
Sorry to dig up this old thread, but could someone recommend a numerical methods book for me to look at? I've got a far better understanding of floating point numbers now, but am getting a little bit stuck with calculating the error between them and a given value, x.
 
  • #17
Floating point numbers are defined on a grid. In other words, they have finite precision, and if a calculation falls between two floating point numbers, there will be roundoff error. Since the smallest distance between two floats is machine epsilon, the maximum value of the roundoff error (in matlab) is eps/2, or about 1.1102e-16 in double precision. Here is an example in matlab:

Code:
>> A = 0.3 + 0.3 + 0.3

A =

    0.9000

>> abs(A - 0.9) == eps/2

ans =

     1

As mentioned in a previous post, this is why you don't compare them directly for equality, but rather to a tolerance.
 
Last edited:
  • #18
kreil said:
Floating point numbers are defined on a grid. In other words, they have finite precision, and if a calculation falls between two floating point numbers, there will be roundoff error. Since the smallest distance between two floats is machine epsilon, the maximum value of the roundoff error (in matlab) is eps/2, or about 1.1102e-16 in double precision. Here is an example in matlab:

Code:
>> A = 0.3 + 0.3 + 0.3

A =

    0.9000

>> abs(A - 0.9) == eps/2

ans =

     1

As mentioned in a previous post, this is why you don't compare them directly for equality, but rather to a tolerance.
Thanks for that! However, it's not so much the concept of the round off error that I'm struggling with, more so it's calculations associated with it. I've actually posted the specific problem that I've struggled with in the homework and course work section and it'd be great if you could have a look as it'd probably give you a better understanding of what I'm struggling with. It's a worked example to do with finding the floating point representation of 0.2 and then the error between the two values.
 
  • #19
Also, could someone let me know if what I did above is ok? I'm not sure making reference to another thread is allowed or not.
 

Similar threads

  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
2
Views
3K
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
9
Views
2K
Replies
14
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
2
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K