Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.* 1 > Newsgroup comp.lang.forth

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 08-17-2009, 11:15 AM
humptydumpty
Guest
 
Posts: n/a
Default Re: revised quadratic.fs

Hi!

On Aug 16, 4:18 pm, Doug Hoffman <glide...@gmail.com> wrote:
> Then it really isn't a correct solution since stack order matters. He
> needs to do something like a F2SWAP to get it right. This might slow
> ROOTS down somewhat.


If having switched roots for only real_roots_with_b=0 is acceptable,
then that is a faster than previous solution, using macros:

\ ---
: ` postpone postpone ; immediate
: -frot ` frot ` frot ; immediate
: f2dup ` fover ` fover ; immediate

: prepare ( F: a b c -- q=c/a p=-b/2a )
` frot ` ftuck ` f/ ` -frot ( F: q b a )
2e ` fliteral ` f* ` f/ ` fnegate
; immediate
: discriminant ( F: q p -- q p d=p^2-q )
` fover ` fnegate ( F: q p -q )
` fover ` fdup ` f* ` f+ ( F: q p -q+p^2 )
; immediate
: complex ( F: q p d -- re1 im1 re2 im2 )
` fnegate ` fsqrt ( F: q p sqrt|d| )
` frot ` fdrop ( F: p sqrt|d| )
` f2dup ` fnegate
; immediate
: real ( F: q p d -- re1 0 re2 0 )
` fsqrt ` fswap ( F: q sqrt|d| p )
` fdup 0e ` fliteral ` f<
` if ` fswap ` fnegate ` then ` f+ ( F: q re1 )
` ftuck ` f/ ( F: q re1 re2 )
` fswap \ switch stack order, but too for b=0 !
0e ` fliteral ` ftuck
; immediate
: roots ( F: a b c -- re1 im1 re2 im2 )
prepare discriminant fdup 0e f<
if complex else real then
;
\ ---


> -Doug

Have a nice day,
humptydumpty
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 11:47 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.