• Sorin Petcu (8/8/2008)


    mtassin (8/7/2008)


    Sorin Petcu (8/7/2008)


    Allof you, you have had wrong! I know from school, and everybody knows, that sqrt function did not support negative numbers (except complex numbers). But with this in your mind, you will be wrong in computers world. You should be guided by documentation of language. And this documentation is clear enough: sqrt supports negative float numbers. I know, you will say about ansi sql and other stuff like superior programming languages. But this issue is obviously clear.

    No... because SQRT returns a float.

    AND THE FLOAT DATATYPE DOES NOT SUPPORT COMPLEX/IMAGINARY NUMBERS.

    Hence SQRT cannot receive a negative number as an input and a domain error will occur because the result of the SQRT(-1) or SQRT(-.01) is outside of the domain of a FLOAT datatype.

    Again, other guy who make wrong suppositions. Theoretical, from math point of view, "SQRT cannot receive a negative number as an input", but here, we are talking about computer universe. Please, lay down the theory and read carrefully the documentation (BOL). On the other side, FLOAT has negative values, also.

    This is nothing to do with theory. Read Books Online about the float data type and tell me where it supports complex numbers. The return data type of SQRT is a float, a float data type cannot contain an imaginary or a complex number.

    The Square Root of -1 is i, which is an imaginary/complex number. It cannot be returned as a float data type because it is out of the domain of the float data type.

    It's right there in BOL.

    Books Online

    Returns the square root of the given expression.

    Syntax

    SQRT ( float_expression )

    Arguments

    float_expression

    An expression whose type can be implicitly converted to float.

    Return Value

    float

    And here is the BOL entry for the float data type.

    Approximate-number data types for use with floating point numeric data. Floating point data is approximate; therefore, not all values in the data type range can be represented exactly.

    Note:

    The SQL-92 synonym for real is float(24).

    Data type Range Storage

    float

    - 1.79E+308 to -2.23E-308, 0 and 2.23E-308 to 1.79E+308

    Depends on the value of n

    real

    - 3.40E + 38 to -1.18E - 38, 0 and 1.18E - 38 to 3.40E + 38

    4 Bytes

    Transact-SQL Syntax Conventions

    Where is i listed as an allowed value for a float data type? If the SQRT function returns a float value, the return value has to be within the allowed values for it. The value of SQRT(-1) is outside of the allowed returnable values for the function.

    This isn't theory... this is fact.

    As a much simpler approach, take a calculator and try to take the SQRT of -1... if you have a really neato calculator you'll get a complex number back, if you don't you'll get an error.

    http://en.wikipedia.org/wiki/Imaginary_number



    --Mark Tassin
    MCITP - SQL Server DBA
    Proud member of the Anti-RBAR alliance.
    For help with Performance click this link[/url]
    For tips on how to post your problems[/url]