If the number is negative (i.e. if its most significant bit is on) then a - (negative) is added to the buffer. If the number is positive (MSB=0), SIGN performs no action.
Note that SIGN takes a single signed value as its input. When using <# … #> to display a signed-double value, one will normally copy the high-order word of the double value, and store it somewhere (e.g. in a variable or on the return stack) to feed to SIGN later.
Caution: When storing data on the return stack, it is crucial that the return stack be restored before the colon definition exits. Additionally, the return stack should not be used to hold data inside of a loop. An alternative to the return stack would be to use the word TUCK to store a copy of the high-order cell underneath the double number, as in:
: TEST TUCK DABS <# #S ROT SIGN #> TYPE SPACE ;
|