I need help converting this Excel formula to C (using pure Win32 API, with atan2 from msvcrt). The Excel formula is:
=IF(AND(L9=0;M9=0);0;IF(M9>=0;DEGREES(ATAN2(L9;M9));DEGREES(ATAN2(L9;M9))+360))
I tried to port it, but I don´t understand the degree convention, because the values are not matching.
What is the correspondent C function for this Excel formula?
Ok, I edited the answer here. I suceeded to make a function that works exactly as the one in excel. I wrote it in assembler (using RosAsm assembler), but it shouldn´t be hard to port to C.
[Float_DoublePi: R$ (2*3.1415926535897932384626433832795028841971693993751058)]
[Float_180_Pi: R$ (3.1415926535897932384626433832795028841971693993751058/2)]
[ConvRadianToDegree: R$ (180/3.14159286)]
[FloatZero: R$ 0]
Proc ComputedH:
Arguments @aFact, @bFact, @HFact
Uses ebx, esi, ecx, edi, eax
mov ebx D@aFact
mov esi D@bFact
mov edi D@HFact
.Fpu_If_And R$ebx = R$FloatZero, R$esi = R$FloatZero
fldz | fstp R$edi
.Fpu_Else_If R$esi >= R$FloatZero
Fpu_If R$ebx >= R$FloatZero
fld R$Float_180_Pi
C_call 'msvcrt.atan2' D$ebx, D$ebx+4, D$esi, D$esi+4
fsubrp ST1 ST0 | fabs
Fpu_Else
fld R$Float_180_Pi
C_call 'msvcrt.atan2' D$ebx, D$ebx+4, D$esi, D$esi+4
fsubrp ST1 ST0 | fabs
Fpu_End_If
.Fpu_Else
Fpu_If R$ebx >= R$FloatZero
C_call 'msvcrt.atan2' D$esi, D$esi+4, D$ebx, D$ebx+4 | fadd R$Float_DoublePi
Fpu_Else
; 360-X-(pi+pi/2) ==> 2PI-X-(pi+pi/2) = pi/2-X
fld R$Float_180_Pi
C_call 'msvcrt.atan2' D$ebx, D$ebx+4, D$esi, D$esi+4
fsubrp ST1 ST0 | fabs
Fpu_End_If
.Fpu_End_If
fmul R$ConvRadianToDegree | fstp R$edi
EndP