11 - 374 11 - 374
MELSEC-Q
11 INSTRUCTIONS AND FUNCTIONS
SGN
Function
SiGN
• Returns the sign of a value.
SGN(<numeric expression>)
Syntax
numeric expression
• • • •
Specify the value whose sign is to be returned.
Examples
A=SGN(B%)
• • • •
Assigns 1 to A if the value of B% is positive, 0 to A if
the value of B% is 0, and -1 to A if the value of B% is
negative.
Description
• The SGN function returns the sign of a value.
• It returns 1 if the value of <numeric expression> is positive, 0 if it is 0, and -1 if it is
negative.
Program Example
10 ' This program returns the sign of a value
20 A=-123
:
'Defines a numeric value
30 B=0
40 C=123
50 PRINT "SGN(A)=";SGN(A)
:
'Displays the result
60 PRINT "SGN(B)=";SGN(B)
70 PRINT "SGN(C)=";SGN(C)
RUN
SGN(A)=1
SGN(B)=0
SGN(C)=-1
OK