Merge branch 'master' of git://factorcode.org/git/factor

db4
Joe Groff 2009-09-14 14:11:17 -05:00
commit 05be076b5f
3 changed files with 25 additions and 3 deletions

View File

@ -0,0 +1,17 @@
! Copyright (C) 2009 Doug Coleman.
! See http://factorcode.org/license.txt for BSD license.
USING: tools.test project-euler.common ;
IN: project-euler.common.tests
[ 4 ] [ -1000 number-length ] unit-test
[ 3 ] [ -999 number-length ] unit-test
[ 3 ] [ -100 number-length ] unit-test
[ 2 ] [ -99 number-length ] unit-test
[ 1 ] [ -9 number-length ] unit-test
[ 1 ] [ -1 number-length ] unit-test
[ 1 ] [ 0 number-length ] unit-test
[ 1 ] [ 9 number-length ] unit-test
[ 2 ] [ 99 number-length ] unit-test
[ 3 ] [ 100 number-length ] unit-test
[ 3 ] [ 999 number-length ] unit-test
[ 4 ] [ 1000 number-length ] unit-test

View File

@ -76,7 +76,12 @@ PRIVATE>
[ dup 0 = not ] [ 10 /mod ] produce reverse nip ; [ dup 0 = not ] [ 10 /mod ] produce reverse nip ;
: number-length ( n -- m ) : number-length ( n -- m )
log10 floor 1 + >integer ; abs [
1
] [
1 0 [ 2over >= ]
[ [ 10 * ] [ 1 + ] bi* ] while 2nip
] if-zero ;
: nth-prime ( n -- n ) : nth-prime ( n -- n )
1 - lprimes lnth ; 1 - lprimes lnth ;

View File

@ -38,7 +38,7 @@ inline static void *ucontext_stack_pointer(void *uap)
inline static unsigned int uap_fpu_status(void *uap) inline static unsigned int uap_fpu_status(void *uap)
{ {
ucontext_t *ucontext = (ucontext_t *)uap; ucontext_t *ucontext = (ucontext_t *)uap;
struct _fpstate *fpregs = (struct _fpstate *)uap->uc_mcontext.fpregs; struct _fpstate *fpregs = (struct _fpstate *)ucontext->uc_mcontext.fpregs;
if (fpregs->magic == X86_FXSR_MAGIC) if (fpregs->magic == X86_FXSR_MAGIC)
return fpregs->sw | fpregs->mxcsr; return fpregs->sw | fpregs->mxcsr;
else else
@ -48,7 +48,7 @@ inline static unsigned int uap_fpu_status(void *uap)
inline static void uap_clear_fpu_status(void *uap) inline static void uap_clear_fpu_status(void *uap)
{ {
ucontext_t *ucontext = (ucontext_t *)uap; ucontext_t *ucontext = (ucontext_t *)uap;
struct _fpstate *fpregs = (struct _fpstate *)uap->uc_mcontext.fpregs; struct _fpstate *fpregs = (struct _fpstate *)ucontext->uc_mcontext.fpregs;
fpregs->sw = 0; fpregs->sw = 0;
if (fpregs->magic == X86_FXSR_MAGIC) if (fpregs->magic == X86_FXSR_MAGIC)
fpregs->mxcsr &= 0xffffffc0; fpregs->mxcsr &= 0xffffffc0;