|
|||
|
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 |
|
|
||||
|
||||
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|