Page 1 of 1
Some more math funcs
Posted: Thu Nov 24, 2005 9:28 pm
by Psychophanta
Code: Select all
Procedure.f Sinh(x.f)
ProcedureReturn (Pow(2,x/Log(2))-Pow(2,-x/Log(2)))/2
EndProcedure
Procedure.f Cosh(x.f)
ProcedureReturn (Pow(2,x/Log(2))+Pow(2,-x/Log(2)))/2
EndProcedure
Procedure.f Tanh(x.f)
ProcedureReturn Sinh(x.f)/Cosh(x.f)
EndProcedure
Procedure.f CoTanh(x.f)
ProcedureReturn Cosh(x.f)/Sinh(x.f)
EndProcedure
Procedure.f Sech(x.f)
ProcedureReturn 1/Cosh(x.f)
EndProcedure
Procedure.f CoSech(x.f)
ProcedureReturn 1/Sinh(x.f)
EndProcedure
Procedure.f ePow(x.f)
ProcedureReturn Pow(2,x/Log(2))
EndProcedure
Procedure.f ATan2(y.f,x.f)
!fld dword[esp]
!fld dword[esp+4]
!fpatan
EndProcedure
Posted: Thu Nov 24, 2005 10:55 pm
by Trond
That ATan2() definetely doesn't look right. Shouldn't it compute x/y (with y as the second argument) and then return an angle in the correct quadrant? Where's the four if checks for the quadrants?
Posted: Fri Nov 25, 2005 9:42 am
by Psychophanta
Trond wrote:Shouldn't it compute x/y?
Where's the four if checks for the quadrants?
Nope.
It computes Atan(y/x) and the only check is that when x=0 it returns Pi/2 or -Pi/2 depending on the sign of y . It doesn't check for quadrant.
However, the quadrant result is almost obvious:
If 0<result<PI/2 => 1st quadrant
If PI/2<result<PI => 2nd quadrant
If -PI<result<-PI/2 => 3rd quadrant
If -PI/2<result<0 => 4th quadrant
Posted: Wed Sep 09, 2009 1:39 am
by eddy
necro poster
PB4.40b2
I didn't manage to test your atan2 ASM function.
Here is my version of ATAN2 :
Code: Select all
Procedure.f ATan2(x.f, y.f)
res.f=ATan(y/x)
If x<0
res+3.141592653589793238
ElseIf y<0
res+6.283185307179586477
EndIf
ProcedureReturn res
EndProcedure
Debug ATan2(0, 100)*180/#PI
Debug ATan2(100, 100)*180/#PI
Debug ATan2(100, 0)*180/#PI
Debug ATan2(-100, 100)*180/#PI
Debug ATan2(-100, 0)*180/#PI
Debug ATan2(-100, -100)*180/#PI
Debug ATan2(0, -100)*180/#PI
Debug ATan2(100, -100)*180/#PI
Posted: Wed Sep 09, 2009 2:00 am
by Guimauve
This is my library of custom Maths function.
Regards
Guimauve
Code: Select all
; <<<<<<<<<<<<<<<<<<<<<
; <<<<< Cosecante <<<<<
Macro Cosec(theta)
(1/Sin(theta))
EndMacro
; <<<<<<<<<<<<<<<<<<<
; <<<<< Secante <<<<<
Macro Sec(theta)
(1/Cos(theta))
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<
; <<<<< Cotangente <<<<<
Macro Cotan(theta)
(Cos(theta)/Sin(theta))
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Sinus Hyperbolique <<<<<
Macro SinH(Angle)
((Pow(2.71828182846, Angle) - Pow(2.71828182846, -Angle)) / 2)
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Cosinus Hyperbolique <<<<<
Macro CosH(Angle)
((Pow(2.71828182846, Angle) + Pow(2.71828182846, -Angle)) / 2)
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< Tangente Hyperbolique <<<<<
Macro TanH(Angle)
(((Pow(2.71828182846, Angle) - Pow(2.71828182846, -Angle))) / ((Pow(2.71828182846, Angle) + Pow(2.71828182846, -Angle))))
EndMacro
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
; <<<<< CoTangente Hyperbolique <<<<<
Macro CotanH(Angle)
(((Pow(2.71828182846, Angle) + Pow(2.71828182846, -Angle))) / ((Pow(2.71828182846, Angle) - Pow(2.71828182846, -Angle))))
EndMacro
Re:
Posted: Thu Sep 10, 2009 12:03 am
by Psychophanta
eddy wrote:necro poster
PB4.41b2
I didn't manage to test your atan2 ASM function.
Here is my version of ATAN2 :
Code: Select all
Procedure.f ATan2(x.f, y.f)
res.f=ATan(y/x)
If x<0
res+3.141592653589793238
ElseIf y<0
res+6.283185307179586477
EndIf
ProcedureReturn res
EndProcedure
Debug ATan2(0, 100)*180/#PI
Debug ATan2(100, 100)*180/#PI
Debug ATan2(100, 0)*180/#PI
Debug ATan2(-100, 100)*180/#PI
Debug ATan2(-100, 0)*180/#PI
Debug ATan2(-100, -100)*180/#PI
Debug ATan2(0, -100)*180/#PI
Debug ATan2(100, -100)*180/#PI
4.41b2 version does not exist, does it?
Well, PB versions has changed in time pass that is why it does not work. This one works now:
Code: Select all
Procedure.f ATan2(y.f,x.f)
!fld dword[p.v_y]
!fld dword[p.v_x]
!fpatan
ProcedureReturn
EndProcedure
But for me is a surprise the now there have to write ProcedureReturn to return a float value using floating point intel ASM stack.
EDIT: AArgh! stupid me! i forget since time ago ProcedureReturn is needed to return the float value content when using floating point i386 ASM in a Procedure!
I already have lots of functions in FPU i386 ASM in PB, but last days i have no time to take with PB and i had forgot it...
I wish i have more time for PB programming, but i have not enough atm. :roll: