{"action":"closed","issue":{"url":"https://api.github.com/repos/magnars/dash.el/issues/123","labels_url":"https://api.github.com/repos/magnars/dash.el/issues/123/labels{/name}","comments_url":"https://api.github.com/repos/magnars/dash.el/issues/123/comments","events_url":"https://api.github.com/repos/magnars/dash.el/issues/123/events","html_url":"https://github.com/magnars/dash.el/issues/123","id":60576640,"number":123,"title":"`-fixfn` test hangs on OSX; reveals larger issue of float comparison","user":{"login":"occidens","id":2824087,"avatar_url":"https://avatars.githubusercontent.com/u/2824087?v=3","gravatar_id":"","url":"https://api.github.com/users/occidens","html_url":"https://github.com/occidens","followers_url":"https://api.github.com/users/occidens/followers","following_url":"https://api.github.com/users/occidens/following{/other_user}","gists_url":"https://api.github.com/users/occidens/gists{/gist_id}","starred_url":"https://api.github.com/users/occidens/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/occidens/subscriptions","organizations_url":"https://api.github.com/users/occidens/orgs","repos_url":"https://api.github.com/users/occidens/repos","events_url":"https://api.github.com/users/occidens/events{/privacy}","received_events_url":"https://api.github.com/users/occidens/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-10T22:00:28Z","updated_at":"2015-03-12T17:54:18Z","closed_at":"2015-03-12T17:54:18Z","body":"Here is a interesting problem: I was running the test suite on my Mac, and it hung on the test of `-fixfn`. I then ran the tests in a Linux virtual machine with no problem.\r\n\r\nCloser inspection reveals that there are some subtle platform-specific (or Emacs minor-version-specific?) differences in the floating-point math in the `cos` function. While the fixpoint of `cos` can be *verified* on both systems\r\n\r\n```emacs-lisp\r\n(= (cos 0.7390851332151607) 0.7390851332151607) ;; => t\r\n```\r\n\r\nOn a Mac (tested on `GNU Emacs 24.4.1 x86_64-apple-darwin13.4.0, NS apple-appkit-1265.21`), `-fixfn` never converges on a solution because `cos` oscillates between *0.739&#x2026;8* and *0.739&#x2026;5*.\r\n\r\n```emacs-lisp\r\n(cos (cos 0.7390851332151608)) ;; => 0.7390851332151608\r\n\r\n(cos (cos (cos 0.7390851332151608))) ;; => 0.7390851332151605\r\n\r\n(cos (cos (cos (cos 0.7390851332151608)))) ;; => 0.7390851332151608\r\n```\r\n\r\nOn Linux (tested on `GNU Emacs 24.4.91.1 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.10)`), however, `cos` does converge to the value specified in the test suite.\r\n\r\n```emacs-lisp\r\n(cos (cos 0.7390851332151608)) ;; => 0.7390851332151607\r\n\r\n(cos (cos (cos 0.7390851332151608))) ;; => 0.7390851332151607\r\n\r\n(cos (cos (cos (cos 0.7390851332151608)))) ;; => 0.7390851332151607\r\n```\r\n\r\nAs a temporary solution, I will submit a pull request in a moment for a change to `run-tests.sh` that will allow the test to be skipped.\r\n\r\nTo solve the larger issue, what do you think of the following solution, which would allow the caller of `-fixfn` to account for the specific nature of the function being analyzed?\r\n\r\n-   Modify `-fixfn` to take two addtional optional arguments\r\n    -   an equality test function, which defaults to `equal`, but which could\r\n        be a fuzzy comparison of floats.\r\n    -   an iteration limit function, which defaults to a simple counter\r\n        with a default max value. The caller could alter the max value or\r\n        specify some more sophisticated convergence test.\r\n-   Modify the tests for `-fixfn` so that they use a fuzzy comparsion\r\n    for floating point numbers such as the one given in the Emacs manual\r\n    (with a narrower tolerance)\r\n    \r\n    ```emacs-lisp\r\n    (defvar fuzz-factor 1.0e-15)\r\n    (defun approx-equal (x y)\r\n      (or (= x y)\r\n          (< (/ (abs (- x y))\r\n    \t    (max (abs x) (abs y)))\r\n    \t fuzz-factor)))\r\n    ```\r\n\r\nIf you agree on this approach, I can work on this futher and submit a pull request.\r\n"}}