## Exponent Engima

 Author Message RBarryYoung SSC-Dedicated Group: General Forum Members Points: 35330 Visits: 9518 skyline666 (8/7/2008)Got it right . Out of interest, what was the "@b bigint" for, to try and confuse people with the @b-17 answer ?Actually, if was to give versimilitude to the first answer: "16^16 = 2^64 which is out of bigint's range". I figured that folks would see think "Aha! BigInt DOES have 64 bits, but half of the range is negative, so it can actually only go up to 2**63!". And so, thinking that they had detected my trick would go with that. -- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoungProactive Performance Solutions, Inc. "Performance is our middle name." mtassin SSCertifiable Group: General Forum Members Points: 7308 Visits: 72521 Sorin Petcu (8/7/2008)what a glitch!!in BOL it says that SQRT ( float_expression )and float could be, as definition of float, float - 1.79E+308 to -2.23E-308, 0 and 2.23E-308 to 1.79E+308so, where it says that the argument of SQRT should be not negative!??? Becaust SQRT(-1) = i ?Somehow I doubt we'll see SQL handle imaginary numbers any time soon. --Mark Tassin MCITP - SQL Server DBAProud member of the Anti-RBAR alliance.For help with Performance click this linkFor tips on how to post your problems Sorin Petcu Ten Centuries Group: General Forum Members Points: 1368 Visits: 367 rbarryyoung (8/7/2008)skyline666 (8/7/2008)Got it right . Out of interest, what was the "@b bigint" for, to try and confuse people with the @b-17 answer ?Actually, if was to give versimilitude to the first answer: "16^16 = 2^64 which is out of bigint's range". I figured that folks would see think "Aha! BigInt DOES have 64 bits, but half of the range is negative, so it can actually only go up to 2**63!". And so, thinking that they had detected my trick would go with that.Actually, it was not any trick here. Because someone would select 16^16 which returns 0. And this means that the input for sqrt will be a negative number. According to BOL, sqrt should receive negative numbers also (float). In Theory, theory and practice are the same...In practice, they are not. RBarryYoung SSC-Dedicated Group: General Forum Members Points: 35330 Visits: 9518 Sorin Petcu (8/7/2008)what a glitch!!in BOL it says that SQRT ( float_expression )and float could be, as definition of float, float - 1.79E+308 to -2.23E-308, 0 and 2.23E-308 to 1.79E+308so, where it says that the argument of SQRT should be not negative!???Right. The datatype float is the valid input type for SQRT(), but not all possible values are allowed as input. This is because SQRT(-1) is technically either i or -i, both of which are unexpressable in any native numeric type in SQL. That makes SQL's math "Real" instead of "Complex" and in all Real Math environments, negative numbers are outside of the domain of accpeted input values for SQRT().Technically you are right, this is not documented in BOL. However, it is documented in the ANSI SQL specs and well understood as a natural limitation of SQRT() in all Real-based languages (LOG() has similar restricitons). -- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoungProactive Performance Solutions, Inc. "Performance is our middle name." mtassin SSCertifiable Group: General Forum Members Points: 7308 Visits: 72521 Sorin Petcu (8/7/2008)[quote]rbarryyoung (8/7/2008)Actually, it was not any trick here. Because someone would select 16^16 which returns 0. And this means that the input for sqrt will be a negative number. According to BOL, sqrt should receive negative numbers also (float).Except that it has to return a float. And the float data type is defined as a number in the range - 1.79E+308 to -2.23E-308, 0 and 2.23E-308 to 1.79E+308i is not in that range. it's complex and falls outside of the non-imaginary number range. Hence SQRT which must return a float will throw a domain error.Heck I got it wrong... because I remembered from the days of Pascal I think using ^ as the exponent operator... but once I learned about it being the XOR operator I could accept my wrongness... this is a good tricky question! --Mark Tassin MCITP - SQL Server DBAProud member of the Anti-RBAR alliance.For help with Performance click this linkFor tips on how to post your problems Festeron Old Hand Group: General Forum Members Points: 315 Visits: 230 I have to admit, I was totally distracted by the caret, and didn't even consider bitwise ops. Nice distraction.There are problems with the question, though.Why is @b declared and never used? Where is @b-17? Answer B cannot be correctAnswer A is not just a distraction, it's wrong to include the "=2^64" because you are deliberately misleading us. A much better A would have been "16^16 is out of range for the bigint datatype' which [in hindsight] is clearly not true.Still, a nice question. BOL should be updated. RBarryYoung SSC-Dedicated Group: General Forum Members Points: 35330 Visits: 9518 Festeron (8/7/2008)There are problems with the question, though.Why is @b declared and never used? Where is @b-17? Answer B cannot be correctYikes! You are right, "@b" shouldn't be in there and Answer B should read "@a-17...". Fortunately, it doesn't change the correct answer.Answer A is not just a distraction, it's wrong to include the "=2^64" because you are deliberately misleading us. A much better A would have been "16^16 is out of range for the bigint datatype' which [in hindsight] is clearly not true.Yes it is trying to mislead you by playing on the mistaken assumption that "^" is the exponent operator, just as the Title is. However, that is the whole point of the Question: it is a mistaken assumption and if you do not figure that out, you will come to the wrong conclusion. And after all, (A) is an incorrect answer, whether it is incorrect for one reason or two (and both the same reason at that) doesn't really matter. -- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoungProactive Performance Solutions, Inc. "Performance is our middle name." bc_ SSCommitted Group: General Forum Members Points: 1680 Visits: 7333 so, would this be the proper expression if it were really an exponential question?DECLARE @a BIGINT , @b BIGINTSET @a = 16SELECT SQRT(POWER(@a,@a - 17))bc bc RBarryYoung SSC-Dedicated Group: General Forum Members Points: 35330 Visits: 9518 Almost:`DECLARE @a BIGINT , @b BIGINTSET @a = 16SELECT SQRT(POWER(@a,@a) - 17)`and this will give an overflow error. -- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoungProactive Performance Solutions, Inc. "Performance is our middle name." Miles Neale SSCarpal Tunnel Group: General Forum Members Points: 4248 Visits: 1695 No argument on the format, trick or the answer. After one of the earlier questions last week that was a slight bit tricky I looked real close and got it right.You got to be careful to be right. But that is the way business is isn't it? ThanksMiles... Not all gray hairs are Dinosaurs!

