Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12345»»»

Exponent Engima Expand / Collapse
Author
Message
Posted Thursday, August 07, 2008 7:45 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Friday, March 28, 2014 2:25 PM
Points: 9,902, Visits: 9,479
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 :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)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #548294
Posted Thursday, August 07, 2008 7:50 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, April 15, 2014 12:05 PM
Points: 3,569, Visits: 72,411
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+308
so, 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 DBA
Proud member of the Anti-RBAR alliance.
For help with Performance click this link
For tips on how to post your problems
Post #548297
Posted Thursday, August 07, 2008 7:52 AM


SSChasing Mays

SSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing MaysSSChasing Mays

Group: General Forum Members
Last Login: Tuesday, February 04, 2014 8:18 AM
Points: 620, Visits: 273
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 :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.
Post #548301
Posted Thursday, August 07, 2008 7:58 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Friday, March 28, 2014 2:25 PM
Points: 9,902, Visits: 9,479
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+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 Real-based languages (LOG() has similar restricitons).


-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #548308
Posted Thursday, August 07, 2008 8:01 AM


Hall of Fame

Hall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of FameHall of Fame

Group: General Forum Members
Last Login: Tuesday, April 15, 2014 12:05 PM
Points: 3,569, Visits: 72,411
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+308

i 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 DBA
Proud member of the Anti-RBAR alliance.
For help with Performance click this link
For tips on how to post your problems
Post #548311
Posted Thursday, August 07, 2008 8:23 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, March 24, 2014 9:17 AM
Points: 164, Visits: 195
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 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.



Post #548326
Posted Thursday, August 07, 2008 8:38 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Friday, March 28, 2014 2:25 PM
Points: 9,902, Visits: 9,479
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 correct


Yikes! 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: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #548338
Posted Thursday, August 07, 2008 8:49 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Yesterday @ 1:13 PM
Points: 1,343, Visits: 7,166
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
Post #548348
Posted Thursday, August 07, 2008 9:04 AM


SSCrazy Eights

SSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy EightsSSCrazy Eights

Group: General Forum Members
Last Login: Friday, March 28, 2014 2:25 PM
Points: 9,902, Visits: 9,479
Almost:
DECLARE         @a BIGINT
, @b BIGINT
SET @a = 16
SELECT SQRT(POWER(@a,@a) - 17)

and this will give an overflow error.


-- RBarryYoung, (302)375-0451 blog: MovingSQL.com, Twitter: @RBarryYoung
Proactive Performance Solutions, Inc.
"Performance is our middle name."
Post #548371
Posted Thursday, August 07, 2008 9:18 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Monday, March 10, 2014 5:44 PM
Points: 2,225, Visits: 1,258
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!
Post #548387
« Prev Topic | Next Topic »

Add to briefcase ««12345»»»

Permissions Expand / Collapse