11-08-2022, 01:39 PM
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...
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
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