Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute:

I am trying to do the following calculation:

DECLARE @X Decimal(18,6);
DECLARE @Y Decimal(20,16);

SET @X = 0.002700;
SET @Y = 0.0027770000000000;

SELECT 200 * ( POWER(@Y, ( -1 / ( 2 * @X ))) - 1 );

However this results in:

Msg 8115, Level 16, State 2, Line 7
Arithmetic overflow error converting expression to data type float.

I have tried casting to float but to no avail.

Any ideas what I am missing here?

share|improve this question
up vote 2 down vote accepted

A float data type can store a maximum value of about 1.79E+308, but the result of this expression is approximately 5.16E+475. See http://tinyurl.com/oy7deu8

share|improve this answer

May be there is a way to do this. You are trying to calculate @y power (-1/2*@x). This is equivalent to calculating e power (log(y)*(-1/2x)).

You could calculate it as

select 200 * POWER(2.718281828, log(@Y) * (-1/(2*@X)))

Note that LOG by default calculates the natural logarithm of the number. And e = 2.718281828

share|improve this answer
    
That didn't work either. I found that the value for @y was wrong. However the limitation of the tSQL POWER() function still stands. – Kamran Farzami Jul 24 at 18:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.