## Permissions

 You can't post new topics. You can't post topic replies. You can't post new polls. You can't post replies to polls. You can't edit your own topics. You can't delete your own topics. You can't edit other topics. You can't delete other topics. You can't edit your own posts. You can't edit other posts. You can't delete your own posts. You can't delete other posts. You can't post events. You can't edit your own events. You can't edit other events. You can't delete your own events. You can't delete other events. You can't send private messages. You can't send emails. You can read topics. You can't vote in polls. You can't upload attachments. You can download attachments. You can't post HTML code. You can't edit HTML code. You can't post IFCode. You can't post JavaScript. You can post emoticons. You can't post or upload images.

##### Select a forum
 SQL Server 2016      SQL Server 2016 - Administration      SQL Server 2016 - Development and T-SQL SQL Server 2014      Administration - SQL Server 2014      Development - SQL Server 2014 SQL Server 2012      SQL 2012 - General      SQL Server 2012 - T-SQL SQL Server vNext      SQL Server 14 - Administration      SQL Server 14 - Development SQL Server 2008      SQL Server 2008 - General      T-SQL (SS2K8)      June 2007 CTP      Working with Oracle      July CTP      SQL Server Newbies      Security (SS2K8)      SQL Server 2008 High Availability      SQL Server 2008 Administration      Data Corruption (SS2K8 / SS2K8 R2)      SQL Server 2008 Performance Tuning Cloud Computing      SQL Azure - Development      SQL Azure - Administration      Amazon AWS and other cloud vendors      General Cloud Computing Questions Reporting Services      Reporting Services      Reporting Services 2005 Administration      Reporting Services 2005 Development      Reporting Services 2008/R2 Administration      Reporting Services 2008 Development      SSRS 2012      SSRS 2014      SSRS 2016 Programming      Connecting      General      SMO/RMO/DMO      XML      Service Broker      Powershell      Testing      TFS/Data Dude/DBPro      SSDT      Continuous Integration, Deployment, and Delivery      R Services and R Language Data Warehousing      Integration Services      Strategies and Ideas      Analysis Services      Data Transformation Services (DTS)      Performance Point      Data Mining      PowerPivot      R language      Machine Learning Database Design      Disaster Recovery      Design Ideas and Questions      Relational Theory      Hardware      Virtualization SQLServerCentral.com      Anything that is NOT about SQL!      Contests!      Editorials      SQLServerCentral.com Announcements      SQLServerCentral.com Website Issues      Suggestions      Tag Issues with Content      Podcast Feedback      SQLServerCentral.com Test Forum      Articles Requested SQL Server 2005      Administering      Backups      Business Intelligence      CLR Integration and Programming.      Data Corruption      Development      Working with Oracle      SQL Server 2005 Compact Edition      SQL Server 2005 General Discussion      SQL Server 2005 Security      SQL Server 2005 Strategies      SS2K5 Replication      SQL Server Express      SQL Server 2005 Performance Tuning      SQL Server 2005 Integration Services      T-SQL (SS2K5)      SQL Server Newbies SQL Server 7,2000      Administration      Backups      Data Corruption      General      Globalization      In The Enterprise      Working with Oracle      Security      Strategies      SQL Server Newbies      Service Packs      SQL Server CE      Performance Tuning      Replication      Sarbanes-Oxley      T-SQL      SQL Server Agent SQL Server and other platforms      MySQL      Oracle      PostgreSQL      DB2      SQL Server and Sharepoint Older Versions of SQL (v6.5, v6.0, v4.2)      Older Versions of SQL (v6.5, v6.0, v4.2) Career      Certification      Employers and Employees      Events      Job Postings      Resumes and Job Hunters      Presentations and Speaking      Retired Members Testing Center      Question of the Day (QOD)      SQL Server Security Skills Microsoft Access      Microsoft Access Products and Books      Third Party Products         CA         Extreme Technologies.         Innovartis         Embarcadero         SQL Sentry         Sonasoft         SQLCentric         Golden Gate Software         Lumigent         Red Gate Software         Quest Software         ApexSQL         Idera      Discussions about Books         Discuss Programming Books          Discuss XML Books          Discuss T-SQL Books          Discuss Data Warehousing Books          Discuss DTS Books          Discuss SQL Server 7.0 Books         Discuss SQL Server 2000 Books Notification Services      Administration Article Discussions Future Versions      SQL 12