Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Day 003: SGN
#5
@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() Big Grin

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
Reply


Messages In This Thread
Day 003: SGN - by SMcNeill - 11-08-2022, 12:34 PM
RE: Day 003: SGN - by Pete - 11-08-2022, 01:39 PM
RE: Day 003: SGN - by SMcNeill - 11-08-2022, 02:29 PM
RE: Day 003: SGN - by Jack - 11-08-2022, 02:28 PM
RE: Day 003: SGN - by Pete - 11-08-2022, 03:13 PM
RE: Day 003: SGN - by SMcNeill - 11-08-2022, 03:50 PM
RE: Day 003: SGN - by Jack - 11-08-2022, 03:43 PM
RE: Day 003: SGN - by Pete - 11-08-2022, 04:11 PM
RE: Day 003: SGN - by SMcNeill - 11-08-2022, 05:47 PM
RE: Day 003: SGN - by Pete - 11-08-2022, 05:57 PM
RE: Day 003: SGN - by mnrvovrfc - 11-08-2022, 04:51 PM
RE: Day 003: SGN - by bplus - 11-08-2022, 08:20 PM
RE: Day 003: SGN - by Pete - 11-08-2022, 08:28 PM
RE: Day 003: SGN - by bplus - 11-08-2022, 09:37 PM
RE: Day 003: SGN - by Pete - 11-08-2022, 09:43 PM
RE: Day 003: SGN - by bplus - 11-08-2022, 09:53 PM
RE: Day 003: SGN - by Pete - 11-08-2022, 10:23 PM
RE: Day 003: SGN - by OldMoses - 11-09-2022, 07:18 AM
RE: Day 003: SGN - by Pete - 11-09-2022, 08:46 AM



Users browsing this thread: 1 Guest(s)