Power

  • Guys think deeper, that question is not "what is 2^31" but "why does this fail"

    Its about data type limitations. The correct answer is not given in the error message

    the floating point answer is i.e. 2.0^31 notice the .00000 on its end.

    It fails because it overflows the default/assumed type of int.

    THINK!THINKTHINK! then think again.

    strive to understand before you strive to be understood!

    Hiding under a desk from SSIS Implemenation Work :crazy:

  • Yeah, I got your point. It is about data type limitation. The question is well written...

  • Just Cast the numeric expression value as float will give the value of power(2,31)

    select POWER (CAST(2 AS FLOAT),31)

  • It is a good question.

    To work around we can cast as float or bigint; but the nub of the answer is in realising that it is the internal datatype of an undeclared 2 (ie an int) that is in question.

    If Sql 2005 had all numbers internally as bigint it would cost memory, if it cast based on a guessed intention it would be slated to high heaven!

    So an undeclared 2 is an int and a power operation on an int returns an int. Wishing that a power operation on an int would sometimes return an int and sometimes a bigint (what about a tinyint?) seems odd.

    All seems reasonable to me.

  • answer results in an error message of Arithmetic over flow

    +1 🙂

    _______________________________________________________________
    To get quick answer follow this link:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

Viewing 5 posts - 16 through 19 (of 19 total)

You must be logged in to reply to this topic. Login to reply