Function Reliabilty
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 9 of 9

Thread: Function Reliabilty

  1. #1
    Join Date
    May 2004
    Posts
    202

    Arrow Function Reliabilty

    Just a quick question. in
    Code:
    <cmath>
    and
    Code:
    <math.h>
    there is an
    Code:
    sqrt
    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.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,418

    Re: Function Reliabilty

    Quote Originally Posted by rockx View Post
    Just a quick question. in
    Code:
    <cmath>
    and
    Code:
    <math.h>
    there is an
    Code:
    sqrt
    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

  3. #3
    Join Date
    May 2004
    Posts
    202

    Re: Function Reliabilty

    It did not really answer my question

  4. #4
    Join Date
    Apr 1999
    Posts
    27,418

    Re: Function Reliabilty

    Quote Originally Posted by rockx View Post
    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 16th, 2013 at 11:12 PM.

  5. #5
    Join Date
    May 2004
    Posts
    202

    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 25-50 digit integer, would this function be able to operate wtih precisiion??

  6. #6
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,196

    Re: Function Reliabilty

    Quote Originally Posted by rockx
    lets consider the size of all positive integers only. say if we get a 25-50 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 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.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  7. #7
    Join Date
    Apr 1999
    Posts
    27,418

    Re: Function Reliabilty

    Quote Originally Posted by rockx View Post
    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,
    What data type gives you a 50 digit integer?

    Regards,

    Paul McKenzie

  8. #8
    Join Date
    Aug 2013
    Posts
    11

    Re: Function Reliabilty

    Quote Originally Posted by rockx View Post
    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??
    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 08:49 AM.

  9. #9
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,639

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center