
August 16th, 2013, 01:11 AM
#1
Function Reliabilty
Just a quick question. in and there is an function.
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.

August 16th, 2013, 02:05 AM
#2
Re: Function Reliabilty
Originally Posted by rockx
Just a quick question. in and there is an function.
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

August 16th, 2013, 11:46 PM
#3
Re: Function Reliabilty
It did not really answer my question

August 17th, 2013, 12:08 AM
#4
Re: Function Reliabilty
Originally Posted by rockx
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"?
is the function constraint to any bounds,
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.
Regards,
Paul McKenzie
Last edited by Paul McKenzie; August 17th, 2013 at 12:12 AM.

August 17th, 2013, 01:01 AM
#5
Re: Function Reliabilty
what i was trying to ask was that. lets consider the size of all positive integers only. say if we get a 2550 digit integer, would this function be able to operate wtih precisiion??

August 17th, 2013, 02:53 AM
#6
Re: Function Reliabilty
Originally Posted by rockx
lets consider the size of all positive integers only. say if we get a 2550 digit integer
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.
So, if you need to work with "a 2550 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.

August 17th, 2013, 05:31 AM
#7
Re: Function Reliabilty
Originally Posted by rockx
what i was trying to ask was that. lets consider the size of all positive integers only. say if we get a 2550 digit integer,
What data type gives you a 50 digit integer?
Regards,
Paul McKenzie

August 19th, 2013, 04:15 AM
#8
Re: Function Reliabilty
Originally Posted by rockx
what i was trying to ask was that. lets consider the size of all positive integers only. say if we get a 2550 digit integer, would this function be able to operate wtih precisiion??
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/
Last edited by zizz; August 19th, 2013 at 09:49 AM.

August 20th, 2013, 11:51 AM
#9
Re: Function Reliabilty
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.
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
OnDemand Webinars (sponsored)
