Guaranteed precision of sqrt function in C/C++

前端 未结 2 1025
误落风尘
误落风尘 2021-01-05 16:44

Everyone knows sqrt function from math.h/cmath in C/C++ - it returns square root of its argument. Of course, it has to do it with some

2条回答
  •  無奈伤痛
    2021-01-05 17:07

    This question was already answered here as Chris Dodd noticed in the comments section. In short: it's not guaranteed by C++ standard, but IEEE-754 standard guarantees me that the result will be as close to the 'real result' as possible, i.e. error will be less than or equal to 1/2 unit-in-the-last-place. In particular, if the result can be precisely stored, it should be.

提交回复
热议问题