Author Topic: SmplMath modified sign function  (Read 113 times)

HSE

  • Member
  • ****
  • Posts: 717
  • <AMD>< 7-32>
SmplMath modified sign function
« on: June 25, 2018, 07:23:08 AM »
Hi qWord!!

Here is a modifed function that work more like "sign" function in Matlab (and others), wich detect 3 states:
Code: [Select]
; sign matlab function
fslv_fnc_sgnm macro
fstp REAL4 ptr T_EXPR([esp-4],[rsp])
.if (DWORD ptr T_EXPR([esp-4],[rsp]))&7FFFFFFFh
        fld1
        .if (DWORD ptr T_EXPR([esp-4],[rsp]))&80000000h
        fchs
        .endif
       .else
            fldz
       .endif

endm

Test:
Code: [Select]
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
    .686
    .XMM
    include \masm32\macros\SmplMath2\Math.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

comment * -----------------------------------------------------
                     Build this console app with
                  "MAKEIT.BAT" on the PROJECT menu.
        ----------------------------------------------------- *

    .data?
      value dd ?

    .data
      item dd 0

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    local a1:real8, a3:sdword

    cls
   
    fSlv a1 = 0.00051
    fSlv a3 = sgnm(a1)
    print sstr$(a3),13,10

    fSlv a1 = -0.1
    fSlv a3 = sgnm(a1)
    print sstr$(a3),13,10

    fSlv a1 = 0.0
    fSlv a3 = sgnm(a1)
    print sstr$(a3),13,10

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

end start

Result:
Code: [Select]
1
-1
0
Press any key to continue ...

Well... apparently it's working in FPU backend.

Regards.