Last active
November 27, 2022 10:09
-
-
Save neuro-sys/228a910e7e11cf467fcd75ace2b27a13 to your computer and use it in GitHub Desktop.
forth locals with vocabularies
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vocabulary quadratic also quadratic definitions | |
vocabulary fdiscriminant also fdiscriminant definitions | |
fvariable a | |
fvariable b | |
fvariable c | |
previous definitions also fdiscriminant | |
\ calculate the discriminant (b^2 - 4ac) | |
: fdiscriminant ( a b c -- n ) | |
c f! b f! a f! | |
b f@ fdup f* a f@ c f@ f* 4e f* f- | |
; | |
previous | |
: solutions? ( a b c -- ) | |
fdiscriminant | |
fdup 0e f= if cr ." 1 solution" fdrop exit then | |
0e f> if cr ." 2 solutions" fdrop exit then | |
cr ." No real solutions" | |
; | |
\ Example usage: | |
\ 9e -12e 4e quadratic solutions? | |
\ 1 solution ok |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment