Rename approx-equal to more accurate approx=

* dev/dash-defs.el (approx-equal): Rename...
(approx=): ...to this, to more accurately reflect its function.
All references changed.

* dev/examples.el (-fixfn): Clean up examples.
* README.md:
* dash.texi: Regenerate docs.
master
Basil L. Contovounesios 5 years ago
parent 41b5681e45
commit cec8c0d685
No known key found for this signature in database
GPG Key ID: 205AB54A5D5D8CFF
  1. 4
      README.md
  2. 4
      dash.texi
  3. 8
      dev/dash-defs.el
  4. 16
      dev/examples.el

@ -2997,9 +2997,9 @@ cdr the final output from `halt-test`.
In types: (a -> a) -> a -> a.
```el
(funcall (-fixfn 'cos 'approx-equal) 0.7) ;; ~> 0.7390851332151607
(funcall (-fixfn #'cos #'approx=) 0.7) ;; ~> 0.7390851332151607
(funcall (-fixfn (lambda (x) (expt (+ x 10) 0.25))) 2.0) ;; => 1.8555845286409378
(funcall (-fixfn 'sin 'approx-equal) 0.1) ;; => (halted . t)
(funcall (-fixfn #'sin #'approx=) 0.1) ;; => (halted . t)
```
#### -prodfn `(&rest fns)`

@ -4527,7 +4527,7 @@ In types: (a -> a) -> a -> a.
@example
@group
(funcall (-fixfn 'cos 'approx-equal) 0.7)
(funcall (-fixfn #'cos #'approx=) 0.7)
@result{} 0.7390851332151607
@end group
@group
@ -4535,7 +4535,7 @@ In types: (a -> a) -> a -> a.
@result{} 1.8555845286409378
@end group
@group
(funcall (-fixfn 'sin 'approx-equal) 0.1)
(funcall (-fixfn #'sin #'approx=) 0.1)
@result{} (halted . t)
@end group
@end example

@ -35,14 +35,14 @@ EXPECTED should be the result of evaluating ACTUAL, and OP is one
of the following comparison operators:
- `=>' ACTUAL should be `equal' to EXPECTED.
- `~>' ACTUAL should be `approx-equal' to EXPECTED.
- `~>' ACTUAL should be `approx=' to EXPECTED.
- `!!>' ACTUAL should signal the EXPECTED error,
either an error symbol or an error object.")
(defvar dash--epsilon 1e-15
"Epsilon used in `approx-equal'.")
"Epsilon used in `approx='.")
(defun approx-equal (u v)
(defun approx= (u v)
"Like `=', but compares floats within `dash--epsilon'.
This allows approximate comparison of floats to work around
differences in implementation between systems. Used in place of
@ -56,7 +56,7 @@ differences in implementation between systems. Used in place of
"Return an ERT assertion form based on EXAMPLE."
(pcase example
(`(,actual => ,expected) `(should (equal ,actual ,expected)))
(`(,actual ~> ,expected) `(should (approx-equal ,actual ,expected)))
(`(,actual ~> ,expected) `(should (approx= ,actual ,expected)))
(`(,actual !!> ,(and (pred symbolp) expected))
;; FIXME: Tests fail on Emacs 24-25 without `eval' for some reason.
`(should-error (eval ',actual ,lexical-binding) :type ',expected))

@ -21,7 +21,7 @@
;; so make those good.
;;
;; Use the `~>' symbol instead of `=>' to test the expected and actual
;; values with `approx-equal'.
;; values with `approx='.
;;; Code:
@ -1710,12 +1710,14 @@ for historical reasons, and will soon be absorbed by `dash'."
(-last-item (-iterate fn init (1+ 5)))))) => t)
(defexamples -fixfn
;; Find solution to cos(x) = x (may not converge without fuzzy comparison)
(funcall (-fixfn 'cos 'approx-equal) 0.7) ~> 0.7390851332151607
;; Find solution to x^4 - x - 10 = 0 (converges using 'equal comparison)
(funcall (-fixfn (lambda (x) (expt (+ x 10) 0.25))) 2.0) => 1.8555845286409378
;; The sin function has a fixpoint at zero, but it converges too slowly and is halted
(funcall (-fixfn 'sin 'approx-equal) 0.1) => '(halted . t))
;; Solve cos(x) = x (may not converge without fuzzy comparison).
(funcall (-fixfn #'cos #'approx=) 0.7) ~> 0.7390851332151607
;; Solve x^4 - x - 10 = 0 (converges using `equal' comparison).
(funcall (-fixfn (lambda (x) (expt (+ x 10) 0.25))) 2.0)
=> 1.8555845286409378
;; The sin function has a fixpoint at zero, but it converges too
;; slowly and is halted.
(funcall (-fixfn #'sin #'approx=) 0.1) => '(halted . t))
(defexamples -prodfn
(funcall (-prodfn '1+ '1- 'number-to-string) '(1 2 3)) => '(2 1 "3")

Loading…
Cancel
Save