Arccosinus and Arcsinus using floating point assembly
-
Hi everybody, I want to get rid of all the imports from the CLR. So I decided to make some functions on my own for example cos() sin() tan() asin() acos(). I already have cos and sin and tan done:
FLOAT Sin( FLOAT A )
{
_asm FLD A;
_asm FSIN;
}FLOAT Cos( FLOAT A )
{
_asm FLD A;
_asm FCOS;
}FLOAT Tan( FLOAT A )
{
_asm FLD A;
_asm FPTAN;
}As you can see I am using inline floating point assembly. But then I thought I could probably use FACOS or FASIN, but those instructions don't exist. Anybody know how I could constructe asin() and acos(), without using the CLR ofcourse. Regards, SystemFiles
-
Hi everybody, I want to get rid of all the imports from the CLR. So I decided to make some functions on my own for example cos() sin() tan() asin() acos(). I already have cos and sin and tan done:
FLOAT Sin( FLOAT A )
{
_asm FLD A;
_asm FSIN;
}FLOAT Cos( FLOAT A )
{
_asm FLD A;
_asm FCOS;
}FLOAT Tan( FLOAT A )
{
_asm FLD A;
_asm FPTAN;
}As you can see I am using inline floating point assembly. But then I thought I could probably use FACOS or FASIN, but those instructions don't exist. Anybody know how I could constructe asin() and acos(), without using the CLR ofcourse. Regards, SystemFiles
when sine or cosine are known, so is the other (remember
sin^2 + cos^2 = 1
), hence also the tangent. Therefore use FPATAN. :)Luc Pattyn [My Articles] Nil Volentibus Arduum
-
when sine or cosine are known, so is the other (remember
sin^2 + cos^2 = 1
), hence also the tangent. Therefore use FPATAN. :)Luc Pattyn [My Articles] Nil Volentibus Arduum
takes a while before I understand what you mean hehe math actually isn't my best point of programming. I will get to this later!
-
when sine or cosine are known, so is the other (remember
sin^2 + cos^2 = 1
), hence also the tangent. Therefore use FPATAN. :)Luc Pattyn [My Articles] Nil Volentibus Arduum
Sorry still dont exactly understand what your saying.
-
Sorry still dont exactly understand what your saying.
when you know cos, you know sin (except for its sign); and vice versa. when you know cos and sin, you know tan. So use FPATAN. :)
Luc Pattyn [My Articles] Nil Volentibus Arduum
-
Hi everybody, I want to get rid of all the imports from the CLR. So I decided to make some functions on my own for example cos() sin() tan() asin() acos(). I already have cos and sin and tan done:
FLOAT Sin( FLOAT A )
{
_asm FLD A;
_asm FSIN;
}FLOAT Cos( FLOAT A )
{
_asm FLD A;
_asm FCOS;
}FLOAT Tan( FLOAT A )
{
_asm FLD A;
_asm FPTAN;
}As you can see I am using inline floating point assembly. But then I thought I could probably use FACOS or FASIN, but those instructions don't exist. Anybody know how I could constructe asin() and acos(), without using the CLR ofcourse. Regards, SystemFiles
Here's some old code that may help:
double Vk05Pi = 1.5707963267948966192313216916398;
#define MTH_ASM_IS0(LABEL_IS0) __asm \
{ \
__asm ftst \
__asm fnstsw ax \
__asm test ah, 40h \
__asm jne LABEL_IS0 \
}
#define MTH_ASM_IS1(LABEL_IS1) __asm \
{ \
__asm fld1 \
__asm fcomp \
__asm fnstsw ax \
__asm test ah, 40h \
__asm jne LABEL_IS1 \
}// arcsine: atan( sqrt( A*A / (1-A*A) ) )
//
double FkASinR( double A )
{
if( A > 1 ) return(0);
#ifndef MTH_ASM_USE
A *= A;
if( FkIs1(A, DBL_MIN) ) return(Vk05Pi);
return( atan( sqrt(A/(1-A)) ) );
#else
__asm {
fld A
fmul A
MTH_ASM_IS1(isone)
fld st(0)
fld1
fsubr // 1 - A*A
fdiv // A*A / (1-A*A)
fsqrt
fld1
fpatan
jmp end
isone:
fstp A
fld Vk05Pi
end:
fstp A
}
return(A);
#endif
}// arccosine: atan( sqrt( (1-A*A) / (A*A) ) )
//
double FkACosR( double A )
{
#ifndef MTH_ASM_USE
A *= A;
if( FkIs0(A, DBL_MIN) ) return(Vk05Pi);
return( atan( sqrt((1-A)/A) ) );
#else
__asm {
fld A
fmul A
MTH_ASM_IS0(iszero)
fld st(0)
fld1
fsubr // 1 - A*A
fdivr // (1-A*A) / A*A
fsqrt
fld1
fpatan
jmp end
iszero:
fstp A
fld Vk05Pi
end:
fstp A
}
return(A);
#endif
}...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack
-
Here's some old code that may help:
double Vk05Pi = 1.5707963267948966192313216916398;
#define MTH_ASM_IS0(LABEL_IS0) __asm \
{ \
__asm ftst \
__asm fnstsw ax \
__asm test ah, 40h \
__asm jne LABEL_IS0 \
}
#define MTH_ASM_IS1(LABEL_IS1) __asm \
{ \
__asm fld1 \
__asm fcomp \
__asm fnstsw ax \
__asm test ah, 40h \
__asm jne LABEL_IS1 \
}// arcsine: atan( sqrt( A*A / (1-A*A) ) )
//
double FkASinR( double A )
{
if( A > 1 ) return(0);
#ifndef MTH_ASM_USE
A *= A;
if( FkIs1(A, DBL_MIN) ) return(Vk05Pi);
return( atan( sqrt(A/(1-A)) ) );
#else
__asm {
fld A
fmul A
MTH_ASM_IS1(isone)
fld st(0)
fld1
fsubr // 1 - A*A
fdiv // A*A / (1-A*A)
fsqrt
fld1
fpatan
jmp end
isone:
fstp A
fld Vk05Pi
end:
fstp A
}
return(A);
#endif
}// arccosine: atan( sqrt( (1-A*A) / (A*A) ) )
//
double FkACosR( double A )
{
#ifndef MTH_ASM_USE
A *= A;
if( FkIs0(A, DBL_MIN) ) return(Vk05Pi);
return( atan( sqrt((1-A)/A) ) );
#else
__asm {
fld A
fmul A
MTH_ASM_IS0(iszero)
fld st(0)
fld1
fsubr // 1 - A*A
fdivr // (1-A*A) / A*A
fsqrt
fld1
fpatan
jmp end
iszero:
fstp A
fld Vk05Pi
end:
fstp A
}
return(A);
#endif
}...cmk The idea that I can be presented with a problem, set out to logically solve it with the tools at hand, and wind up with a program that could not be legally used because someone else followed the same logical steps some years ago and filed for a patent on it is horrifying. - John Carmack
Thats awesome thank you