

SSCrazy Eights
Group: General Forum Members
Last Login: Wednesday, October 15, 2014 9:14 AM
Points: 9,294,
Visits: 9,483


skyline666 (8/7/2008)
Got it right . Out of interest, what was the "@b bigint" for, to try and confuse people with the @b17 answer :D?
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)3750451 blog: MovingSQL.com, Twitter: @RBarryYoung Proactive Performance Solutions, Inc. "Performance is our middle name."




Hall of Fame
Group: General Forum Members
Last Login: Tuesday, September 30, 2014 7:42 AM
Points: 3,688,
Visits: 72,435





SSChasing Mays
Group: General Forum Members
Last Login: Friday, September 19, 2014 12:29 AM
Points: 622,
Visits: 287


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 @b17 answer :D? 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.




SSCrazy Eights
Group: General Forum Members
Last Login: Wednesday, October 15, 2014 9:14 AM
Points: 9,294,
Visits: 9,483


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.23E308, 0 and 2.23E308 to 1.79E+308 so, 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 Realbased languages (LOG() has similar restricitons).
 RBarryYoung, (302)3750451 blog: MovingSQL.com, Twitter: @RBarryYoung Proactive Performance Solutions, Inc. "Performance is our middle name."




Hall of Fame
Group: General Forum Members
Last Login: Tuesday, September 30, 2014 7:42 AM
Points: 3,688,
Visits: 72,435


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.23E308, 0 and 2.23E308 to 1.79E+308
i is not in that range. it's complex and falls outside of the nonimaginary 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 DBA Proud member of the AntiRBAR alliance. For help with Performance click this link For tips on how to post your problems




SSCEnthusiastic
Group: General Forum Members
Last Login: Friday, October 10, 2014 3:11 PM
Points: 166,
Visits: 200


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 @b17? Answer B cannot be correct 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.
Still, a nice question. BOL should be updated.




SSCrazy Eights
Group: General Forum Members
Last Login: Wednesday, October 15, 2014 9:14 AM
Points: 9,294,
Visits: 9,483


Festeron (8/7/2008) There are problems with the question, though.
Why is @b declared and never used? Where is @b17? Answer B cannot be correct
Yikes! You are right, "@b" shouldn't be in there and Answer B should read "@a17...". 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)3750451 blog: MovingSQL.com, Twitter: @RBarryYoung Proactive Performance Solutions, Inc. "Performance is our middle name."




Ten Centuries
Group: General Forum Members
Last Login: Yesterday @ 2:50 PM
Points: 1,343,
Visits: 7,184


so, would this be the proper expression if it were really an exponential question?
DECLARE @a BIGINT , @b BIGINT SET @a = 16 SELECT SQRT(POWER(@a,@a  17))
bc
bc




SSCrazy Eights
Group: General Forum Members
Last Login: Wednesday, October 15, 2014 9:14 AM
Points: 9,294,
Visits: 9,483





SSCrazy
Group: General Forum Members
Last Login: Yesterday @ 11:01 AM
Points: 2,401,
Visits: 1,485


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? :)
Thanks
Miles...
Not all gray hairs are Dinosaurs!



