August 8, 2008 at 3:03 pm
Sorin Petcu (8/8/2008)
I think you don't understand or you don't want to understand.
Let me see: how it is represented the number -5 in computer? as binar form as 1111111111111111111111111111111111111111111111111111111111111011 and this number would be reconverted as 18446744073709551611 in decimal format.
So, SQRT(-5) would be what? guess what:
select SQRT(18446744073709551611) = 4294967296
So we are talking only about numbers and not math theory. You said forth and forth about complex numbers. Wrong! Why you want to receive a complex number from a function built in a programming language? Why you want all the time that float number can't be asimilated as complex number? It is nothing to do with complex numbers in a programming language or an engine like sql server. Complex numbers are in math theory. So wake up!
Sorry wrong.
-5 in binary is what is below for a 64 bit integer (notice how it's 65 bits long).
1111111111111111111111111111111111111111111111111111111111111011 when converted to an unsigned integer is 18446744073709551611, when converted to a signed integer it's -5.
Just because you're using Calc to do the conversions... it doesn't apparently handle converting negative numbers to binary and back. Take -5 convert it to binary... convert it back... it should be
-5 again.
I'm sure you will agree that 18446744073709551611 is not equal to -5.
Do you understand how to actually convert binary to decimal?
http://en.wikipedia.org/wiki/Two's_complement
It's interesting that you've perhaps pointed out a bug in calc.exe though.. if you use excel and do a DEC2BIN of -5 you get 1111111011 and if you use BIN2DEC to convert it back you'll get the correct answer which is -5.
Here's an example in SQL
select convert(binary,-5)
select convert(int,0x0000000000000000000000000000000000000000000000000000FFFFFFFB)
select convert(int,convert(binary,-5))
August 10, 2008 at 2:17 am
no comment!!
August 19, 2008 at 4:46 pm
Good question. Makes a good differentiation between the bit Operator XOR and the Math function POWER.
August 19, 2008 at 8:32 pm
Thanks, Mohamed. I got the idea for this question because I keep making this mistake myself.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
August 20, 2008 at 10:22 am
mtassin (8/8/2008)
The Square Root of -1 is i, which is an imaginary/complex number. It cannot be returned as a float data type because it is out of the domain of the float data type.
Mark, your argument assumes that the reader knows that the result of passing a negative parameter to the function results in an answer that is out of range or of the wrong data type. For instance, if I typed SELECT SQRT(-23) and I got the error "a domain error occurred", how would I know that this is wasn't because I used an odd number rather than because I used a negative number? I totally agree with you that this behaviour is correct: I'm just saying that I think the range of permissible values should be documented in Books Online. Look at the documentation for the ASIN function, for how it should be done:
float_expression
Is an expression of the type float or of a type that can be implicitly converted to float, with a value from -1 through 1. Values outside this range return NULL and report a domain error.
By the way, I was fooled by the @b-2 thing, just like James. I read "negative" instead of "non-negative" and so I immediately discounted the correct answer!
John
April 7, 2010 at 10:29 am
Nice question. I think the math behind the question is revealing for the answer.
Good Job on this Barry (p.s. got it correct).
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
April 7, 2010 at 10:38 am
Nice job Jason. This is one tough question, and I know that I'm biased but it's really one of my favorite questions ever. (and I am really glad that the two mistakes that I made in it did not affect the correct answer, whew!) Even the discussion here has been great.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
April 7, 2010 at 10:42 am
I too liked the discussion as I reread it today.
Involve math, SQL, and a good discussion and you have a good QOD!!:cool:
Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw[/url]
Learn Extended Events
Viewing 8 posts - 46 through 52 (of 52 total)
You must be logged in to reply to this topic. Login to reply