Hi,
I could not resist to play with Leon's newest >float library, so
here is a small real life test, it tests basically everything so you
may optimise. Currently running on amforth 4.0. Enjoy the fun with
float! P.

\ ##########################################################
\ FLOATING POINT TEST
\ The kinetic energy of 100 random sized spherical asteroids 
\ 
\ speeds between 20-70 km/sec 
\ density 2.5 g/cm3
\ diameter 1m-1km
\
\ amforth 4.0 @22MHz, 115200 Baud 
\ typical elapsed time ~22sec
\ Leon's flib library, Pito's asm (f*/+-) lib
\ Pito 10\2010

marker -armageddontest

\ simple RND generator u2 = 0..u1-1
variable rnd here rnd !
: (random)  rnd @ 31421 *  6927 +  dup rnd ! ;
: nip swap drop ;
: random  ( u1 -- u2 )  (random) um*  nip ;

\ floating point input with >float, "& -1.23456e-12"
: & bl word count >float not abort" NaN" 
state @ if postpone fliteral then ; immediate

\ print 6 decimal places
: f6. 6 fsn. ;

\ radius of the asteroid in m
: radius ( -- fradius )
random 1+ s>f & 2.0 f/  fdup  
." R(m)=" f6. space ;

\ volume in m3
: volume ( fradius -- fvolume )
fdup fdup f* f* & 4.0e0 & 3.0e0 f/ & 3.141592e0 f*  f* fdup
." V(m3)=" f6. space ;

\ mass in kg
: mass ( fvolume -- fmass ) 
& 2.50e & 1.0e-3 & 1.0e6 f* f*  
f* fdup 
." M(kg)=" f6. space ;

\ speed between 20-70km/sec
: speed ( -- fspeed ) 
51 random 20 + s>f & 1.0e3 f* fdup
." v(m/sec)=" f6. space ;

\ kinetic energy
: kenergy ( fmass fspeed - fkenergy )
fdup f* f* & 2.0e0 f/ 
." Ek(J)=" f6. space ;

\ simulation
: simulate 1000 radius volume mass speed kenergy cr ;

\ run 100x
: test
cr 100 0 timer-start 
do i 1+ . simulate loop
.elapsed ." elapsed" ;

-----------------------
......
99 R(m)= 7.199999E1  V(m3)= 1.563457E6  M(kg)= 3.908643E9  v(m/sec)=
6.599999E4  Ek(J)= 8.513026E18  
100 R(m)= 2.605000E2  V(m3)= 7.404773E7  M(kg)= 1.851193E11 
v(m/sec)= 5.099999E4  Ek(J)= 2.407476E20  
2.196E1 secs elapsed ok

# .s
ok





------------------------------------------------------------------------------
Nokia and AT&T present the 2010 Calling All Innovators-North America contest
Create new apps & games for the Nokia N8 for consumers in  U.S. and Canada
$10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing
Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store 
http://p.sf.net/sfu/nokia-dev2dev
_______________________________________________
Amforth-devel mailing list
Amforth-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amforth-devel

Reply via email to