• Welcome to Jose's Read Only Forum 2023.
 

Fast SGN and ABS Inline Function

Started by Theo Gottwald, December 19, 2009, 02:12:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Theo Gottwald

This is of more use. You just want to know if that number is negative.
Here is FastSGN. Just needed is yesterday.

' P2 will be set to 1 in case SIGN of P1 is negative
MACRO SGN_LNG(P1,P2)
MACROTEMP POX
! MOV P2,0
! BT P1,31
! JNC POX
! MOV P2,1
POX:
END MACRO


ABS will normally be compiled from Powerbasic using Floating Point Mnemonics.
If you have a LONG value and just want to cut the Sign, you can use this few lines.

MACRO ABS_LNG(P1)
MACROTEMP POS
! BT P1,31
! JNC POS
! NEG P1
POS:
END MACRO