Basic Univers
Procedure.f WrapValue(Angle.f)
!FLDPI
!FADD st, st
!FLD dword [p.v_Angle]
!FPREM
!FSTP st1
!FLDZ
!FCOMP
!FNSTSW ax
!TEST ah, $41
!JNE l_wrapvalue_ok
!FLDPI
!FADD st, st
!FADDP
wrapvalue_ok:
!RET 4
EndProcedure
Procedure.f ATan2(y.f, x.f)
!FLD dword [p.v_y]
!FLD dword [p.v_x]
!FPATAN
!RET 8
EndProcedure
Procedure.f ATanFull(y.f, x.f)
!FLD dword [p.v_y]
!FLD dword [p.v_x]
!FPATAN
!FLDZ
!FCOMP
!FNSTSW ax
!TEST ah, $41
!JNE l_atanfull_ok
!FLDPI
!FADD st, st
!FADDP
atanfull_ok:
!RET 8
EndProcedure
Procedure.f Exp(x.f)
Protected i.l
!NewCW equ p.v_i + 0
!OldCW equ p.v_i + 2
!FLD dword [p.v_x]
!FABS
!FLDLN2
!FDIVR st0, st1
!FNSTCW word [NewCW]
!FNSTCW word [OldCW]
!AND word [NewCW], $F3FF
!OR word [NewCW], $0400
!FLDCW word [NewCW]
!FRNDINT
!FLDCW word [OldCW]
!FXCH
!FLD st1
!FLDLN2
!FMULP
!FSUBP
!FLD1
!FLD1
!MOV dword [p.v_i], 1
exp_loop:
!FLDZ
!FCOMP
!FNSTSW ax
!TEST ah, $40
!JNE l_exp_end_loop
!FMUL st0, st2
!FIDIV dword [p.v_i]
!INC dword [p.v_i]
!FADD st1, st0
!JMP l_exp_loop
exp_end_loop:
!FSTP st0
!FSTP st1
!FSCALE
!FSTP st1
!TEST dword [p.v_x], $80000000
!JE l_exp_end
!FLD1
!FDIVRP
exp_end:
!ADD esp, 4
!RET 4
EndProcedure
Procedure.d Factorial(n.l)
!TEST dword [p.v_n], $80000000
!JNE l_factorial_end
!FLD1
factorial_loop:
!CMP dword [p.v_n], 1
!JLE l_factorial_end
!FIMUL dword [p.v_n]
!DEC dword [p.v_n]
!JMP l_factorial_loop
factorial_end:
!RET 4
EndProcedure
Procedure.d Permutations(n.l, p.l)
!TEST dword [p.v_n], $80000000
!JNE l_permutations_end
!TEST dword [p.v_p], $80000000
!JNE l_permutations_end
!MOV eax, dword [p.v_n]
!CMP eax, dword [p.v_p]
!JL l_permutations_end
!FLD1
!SUB eax, dword [p.v_p]
permutations_loop:
!CMP dword [p.v_n], eax
!JE l_permutations_end
!FIMUL dword [p.v_n]
!DEC dword [p.v_n]
!JMP l_permutations_loop
permutations_end:
!RET 8
EndProcedure
Procedure.d Combinations(n.l, p.l)
!TEST dword [p.v_n], $80000000
!JNE l_combinations_end
!TEST dword [p.v_p], $80000000
!JNE l_combinations_end
!MOV eax, dword [p.v_n]
!CMP eax, dword [p.v_p]
!JL l_combinations_end
!FLD1
!SHR eax, 1
!CMP eax, dword [p.v_p]
!JG l_combinations_loop
!MOV eax, dword [p.v_n]
!SUB eax, dword [p.v_p]
!MOV dword [p.v_p], eax
combinations_loop:
!CMP dword [p.v_p], 0
!JLE l_combinations_end_loop
!FIMUL dword [p.v_n]
!FIDIV dword [p.v_p]
!DEC dword [p.v_n]
!DEC dword [p.v_p]
!JMP l_combinations_loop
combinations_end_loop:
!FRNDINT
combinations_end:
!RET 8
EndProcedure
Procedure.f Mod(x.f, y.f)
!FLD dword [p.v_x]
!FLD dword [p.v_y]
!FPREM
!FSTP st1
!RET 8
EndProcedure
Procedure.f Ceil(Value.f)
Protected CW.l
!NewCW equ p.v_CW + 0
!OldCW equ p.v_CW + 2
!FNSTCW word [OldCW]
!FNSTCW word [NewCW]
!AND word [NewCW], $F3FF
!OR word [NewCW], $0800
!FLDCW word [NewCW]
!FLD dword [p.v_Value]
!FRNDINT
!FLDCW word [OldCW]
!ADD esp, 4
!RET 4
EndProcedure
Procedure.f Floor(Value.f)
Protected CW.l
!NewCW equ p.v_CW + 0
!OldCW equ p.v_CW + 2
!FNSTCW word [OldCW]
!FNSTCW word [NewCW]
!AND word [NewCW], $F3FF
!OR word [NewCW], $0400
!FLDCW word [NewCW]
!FLD dword [p.v_Value]
!FRNDINT
!FLDCW word [OldCW]
!ADD esp, 4
!RET 4
EndProcedure
Procedure.f Significand(Value.f)
!FLD dword [p.v_Value]
!FXTRACT
!FSTP st1
!RET 4
EndProcedure
Procedure.f Exponent(Value.f)
!FLD dword [p.v_Value]
!FXTRACT
!FSTP st0
!RET 4
EndProcedure
Procedure.f Scale(Significand.f, Exponent.f)
!FLD dword [p.v_Exponent]
!FLD dword [p.v_Significand]
!FSCALE
!FSTP st1
!RET 8
EndProcedure
Procedure GCD(a.l, b.l)
!MOV eax, dword [p.v_a]
!MOV ebx, dword [p.v_b]
gcd_loop:
!CMP ebx, 0
!JE l_gcd_end
!CDQ
!IDIV ebx
!MOV eax, ebx
!MOV ebx, edx
!JMP l_gcd_loop
gcd_end:
!RET 8
EndProcedure