Real number floating point error

Grindelwald

New member
Joined
Jun 3, 2020
Messages
1
I am not sure if I write in the correct section.

So the issue is the question: How to know that real value of a number is without error within floating point number?
For example:
0.2
0.3
0.4
0.5

How can I know that these real numbers can be presented as floating point numbers in programming without error. I don't know if my question is well written.
 
I am not sure if I write in the correct section.

So the issue is the question: How to know that real value of a number is without error within floating point number?
For example:
0.2
0.3
0.4
0.5

How can I know that these real numbers can be presented as floating point numbers in programming without error. I don't know if my question is well written.
What level of error is your concern? 10-8 , 10-16?
 
To check if an exact representation is possible, I guess you can try to produce the mantissa as a sum like this:-

0.375 = 2^-2 + 2^-3 therefore exact
0.1 = 2^-4 + 2^-5 + 2^-8 + 2^-9 + 2^-12 + 2^-13 + 2^-16 + 2^-17 + 2^-20 +2^-21 +... an infinite sum, therefore can't be exactly respresented

As Subhotosh points out, floats and doubles are long enough that the error will be small.
 
If the number can be written as a fraction whose denominator is a power of 2 (and if both numerator and denominator are within some range, if you want to go to extremes), then it should be able to be expressed exactly in floating point (on a base-2 machine).

But if you want exact values, you don't use floating point.
 
There's a problem with my post#3:- it doesn't prove that there's an infinite, recurring, sum. If you use binary long division then this can be proved. This website(click and scroll down a little) shows the process for the number 0.1. Also, don't forget that the mantissa may have a limited size (width) which would further limit the set of numbers that can be represented exactly.
 
Top