Tweak math.functions to inline better
parent
86d45262dc
commit
e1578b5848
|
@ -100,7 +100,7 @@ PRIVATE>
|
||||||
{ [ dup integer? ] [ integer^ ] }
|
{ [ dup integer? ] [ integer^ ] }
|
||||||
{ [ 2dup real^? ] [ fpow ] }
|
{ [ 2dup real^? ] [ fpow ] }
|
||||||
[ ^complex ]
|
[ ^complex ]
|
||||||
} cond ;
|
} cond ; inline
|
||||||
|
|
||||||
: (^mod) ( n x y -- z )
|
: (^mod) ( n x y -- z )
|
||||||
1 swap [
|
1 swap [
|
||||||
|
@ -174,47 +174,61 @@ M: real log dup 0.0 >= [ flog ] [ 0.0 rect> log ] if ;
|
||||||
|
|
||||||
M: complex log >polar swap flog swap rect> ;
|
M: complex log >polar swap flog swap rect> ;
|
||||||
|
|
||||||
: cos ( x -- y )
|
GENERIC: cos ( x -- y ) foldable
|
||||||
dup complex? [
|
|
||||||
>float-rect 2dup
|
M: complex cos
|
||||||
fcosh swap fcos * -rot
|
>float-rect 2dup
|
||||||
fsinh swap fsin neg * rect>
|
fcosh swap fcos * -rot
|
||||||
] [ fcos ] if ; foldable
|
fsinh swap fsin neg * rect> ;
|
||||||
|
|
||||||
|
M: real cos fcos ;
|
||||||
|
|
||||||
: sec ( x -- y ) cos recip ; inline
|
: sec ( x -- y ) cos recip ; inline
|
||||||
|
|
||||||
: cosh ( x -- y )
|
GENERIC: cosh ( x -- y ) foldable
|
||||||
dup complex? [
|
|
||||||
>float-rect 2dup
|
M: complex cosh
|
||||||
fcos swap fcosh * -rot
|
>float-rect 2dup
|
||||||
fsin swap fsinh * rect>
|
fcos swap fcosh * -rot
|
||||||
] [ fcosh ] if ; foldable
|
fsin swap fsinh * rect> ;
|
||||||
|
|
||||||
|
M: real cosh fcosh ;
|
||||||
|
|
||||||
: sech ( x -- y ) cosh recip ; inline
|
: sech ( x -- y ) cosh recip ; inline
|
||||||
|
|
||||||
: sin ( x -- y )
|
GENERIC: sin ( x -- y ) foldable
|
||||||
dup complex? [
|
|
||||||
>float-rect 2dup
|
M: complex sin
|
||||||
fcosh swap fsin * -rot
|
>float-rect 2dup
|
||||||
fsinh swap fcos * rect>
|
fcosh swap fsin * -rot
|
||||||
] [ fsin ] if ; foldable
|
fsinh swap fcos * rect> ;
|
||||||
|
|
||||||
|
M: real sin fsin ;
|
||||||
|
|
||||||
: cosec ( x -- y ) sin recip ; inline
|
: cosec ( x -- y ) sin recip ; inline
|
||||||
|
|
||||||
: sinh ( x -- y )
|
GENERIC: sinh ( x -- y ) foldable
|
||||||
dup complex? [
|
|
||||||
>float-rect 2dup
|
M: complex sinh
|
||||||
fcos swap fsinh * -rot
|
>float-rect 2dup
|
||||||
fsin swap fcosh * rect>
|
fcos swap fsinh * -rot
|
||||||
] [ fsinh ] if ; foldable
|
fsin swap fcosh * rect> ;
|
||||||
|
|
||||||
|
M: real sinh fsinh ;
|
||||||
|
|
||||||
: cosech ( x -- y ) sinh recip ; inline
|
: cosech ( x -- y ) sinh recip ; inline
|
||||||
|
|
||||||
: tan ( x -- y )
|
GENERIC: tan ( x -- y ) foldable
|
||||||
dup complex? [ dup sin swap cos / ] [ ftan ] if ; inline
|
|
||||||
|
|
||||||
: tanh ( x -- y )
|
M: complex tan [ sin ] [ cos ] bi / ;
|
||||||
dup complex? [ dup sinh swap cosh / ] [ ftanh ] if ; inline
|
|
||||||
|
M: real tan ftan ;
|
||||||
|
|
||||||
|
GENERIC: tanh ( x -- y ) foldable
|
||||||
|
|
||||||
|
M: complex tanh [ sinh ] [ cosh ] bi / ;
|
||||||
|
|
||||||
|
M: real tanh ftanh ;
|
||||||
|
|
||||||
: cot ( x -- y ) tan recip ; inline
|
: cot ( x -- y ) tan recip ; inline
|
||||||
|
|
||||||
|
@ -231,7 +245,7 @@ M: complex log >polar swap flog swap rect> ;
|
||||||
: acosech ( x -- y ) recip asinh ; inline
|
: acosech ( x -- y ) recip asinh ; inline
|
||||||
|
|
||||||
: atanh ( x -- y )
|
: atanh ( x -- y )
|
||||||
dup 1+ swap 1- neg / log 2 / ; inline
|
[ 1+ ] [ 1- neg ] bi / log 2 / ; inline
|
||||||
|
|
||||||
: acoth ( x -- y ) recip atanh ; inline
|
: acoth ( x -- y ) recip atanh ; inline
|
||||||
|
|
||||||
|
@ -246,8 +260,11 @@ M: complex log >polar swap flog swap rect> ;
|
||||||
dup [-1,1]? [ facos ] [ asin pi 2 / swap - ] if ;
|
dup [-1,1]? [ facos ] [ asin pi 2 / swap - ] if ;
|
||||||
inline
|
inline
|
||||||
|
|
||||||
: atan ( x -- y )
|
GENERIC: atan ( x -- y ) foldable
|
||||||
dup complex? [ i* atanh i* ] [ fatan ] if ; inline
|
|
||||||
|
M: complex atan i* atanh i* ;
|
||||||
|
|
||||||
|
M: real atan fatan ;
|
||||||
|
|
||||||
: asec ( x -- y ) recip acos ; inline
|
: asec ( x -- y ) recip acos ; inline
|
||||||
|
|
||||||
|
|
|
@ -5,69 +5,69 @@ IN: math.libm
|
||||||
|
|
||||||
: facos ( x -- y )
|
: facos ( x -- y )
|
||||||
"double" "libm" "acos" { "double" } alien-invoke ;
|
"double" "libm" "acos" { "double" } alien-invoke ;
|
||||||
foldable
|
inline
|
||||||
|
|
||||||
: fasin ( x -- y )
|
: fasin ( x -- y )
|
||||||
"double" "libm" "asin" { "double" } alien-invoke ;
|
"double" "libm" "asin" { "double" } alien-invoke ;
|
||||||
foldable
|
inline
|
||||||
|
|
||||||
: fatan ( x -- y )
|
: fatan ( x -- y )
|
||||||
"double" "libm" "atan" { "double" } alien-invoke ;
|
"double" "libm" "atan" { "double" } alien-invoke ;
|
||||||
foldable
|
inline
|
||||||
|
|
||||||
: fatan2 ( x y -- z )
|
: fatan2 ( x y -- z )
|
||||||
"double" "libm" "atan2" { "double" "double" } alien-invoke ;
|
"double" "libm" "atan2" { "double" "double" } alien-invoke ;
|
||||||
foldable
|
inline
|
||||||
|
|
||||||
: fcos ( x -- y )
|
: fcos ( x -- y )
|
||||||
"double" "libm" "cos" { "double" } alien-invoke ;
|
"double" "libm" "cos" { "double" } alien-invoke ;
|
||||||
foldable
|
inline
|
||||||
|
|
||||||
: fsin ( x -- y )
|
: fsin ( x -- y )
|
||||||
"double" "libm" "sin" { "double" } alien-invoke ;
|
"double" "libm" "sin" { "double" } alien-invoke ;
|
||||||
foldable
|
inline
|
||||||
|
|
||||||
: ftan ( x -- y )
|
: ftan ( x -- y )
|
||||||
"double" "libm" "tan" { "double" } alien-invoke ;
|
"double" "libm" "tan" { "double" } alien-invoke ;
|
||||||
foldable
|
inline
|
||||||
|
|
||||||
: fcosh ( x -- y )
|
: fcosh ( x -- y )
|
||||||
"double" "libm" "cosh" { "double" } alien-invoke ;
|
"double" "libm" "cosh" { "double" } alien-invoke ;
|
||||||
foldable
|
inline
|
||||||
|
|
||||||
: fsinh ( x -- y )
|
: fsinh ( x -- y )
|
||||||
"double" "libm" "sinh" { "double" } alien-invoke ;
|
"double" "libm" "sinh" { "double" } alien-invoke ;
|
||||||
foldable
|
inline
|
||||||
|
|
||||||
: ftanh ( x -- y )
|
: ftanh ( x -- y )
|
||||||
"double" "libm" "tanh" { "double" } alien-invoke ;
|
"double" "libm" "tanh" { "double" } alien-invoke ;
|
||||||
foldable
|
inline
|
||||||
|
|
||||||
: fexp ( x -- y )
|
: fexp ( x -- y )
|
||||||
"double" "libm" "exp" { "double" } alien-invoke ;
|
"double" "libm" "exp" { "double" } alien-invoke ;
|
||||||
foldable
|
inline
|
||||||
|
|
||||||
: flog ( x -- y )
|
: flog ( x -- y )
|
||||||
"double" "libm" "log" { "double" } alien-invoke ;
|
"double" "libm" "log" { "double" } alien-invoke ;
|
||||||
foldable
|
inline
|
||||||
|
|
||||||
: fpow ( x y -- z )
|
: fpow ( x y -- z )
|
||||||
"double" "libm" "pow" { "double" "double" } alien-invoke ;
|
"double" "libm" "pow" { "double" "double" } alien-invoke ;
|
||||||
foldable
|
inline
|
||||||
|
|
||||||
: fsqrt ( x -- y )
|
: fsqrt ( x -- y )
|
||||||
"double" "libm" "sqrt" { "double" } alien-invoke ;
|
"double" "libm" "sqrt" { "double" } alien-invoke ;
|
||||||
foldable
|
inline
|
||||||
|
|
||||||
! Windows doesn't have these...
|
! Windows doesn't have these...
|
||||||
: facosh ( x -- y )
|
: facosh ( x -- y )
|
||||||
"double" "libm" "acosh" { "double" } alien-invoke ;
|
"double" "libm" "acosh" { "double" } alien-invoke ;
|
||||||
foldable
|
inline
|
||||||
|
|
||||||
: fasinh ( x -- y )
|
: fasinh ( x -- y )
|
||||||
"double" "libm" "asinh" { "double" } alien-invoke ;
|
"double" "libm" "asinh" { "double" } alien-invoke ;
|
||||||
foldable
|
inline
|
||||||
|
|
||||||
: fatanh ( x -- y )
|
: fatanh ( x -- y )
|
||||||
"double" "libm" "atanh" { "double" } alien-invoke ;
|
"double" "libm" "atanh" { "double" } alien-invoke ;
|
||||||
foldable
|
inline
|
||||||
|
|
Loading…
Reference in New Issue