Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the inverse of std::numeric_limits::infinity() zero?

Tags:

Is there anything in the C++ standard (or the IEEE 754 floating-point standard) that guarantees that 1./std::numeric_limits<double>::infinity() is zero (or at least a small number)?

like image 852
davidhigh Avatar asked Aug 25 '18 09:08

davidhigh


People also ask

Does C++ have infinity?

The C++ infinity is written as “INF” and it accrues in the outcome of dividing a positive numeric value by a null value or calculating a numeric value that is greater than the larger number of our system that can be represented in 64 bits.


1 Answers

Any finite number divided by infinity results in zero under IEEE 754 (and therefore the same in most typical C++ implementations).

If the sign of the of numerator and denominator differ, the result will be negative zero, which is equal to zero.

like image 112
John Zwinck Avatar answered Nov 02 '22 05:11

John Zwinck