Floating-point division imperfection

I know that the floating-point is not perfect, either it's float or double, but does it mean that, when I divide one floating-point number by another and the the dividend is divisible by the divider without a reminder (like 10000.0 is divisible by 10.0), is it possible that I get a number with .99999999... at the end which is only smaller than the correct result by a tiny fraction. Can such thing happen with floating-points?

I need to know because I need to apply floor function after the division and it would make a huge difference if floating-point divisions are really that imperfect.

Answers


does it mean that, when I divide one floating-point number by another and the the dividend is divisible by the divider without a reminder (like 10000.0 is divisible by 10.0), it's possible that I get a number with .99999999... at the end

No. IEEE 754 division is correctly rounded. If there is a representable floating-point number (1000 in your example) for the result, this is the result you will get for the division.

What can happen is that you do not divide the numbers you are thinking, because you wrote 0.1 and you think that this represents the mathematical value 0.1. In this case the end result can be surprising, but this is no fault of the floating-point division.

As long that you know that you are dividing the numbers you mean, if the mathematical result of the division is, say, an integer below 224, then the result of the floating-point division will be that integer.


Need Your Help

sed -i option is not working on solaris

unix sed solaris

I am using sed to replace a line with NULL in a file. The command i used is

javascript/jquery grab part of URL

javascript jquery regex parsing url

I have for example, https://www.example.com/test1/something?asd=1. Of this example URL I need to grab everything up until and included /test1/. So I would set var url = https://www.example.com/test...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.