move nth-root to math.functions, use exchange-unsafe in math.statistics

db4
Doug Coleman 2009-10-30 02:35:51 -05:00
parent 1cf45abf06
commit 003787113f
3 changed files with 6 additions and 8 deletions

View File

@ -106,6 +106,8 @@ PRIVATE>
[ ^complex ] [ ^complex ]
} cond ; inline } cond ; inline
: nth-root ( n x -- y ) swap recip ^ ; inline
: gcd ( x y -- a d ) : gcd ( x y -- a d )
[ 0 1 ] 2dip (gcd) dup 0 < [ neg ] when ; foldable [ 0 1 ] 2dip (gcd) dup 0 < [ neg ] when ; foldable
@ -304,4 +306,3 @@ M: real atan >float atan ; inline
[ [ / floor ] [ * ] bi ] unless-zero ; [ [ / floor ] [ * ] bi ] unless-zero ;
: lerp ( a b t -- a_t ) [ over - ] dip * + ; inline : lerp ( a b t -- a_t ) [ over - ] dip * + ; inline

View File

@ -1,8 +1,8 @@
! Copyright (C) 2008 Doug Coleman, Michael Judge. ! Copyright (C) 2008 Doug Coleman, Michael Judge.
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: arrays combinators kernel math math.analysis USING: arrays combinators kernel math math.functions
math.functions math.order sequences sorting locals math.order sequences sorting locals sequences.private
sequences.private assocs fry ; assocs fry ;
IN: math.statistics IN: math.statistics
: mean ( seq -- x ) : mean ( seq -- x )
@ -33,7 +33,7 @@ IN: math.statistics
[ i seq nth-unsafe x < ] [ i 1 + i! ] while [ i seq nth-unsafe x < ] [ i 1 + i! ] while
[ x j seq nth-unsafe < ] [ j 1 - j! ] while [ x j seq nth-unsafe < ] [ j 1 - j! ] while
i j <= [ i j <= [
i j seq exchange i j seq exchange-unsafe
i 1 + i! i 1 + i!
j 1 - j! j 1 - j!
] when ] when

View File

@ -56,9 +56,6 @@ PRIVATE>
[ abs gammaln-lanczos6 ] keep dup 0 > [ drop ] [ gamma-neg ] if [ abs gammaln-lanczos6 ] keep dup 0 > [ drop ] [ gamma-neg ] if
] if ; ] if ;
: nth-root ( n x -- y )
swap recip ^ ;
! Forth Scientific Library Algorithm #1 ! Forth Scientific Library Algorithm #1
! !
! Evaluates the Real Exponential Integral, ! Evaluates the Real Exponential Integral,