Recent PostsRecent Posts Popular TopicsPopular Topics
 Home Search Members Calendar Who's On

 Bug in POWER function? Rate Topic Display Mode Topic Options
Author
 Message
 Posted Tuesday, February 15, 2011 1:21 PM
 Forum Newbie Group: General Forum Members Last Login: Monday, December 22, 2014 12:50 PM Points: 6, Visits: 97
 I was just trying to load up the largest BIGINT, 9,223,372,036,854,775,807, by using the POWER function (2^63) - 1. When plugging in "2 raised to the 63," the returned value is 9,223,372,036,854,775,800 and not 9,223,372,036,854,775,808 as I would expect (prior subtracting 1 to get the largest allowed BIGINT). SELECT POWER(2., 63.) - 1.When obtaining the largest INT value by raising to the power of 31, I get the expected results. SELECT POWER(2., 31.) - 1.This a known issue?
Post #1064529
 Posted Tuesday, February 15, 2011 2:14 PM
 SSChampion Group: General Forum Members Last Login: Monday, August 29, 2016 1:09 PM Points: 13,999, Visits: 9,728
 It's probably a floating point issue. It looks like you're using floating point numbers (they have decimal places), instead of integers. Shouldn't affect whole-number calculations, but it may in this kind of case. - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETCProperty of The Thread"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
Post #1064569
 Posted Tuesday, February 15, 2011 4:08 PM
 SSC-Forever Group: General Forum Members Last Login: Today @ 2:41 PM Points: 42,081, Visits: 39,473
 POWER relies on a FLOAT conversion which, IIRC, has a maximum precision of 15 digits. Here's an article that demonstrates the problem for another function that does a FLOAT conversion...`http://www.sqlservercentral.com/articles/T-SQL/71565/` --Jeff Moden"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".First step towards the paradigm shift of writing Set Based code: Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column." Helpful Links:How to post code problemsHow to post performance problems
Post #1064616

 Permissions