Guaranteed precision of sqrt function in C/C++

yeputons

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 error, because not every number can be stored precisely. But am I guaranteed that the result has some precision? For example, 'it's the best approximation of square root that can be represented in the floating point type usedorif you calculate square of the result, it will be as close to initial argument as possible using the floating point type given`?

Does C/C++ standard have something about it?

nwellnhof

For C99, there are no specific requirements. But most implementations try to support Annex F: IEC 60559 floating-point arithmetic as good as possible. It says:

An implementation that defines __STDC_IEC_559__ shall conform to the specifications in this annex.

And:

The sqrt functions in <math.h> provide the IEC 60559 square root operation.

IEC 60559 (equivalent to IEEE 754) says about basic operations like sqrt:

Except for binary <-> decimal conversion, each of the operations shall be performed as if it first produced an intermediate result correct to infinite precision and with unbounded range, and then coerced this intermediate result to fit in the destination's format.

The final step consists of rounding according to several rounding modes but the result must always be the closest representable value in the target precision.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Guaranteed precision of sqrt function in C/C++

From Dev

C++ sqrt function precision for full squares

From Dev

Applying sqrt function on a column

From Dev

Sqrt function invokes an error

From Dev

Do floats, doubles, and long doubles have a guaranteed minimum precision?

From Dev

Are function arguments guaranteed to pass on the stack?

From Dev

Lua Sqrt function inaccurate result

From Dev

Double precision in FORMAT function

From Dev

Double precision in FORMAT function

From Dev

LOCALTIMESTAMP function with precision parameter

From Dev

function signature specialization <Arg[0] = Owned To Guaranteed>

From Dev

Is send() function in TCP Guaranteed to arrive in order?

From Dev

function signature specialization <Arg[0] = Owned To Guaranteed>

From Dev

Is the order in which function arguments are resolved guaranteed?

From Dev

Decidable sqrt function in Z3

From Dev

Finding square root without using sqrt function?

From Dev

BigInteger Sqrt Function isn't converging

From Dev

Trying to timeit my sqrt function in Python

From Dev

Applying sqrt function to multiple lists in clisp

From Dev

Finding square root without using sqrt function?

From Dev

domain_error in c in sqrt() function

From Dev

NSExpression using sqrt: function results in NSInvalidArgumentException

From Dev

Hypotenuse using function & Math.sqrt() javascript

From Dev

Performance of sqrt function on AArch64

From Dev

Precision issue of integrate function in R

From Dev

Precision of acos function in c++

From Dev

Calling function with configurable real precision

From Dev

Precision of calculations after exponent function

From Dev

Precision of acos function in c++

Related Related

HotTag

Archive