trying to figure out if number is negative
-
Try Dim d As Double = Math.Sqrt(number) Catch ex As Exception 'do stuff End Try
-
Try Dim d As Double = Math.Sqrt(number) Catch ex As Exception 'do stuff End Try
-
Try Dim d As Double = Math.Sqrt(number) Catch ex As Exception 'do stuff End Try
It's almost like this one I saw a long time ago:
if (abs(num)!=num) ...
(this is a real one...)
-
It's almost like this one I saw a long time ago:
if (abs(num)!=num) ...
(this is a real one...)
jkruza wrote:
(this is a real one...)
lol, i didnt make this up :)
-
jkruza wrote:
(this is a real one...)
lol, i didnt make this up :)
Yeah, I believe you. But it's so stupid, it's really hard to believe it's real. ;)
-
Yeah, I believe you. But it's so stupid, it's really hard to believe it's real. ;)
true that :-D
-
Try Dim d As Double = Math.Sqrt(number) Catch ex As Exception 'do stuff End Try
-
Try Dim d As Double = Math.Sqrt(number) Catch ex As Exception 'do stuff End Try
In the original BASIC, the absolute value would be used, so no error.
-
Try Dim d As Double = Math.Sqrt(number) Catch ex As Exception 'do stuff End Try
I will never complain about our code base again. OK - that was a lie, but I'm tempted.
CCC solved so far: 2 (including a Hard One!)
-
Try Dim d As Double = Math.Sqrt(number) Catch ex As Exception 'do stuff End Try
I don't think this code is doing what you think: it is not testing whether number is negative. No exception will be thrown because Math.Sqrt(n) returns NaN if n is negative. This is a valid Double value, and the code will drop out of the Try-Catch block without executing the line you have labelled 'do stuff. The only way this will get an exception is if the variable number is a String such as "XYZ". Math.Sqrt will cast a string such as "16" to a Double then take the square root of that, so as long as the String represents a numeric value it will work. Even "-16" will work because this will return NaN. But something such as "XYZ" will fail with an exception because this cannot be converted to a number and you will get an error. Having said that, there are better ways to check whether a String is numeric.
-
It's almost like this one I saw a long time ago:
if (abs(num)!=num) ...
(this is a real one...)
jkruza wrote:
(this is a real one
As opposed to an imaginary 1?
Visual Studio is an excellent GUIIDE.