Showing posts with label symbol. Show all posts
Showing posts with label symbol. Show all posts

Friday, March 23, 2012

POWER function

Hello,

I'm trying to follow a specification here:

W1 = (W0^0.333 + G * D/1000)^3 (the ^ symbol means 'to the power')

In my stored procedure I have used the following test data with unexpected results. Can anyone tell me if I'm using POWER properly?

@.Value = POWER(((POWER(150,(1/3))+ 2)* 10/1000),3)

Thanks

I think you are adding parentheses that are forcing a different order of arguments than the original. Here is what the original equation looks like with parentheses:

W1 = ( W0^(1/3) + ( G * D/1000) )^3

Your equation is written like this:

Val = ( (150^(1/3) + 2) * 10/1000 ) ^3|||Thanks Darrell, you're right about the parentheses. However, even with the correction and replacing '1/3' with 0.3333 (which makes a difference) - the results are still out - we expect the @.Value to be 150+ and it's only 125+. But you think the nested POWER function is OK? Or should I do this in 2 seperate statements?|||

Do you have to multiply G with D before dividing it by 1000? Maybe you miss a parenthesis with G*D.

W1 = ( W0^(1/3) + ((G * D)/1000) )^3

|||

Thanks, but tried that with no improvement. I've read elsewhere that "SQL server does not have a datatype for fractions and instead uses an approximate datatype such as float, where rounding will occur. Float has a maximum precision of 15 digits." Does this mean that trying to get a cube root with POWER is indeterminate? Has anyone by any chance written a function for getting cube roots? At the moment POWER is giving me 5 as a cube root of 150 - which is way out.

set

@.value=POWER(150,1.00/3.00)|||

Here are the relevant links and by Microsoft docs there is no indication the POWER function in SQL Server is none deterministic and yes it is FLOAT dependent. The links below will take you in the right direction. Hope this helps.


http://msdn2.microsoft.com/en-us/library/ms173773.aspx
http://msdn2.microsoft.com/en-us/library/ms174276.aspx
http://msdn2.microsoft.com/en-us/library/ms177516.aspx

|||

Caddre,

I'm having a 'duh' moment! Thanks for that- making the value being acted on convertible to float (150.00 instead of 150) gave the result we were looking for.

|||

ashaig:

Caddre,

I'm having a 'duh' moment! Thanks for that- making the value being acted on convertible to float (150.00 instead of 150) gave the result we were looking for.

I am glad I could help and you are not alone most people don't know that most are FLOAT dependent.

|||
Try this one, you can always change the precision to max.
POWER(CONVERT(float, 150), 0.333)