# when float number is above 0.5 and when is below 0.5?

Dear Collegues,

i have read a lot of papers and nowhere I can find any solution or solutions to verified when float number is above 0.5 and when below 0.5

example:

number 0.2 -> below 0.5
number 0.55 -> above 0.5


what I have : to verified in algorithm : number 1.345 , and I;d like to know how to check that is more than 1.5 or les than 1.5? I cant check by if 1.345 > 1.5 then print("above") :)

it is any solution algoritms how compute calculate it?

Now i will describe the problem: I have a number which I divide by 2: for example

number =  1699
1 849.5
2 424.75
3 212.375
4 106.1875
5 53.09375
6 26.546875
7 13.2734375
8 6.63671875
9 3.318359375
10 1.6591796875


the last line - "10" there is 1.6591796875 -> it tranlated -> 1 * 2^10 + 2^10 * 0.6591796875 = 1699

and know -> I only know that there is value x which is 1.6591796875 , but I don't know this exactly number , but only know there is 1 plus rest. so I can substract from 1.6591796875 - 1 = to get rest : 0.6591796875 -> and here how to check it is more than 0.5 or less than 0.5?

edit retag close merge delete

Sort by » oldest newest most voted

Short anwser :

sage: a = 1699./2^10 - 1
sage: a > 0.5
True


As 0.6591796875 is very far from 0.5, there is no issue here. But if the number are closer to eachother, and could be equal, you have to use more robust methods than raw floating-point nunbers. The right choice of numbers depends on your application, so you should provide more details.

more