Is it POWER function and FLOAT limitation ?

  • Hi,

    I am just wondering why

    SELECT POWER(2.718, -34.08)

    returns me 0.

    Tested it in Microsoft Excel

    =2.718^-34.08

    and it is returning me 1.58774E-15 which is approximate 15 decimal points.

    My table column defined as FLOAT which can take up to 54.

    Is it the limitation in the POWER function ?

    Thanks.

  • It is a limitation in Power.

    SELECT POWER(2,34)

    Produces

    Msg 232, Level 16, State 3, Line 1

    Arithmetic overflow error for type int, value = 17179869184.000000.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • Geez... found the solution myself.

    By default, POWER function will follow the data type from the first argument.

    http://technet.microsoft.com/en-us/library/ms174276.aspx

    By defining 2.718 as a FLOAT and use a variable to call the POWER function, it returns me the results I want.

  • davidku (4/2/2014)


    Geez... found the solution myself.

    By default, POWER function will follow the data type from the first argument.

    http://technet.microsoft.com/en-us/library/ms174276.aspx

    By defining 2.718 as a FLOAT and use a variable to call the POWER function, it returns me the results I want.

    Or you can just use the (nearly) exact value for e:

    SELECT POWER(EXP(1),-34.08);


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St

Viewing 4 posts - 1 through 3 (of 3 total)

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