diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2025-04-06 22:25:14 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2025-04-06 22:25:14 -0700 |
commit | ee37e03ec9f91e0938c4bc4eb6d03156f75c7405 (patch) | |
tree | 7486739c06045eb82f2cb6eeaadc1a7e9ae9cb9b | |
parent | 6feec15b59de91e753e0ab55e748c2ec6192b80a (diff) | |
download | txr-ee37e03ec9f91e0938c4bc4eb6d03156f75c7405.tar.gz txr-ee37e03ec9f91e0938c4bc4eb6d03156f75c7405.tar.bz2 txr-ee37e03ec9f91e0938c4bc4eb6d03156f75c7405.zip |
infix: add quadratic-roots test
* tests/012/infix.tl (quadractic-roots): New function.
Add couple of tests.
* txr.1: Add quadratic-roots as example to ifx macro.
-rw-r--r-- | tests/012/infix.tl | 10 | ||||
-rw-r--r-- | txr.1 | 14 |
2 files changed, 24 insertions, 0 deletions
diff --git a/tests/012/infix.tl b/tests/012/infix.tl index c619db18..79767f31 100644 --- a/tests/012/infix.tl +++ b/tests/012/infix.tl @@ -65,3 +65,13 @@ (x ** a[i][j][k] ++) (expt x (pinc [[[a i] j] k])) (x ** -- a[i][j][k]) (expt x (dec [[[a i] j] k])) (x ** -- a[i + y][j ++][-- k]) (expt x (dec [[[a i + y] j ++] -- k]))) + +(ifx + (defun quadratic-roots (a b c) + (let ((d (sqrt b * b - 4 * a * c))) + (list ((- b + d) / 2 * a) + ((- b - d) / 2 * a))))) + +(mtest + (quadratic-roots 1 0 -4) (2.0 -2.0) + (quadratic-roots 1 2 1) (-1.0 -1.0)) @@ -54327,6 +54327,20 @@ continues to apply, infix subexpressions produced by .code parse-infix are recursively detected and expanded. +.TP* Example + +Calculate the roots of a quadratic formula, when real: + +.verb + (ifx + (defun quadratic-roots (a b c) + (let ((d (sqrt b * b - 4 * a * c))) + (list ((- b + d) / 2 * a) + ((- b - d) / 2 * a))))) + + (quadratic-roots 1 0 -4) -> (2.0 -2.0) + (quadratic-roots 1 2 1) -> (-1.0 -1.0) +.brev .SS* Enumerated Constants The enumerated constants module provides ways for defining |