Improve math.functions
parent
a77bbfc28e
commit
8af320a2c0
|
@ -39,6 +39,12 @@ IN: math.functions.tests
|
||||||
[ 0.0 ] [ 0 sin ] unit-test
|
[ 0.0 ] [ 0 sin ] unit-test
|
||||||
[ 0.0 ] [ 0 asin ] unit-test
|
[ 0.0 ] [ 0 asin ] unit-test
|
||||||
|
|
||||||
|
[ t ] [ 10 atan real? ] unit-test
|
||||||
|
[ f ] [ 10 atanh real? ] unit-test
|
||||||
|
|
||||||
|
[ t ] [ 10 asin sin 10 1.e-10 ~ ] unit-test
|
||||||
|
[ t ] [ -1 sqrt neg dup acos cos 1.e-10 ~ ] unit-test
|
||||||
|
|
||||||
[ 100 ] [ 100 100 gcd nip ] unit-test
|
[ 100 ] [ 100 100 gcd nip ] unit-test
|
||||||
[ 100 ] [ 1000 100 gcd nip ] unit-test
|
[ 100 ] [ 1000 100 gcd nip ] unit-test
|
||||||
[ 100 ] [ 100 1000 gcd nip ] unit-test
|
[ 100 ] [ 100 1000 gcd nip ] unit-test
|
||||||
|
|
|
@ -125,74 +125,90 @@ M: real absq sq ;
|
||||||
M: number (^)
|
M: number (^)
|
||||||
swap >polar 3dup ^theta >r ^mag r> polar> ;
|
swap >polar 3dup ^theta >r ^mag r> polar> ;
|
||||||
|
|
||||||
|
: [-1,1]? ( x -- ? )
|
||||||
|
dup complex? [ drop f ] [ abs 1 <= ] if ; inline
|
||||||
|
|
||||||
|
: >=1? ( x -- ? )
|
||||||
|
dup complex? [ drop f ] [ 1 >= ] if ; inline
|
||||||
|
|
||||||
: exp ( x -- y ) >rect swap fexp swap polar> ; inline
|
: exp ( x -- y ) >rect swap fexp swap polar> ; inline
|
||||||
|
|
||||||
: log ( x -- y ) >polar swap flog swap rect> ; inline
|
: log ( x -- y ) >polar swap flog swap rect> ; inline
|
||||||
|
|
||||||
: cos ( x -- y )
|
: cos ( x -- y )
|
||||||
|
dup complex? [
|
||||||
>float-rect 2dup
|
>float-rect 2dup
|
||||||
fcosh swap fcos * -rot
|
fcosh swap fcos * -rot
|
||||||
fsinh swap fsin neg * rect> ; foldable
|
fsinh swap fsin neg * rect>
|
||||||
|
] [ fcos ] if ; foldable
|
||||||
|
|
||||||
: sec ( x -- y ) cos recip ; inline
|
: sec ( x -- y ) cos recip ; inline
|
||||||
|
|
||||||
: cosh ( x -- y )
|
: cosh ( x -- y )
|
||||||
|
dup complex? [
|
||||||
>float-rect 2dup
|
>float-rect 2dup
|
||||||
fcos swap fcosh * -rot
|
fcos swap fcosh * -rot
|
||||||
fsin swap fsinh * rect> ; foldable
|
fsin swap fsinh * rect>
|
||||||
|
] [ fcosh ] if ; foldable
|
||||||
|
|
||||||
: sech ( x -- y ) cosh recip ; inline
|
: sech ( x -- y ) cosh recip ; inline
|
||||||
|
|
||||||
: sin ( x -- y )
|
: sin ( x -- y )
|
||||||
|
dup complex? [
|
||||||
>float-rect 2dup
|
>float-rect 2dup
|
||||||
fcosh swap fsin * -rot
|
fcosh swap fsin * -rot
|
||||||
fsinh swap fcos * rect> ; foldable
|
fsinh swap fcos * rect>
|
||||||
|
] [ fsin ] if ; foldable
|
||||||
|
|
||||||
: cosec ( x -- y ) sin recip ; inline
|
: cosec ( x -- y ) sin recip ; inline
|
||||||
|
|
||||||
: sinh ( x -- y )
|
: sinh ( x -- y )
|
||||||
|
dup complex? [
|
||||||
>float-rect 2dup
|
>float-rect 2dup
|
||||||
fcos swap fsinh * -rot
|
fcos swap fsinh * -rot
|
||||||
fsin swap fcosh * rect> ; foldable
|
fsin swap fcosh * rect>
|
||||||
|
] [ fsinh ] if ; foldable
|
||||||
|
|
||||||
: cosech ( x -- y ) sinh recip ; inline
|
: cosech ( x -- y ) sinh recip ; inline
|
||||||
|
|
||||||
: tan ( x -- y ) dup sin swap cos / ; inline
|
: tan ( x -- y )
|
||||||
|
dup complex? [ dup sin swap cos / ] [ ftan ] if ; inline
|
||||||
|
|
||||||
: tanh ( x -- y ) dup sinh swap cosh / ; inline
|
: tanh ( x -- y )
|
||||||
|
dup complex? [ dup sinh swap cosh / ] [ ftanh ] if ; inline
|
||||||
|
|
||||||
: cot ( x -- y ) dup cos swap sin / ; inline
|
: cot ( x -- y ) tan recip ; inline
|
||||||
|
|
||||||
: coth ( x -- y ) dup cosh swap sinh / ; inline
|
: coth ( x -- y ) tanh recip ; inline
|
||||||
|
|
||||||
: acosh ( x -- y ) dup sq 1- sqrt + log ; inline
|
: acosh ( x -- y )
|
||||||
|
dup >=1? [ facosh ] [ dup sq 1- sqrt + log ] if ; inline
|
||||||
|
|
||||||
: asech ( x -- y ) recip acosh ; inline
|
: asech ( x -- y ) recip acosh ; inline
|
||||||
|
|
||||||
: asinh ( x -- y ) dup sq 1+ sqrt + log ; inline
|
: asinh ( x -- y )
|
||||||
|
dup complex? [ dup sq 1+ sqrt + log ] [ fasinh ] if ; inline
|
||||||
|
|
||||||
: acosech ( x -- y ) recip asinh ; inline
|
: acosech ( x -- y ) recip asinh ; inline
|
||||||
|
|
||||||
: atanh ( x -- y ) dup 1+ swap 1- neg / log 2 / ; inline
|
: atanh ( x -- y )
|
||||||
|
dup [-1,1]? [ fatanh ] [ dup 1+ swap 1- neg / log 2 / ] if ; inline
|
||||||
|
|
||||||
: acoth ( x -- y ) recip atanh ; inline
|
: acoth ( x -- y ) recip atanh ; inline
|
||||||
|
|
||||||
: [-1,1]? ( x -- ? )
|
|
||||||
dup complex? [ drop f ] [ abs 1 <= ] if ; inline
|
|
||||||
|
|
||||||
: i* ( x -- y ) >rect neg swap rect> ;
|
: i* ( x -- y ) >rect neg swap rect> ;
|
||||||
|
|
||||||
: -i* ( x -- y ) >rect swap neg rect> ;
|
: -i* ( x -- y ) >rect swap neg rect> ;
|
||||||
|
|
||||||
: asin ( x -- y )
|
: asin ( x -- y )
|
||||||
dup [-1,1]? [ >float fasin ] [ i* asinh -i* ] if ; inline
|
dup [-1,1]? [ fasin ] [ i* asinh -i* ] if ; inline
|
||||||
|
|
||||||
: acos ( x -- y )
|
: acos ( x -- y )
|
||||||
dup [-1,1]? [ >float facos ] [ asin pi 2 / swap - ] if ;
|
dup [-1,1]? [ facos ] [ asin pi 2 / swap - ] if ;
|
||||||
inline
|
inline
|
||||||
|
|
||||||
: atan ( x -- y )
|
: atan ( x -- y )
|
||||||
dup [-1,1]? [ >float fatan ] [ i* atanh i* ] if ; inline
|
dup complex? [ i* atanh i* ] [ fatan ] if ; inline
|
||||||
|
|
||||||
: asec ( x -- y ) recip acos ; inline
|
: asec ( x -- y ) recip acos ; inline
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,18 @@ IN: math.libm
|
||||||
"double" "libm" "atan" { "double" } alien-invoke ;
|
"double" "libm" "atan" { "double" } alien-invoke ;
|
||||||
foldable
|
foldable
|
||||||
|
|
||||||
|
: facosh ( x -- y )
|
||||||
|
"double" "libm" "acosh" { "double" } alien-invoke ;
|
||||||
|
foldable
|
||||||
|
|
||||||
|
: fasinh ( x -- y )
|
||||||
|
"double" "libm" "asinh" { "double" } alien-invoke ;
|
||||||
|
foldable
|
||||||
|
|
||||||
|
: fatanh ( x -- y )
|
||||||
|
"double" "libm" "atanh" { "double" } alien-invoke ;
|
||||||
|
foldable
|
||||||
|
|
||||||
: fatan2 ( x y -- z )
|
: fatan2 ( x y -- z )
|
||||||
"double" "libm" "atan2" { "double" "double" } alien-invoke ;
|
"double" "libm" "atan2" { "double" "double" } alien-invoke ;
|
||||||
foldable
|
foldable
|
||||||
|
@ -27,6 +39,10 @@ IN: math.libm
|
||||||
"double" "libm" "sin" { "double" } alien-invoke ;
|
"double" "libm" "sin" { "double" } alien-invoke ;
|
||||||
foldable
|
foldable
|
||||||
|
|
||||||
|
: ftan ( x -- y )
|
||||||
|
"double" "libm" "tan" { "double" } alien-invoke ;
|
||||||
|
foldable
|
||||||
|
|
||||||
: fcosh ( x -- y )
|
: fcosh ( x -- y )
|
||||||
"double" "libm" "cosh" { "double" } alien-invoke ;
|
"double" "libm" "cosh" { "double" } alien-invoke ;
|
||||||
foldable
|
foldable
|
||||||
|
@ -35,6 +51,10 @@ IN: math.libm
|
||||||
"double" "libm" "sinh" { "double" } alien-invoke ;
|
"double" "libm" "sinh" { "double" } alien-invoke ;
|
||||||
foldable
|
foldable
|
||||||
|
|
||||||
|
: ftanh ( x -- y )
|
||||||
|
"double" "libm" "tanh" { "double" } alien-invoke ;
|
||||||
|
foldable
|
||||||
|
|
||||||
: fexp ( x -- y )
|
: fexp ( x -- y )
|
||||||
"double" "libm" "exp" { "double" } alien-invoke ;
|
"double" "libm" "exp" { "double" } alien-invoke ;
|
||||||
foldable
|
foldable
|
||||||
|
|
Loading…
Reference in New Issue