@Jack
You're right. I didn't check SGN(0) in the code I posted for zero. Oops, my bad. So it does 3 things, but...
Hurry Steve, stomp out that flaming bag of SGN()
But wait a sec... Instead of...
I'd do...
A bit less code that way, or a slight bit more to use SELECT CASE for evaluation as:
SELECT CASE. 1, 0 , -1 vs IS > 0 , 0, IS < 0. Not much of a difference.
It is good as a reference point in your code, to see where you need such comparisons on a search. Jut type search SGN.
I vaguely remember using this statement maybe once decades ago but can't recall what for.
Now Steve's second example is a good one, as you'd get bit in the ASCII doing it this way...
COLOR Kolors((number / ABS(number)))
Division by zero is a killer.
So it is good for at least that nice example. Kudos Steve + 1. Now wipe off your shoes before coming back to the forum!
Pete
You're right. I didn't check SGN(0) in the code I posted for zero. Oops, my bad. So it does 3 things, but...
Hurry Steve, stomp out that flaming bag of SGN()
But wait a sec... Instead of...
Code: (Select All)
Position1X = 10: Position2X = 15
DirectionX = SGN(Position1X - Position2X)
IF DirectionX =-1 THEN PRINT "NEG" ELSE IF DirectionX THEN PRINT "POS" ELSE PRINT "ZERO"
I'd do...
Code: (Select All)
Position1X = 10: Position2X = 15
DirectionX = Position1X - Position2X
IF DirectionX < 0 THEN PRINT "NEG" ELSE IF DirectionX THEN PRINT "POS" ELSE PRINT "ZERO"
A bit less code that way, or a slight bit more to use SELECT CASE for evaluation as:
SELECT CASE. 1, 0 , -1 vs IS > 0 , 0, IS < 0. Not much of a difference.
It is good as a reference point in your code, to see where you need such comparisons on a search. Jut type search SGN.
I vaguely remember using this statement maybe once decades ago but can't recall what for.
Now Steve's second example is a good one, as you'd get bit in the ASCII doing it this way...
COLOR Kolors((number / ABS(number)))
Division by zero is a killer.
So it is good for at least that nice example. Kudos Steve + 1. Now wipe off your shoes before coming back to the forum!
Pete