Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Day 003: SGN
#2
My proposed use for SGN is a 3-step process: 1) Wrap it up in a brown paper bag. 2) Place it on the porch of QB64 Official. 3) Light it on fire.

Honestly this is one of the few BASIC keywords that require you to type slightly more code instead of less...

Code: (Select All)
FOR i = -5 TO 5
    PRINT i;
    IF SGN(i) < 0 THEN PRINT "neg", ELSE PRINT "pos",
    IF i < 0 THEN PRINT "neg" ELSE PRINT "pos"
NEXT
PRINT: PRINT SGN(-2 + -6 + 8 + 22 - 33 + -77), -2 + -6 + 8 + 22 - 33 + -77 < 0
PRINT: PRINT SGN(ABS(-2 + -6 + 8 + 22 - 33 + -77)), ABS(-2 + -6 + 8 + 22 - 33 + -77) < 0

Note the only difference is a numerical one, involving the numbers in parentheses. SGN returns -1 for true and 1 for false, where "<" returns zero for false. I really can't see how even that is useful. Special consideration isn't even given to zero. SGN returns zero as positive, so I see no advantage there, either.

Oh well, "Random Generator" is just in its infancy, but I'm pretty sure given the way things are going, it is destined to grow up and be a Magic 8-Ball.

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)