Just a quick question. inandCode:<cmath>
there is anCode:<math.h>
function.Code:sqrt
I just wish to know how reliable would it be. What i am asking is that, is the function constraint to any bounds, or is it universal.
Printable View
Just a quick question. inandCode:<cmath>
there is anCode:<math.h>
function.Code:sqrt
I just wish to know how reliable would it be. What i am asking is that, is the function constraint to any bounds, or is it universal.
http://www.cplusplus.com/reference/cmath/sqrt/
Regards,
Paul McKenzie
It did not really answer my question
Because the question you asked was so vague, the only thing to do is give you the link to the documentation to the function. The description of sqrt() at the link tells you what it does, what it returns, and what happens if the argument is not valid. What else do you need to know? What do you mean by "reliable" or "universal"?
The function takes a double or float. Whatever the limits of a double or float are, that's what the constraints are. And again, if the number is deemed negative or invalid, then the link tells you what is returned. Everything you need to know is at that link.Quote:
is the function constraint to any bounds,
Regards,
Paul McKenzie
what i was trying to ask was that. lets consider the size of all positive integers only. say if we get a 25-50 digit integer, would this function be able to operate wtih precisiion??
How are you going to get that? The unsigned long long type in C99, later incorporated into C++11, is guaranteed to provide at least a range of [0, 18446744073709551615], but I find it improbable that you will get a significantly larger range at this point of time. Hence, that means a maximum of 20 digits in decimal representation.Quote:
Originally Posted by rockx
So, if you need to work with "a 25-50 digit integer", you might use an arbitrary precision integer library, which may provide a square root function that you can use with the integer type(s) provided.
Since the sqrt function you're referring to belongs to the C++ standard library you can expect it to work within the bounds of all mathematically relevant types that belong to standard C++, like say float and double.
The C++ standard is carefully matched and balanced to avoid surprises but this also implies that no single feature, say sqrt, will very much exceed this core body of bounds. If you want that you need to look elsewhere. In this case say here,
http://gmplib.org/
it'll work with full precision for all possible ranges of float and double in so far as it can give a proper result.
giving it bogus input (nan's, infinity, negatives) will give the defined outputs.
note that this says nothing about performance. Performance may or may not suffer for certain values depending on the algorithm used to calculate the result. typically for sqrt this isn't much of an issue as it's a fairly linearly solvable equation.