I wrote an input library that contained this code last year.
(stick input was normalized to 1.0, and where UDLR are boolean only)
DEF BTN_TO_ANALOG U%,D%,L%,R% OUT X,Y UNITVECTOR R% - L%, U% - D% OUT X, Y END DEF UNITVECTOR X, Y OUT UX, UY VAR ANGLE# = ATAN(Y, X) UX = COS(ANGLE#) UY = SIN(ANGLE#) ENDFor this purpose, optimized for lines:
DEF DPAD B OUT IX, IY IX = 0.875 * -SIN(ATAN(!(B AND 8) - !(B AND 4), !(B AND 2) - !(B AND 1))) IY = 0.875 * SIN(ATAN(!(B AND 2) - !(B AND 1), !(B AND 8) - !(B AND 4))) END