{"id":26937312,"url":"https://github.com/predictiveecology/fpcompare","last_synced_at":"2025-04-02T13:15:08.769Z","repository":{"id":29785561,"uuid":"33329714","full_name":"PredictiveEcology/fpCompare","owner":"PredictiveEcology","description":"Reliable comparison of floating point numbers in R","archived":false,"fork":false,"pushed_at":"2024-11-25T22:57:05.000Z","size":219,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-25T23:31:58.321Z","etag":null,"topics":["r-package"],"latest_commit_sha":null,"homepage":"http://fpcompare.predictiveecology.org","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/PredictiveEcology.png","metadata":{"files":{"readme":"README.md","changelog":"NEWS.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-04-02T20:15:04.000Z","updated_at":"2024-03-06T18:13:55.000Z","dependencies_parsed_at":"2024-11-26T00:15:16.724Z","dependency_job_id":null,"html_url":"https://github.com/PredictiveEcology/fpCompare","commit_stats":{"total_commits":131,"total_committers":3,"mean_commits":"43.666666666666664","dds":"0.14503816793893132","last_synced_commit":"a0260b8476b06628bba0ae73af3430cce9620ca0"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PredictiveEcology%2FfpCompare","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PredictiveEcology%2FfpCompare/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PredictiveEcology%2FfpCompare/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PredictiveEcology%2FfpCompare/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PredictiveEcology","download_url":"https://codeload.github.com/PredictiveEcology/fpCompare/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246819771,"owners_count":20839095,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["r-package"],"created_at":"2025-04-02T13:15:07.772Z","updated_at":"2025-04-02T13:15:08.750Z","avatar_url":"https://github.com/PredictiveEcology.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fpCompare\n\n\u003c!-- badges: start --\u003e\n[![R build status](https://github.com/PredictiveEcology/fpCompare/workflows/R-CMD-check/badge.svg)](https://github.com/PredictiveEcology/fpCompare/actions)\n[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/fpCompare)](https://CRAN.R-project.org/package=fpCompare)\n[![Downloads](http://cranlogs.r-pkg.org/badges/grand-total/fpCompare)](https://CRAN.R-project.org/package=fpCompare)\n[![DOI](https://zenodo.org/badge/17892/PredictiveEcology/fpCompare.svg)](https://zenodo.org/badge/latestdoi/17892/PredictiveEcology/fpCompare)\n[![Codecov test coverage](https://codecov.io/gh/PredictiveEcology/fpCompare/branch/master/graph/badge.svg)](https://app.codecov.io/gh/PredictiveEcology/fpCompare?branch=master)\n\u003c!-- badges: end --\u003e\n\n## Reliable comparison of floating point numbers\n\nComparisons of floating point numbers are problematic due to errors associated with the binary representation of decimal numbers. Computer scientists and programmers are aware of these problems and yet people still use numerical methods which fail to account for floating point errors (this pitfall is the first to be highlighted in Circle 1 of Burns (2012) [The R Inferno](https://www.burns-stat.com/pages/Tutor/R_inferno.pdf)).\n\nTo avoid these and other numerical rounding issues, R's help file for relational operators (*e.g.*, `?'\u003e'`) suggests using `identical` and `all.equal` when making numerical comparisons:\n\n```r\nx1 \u003c- 0.5 - 0.3\nx2 \u003c- 0.3 - 0.1\nx1 == x2                           # FALSE on most machines\nidentical(all.equal(x1, x2), TRUE) # TRUE everywhere\n```\n\nInspired by [R FAQ 7.31](https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f) and [this Stack Overflow answer](https://stackoverflow.com/a/2769618/1380598), this package provides new relational operators useful for performing floating point number comparisons with a set tolerance:\n\n**`fpCompare`**[^1] | **`base`**\n--------------------|-----------\n`%\u003e=%`              | `\u003e=`\n`%\u003e\u003e%`              | `\u003e`\n`%\u003c=%`              | `\u003c=`\n`%\u003c\u003c%`              | `\u003c`\n`%==%`              | `==`\n`%!=%`              | `!=`\n\nThese functions use the `base` relational operators to make comparisons, but incorporate a tolerance value (`fpCompare.tolerance`) similar to `all.equal`. The default `fpCompare.tolerance` value is `.Machine$double.eps^0.5`, set via `options`. This is the same default used in `all.equal` for numeric comparisons.\n\n```r\n# set telorance value\ntol = .Machine$double.eps^0.5       # default value\noptions(fpCompare.tolerance = tol)\n\n# perform comparisons\nx1 \u003c- 0.5 - 0.3\nx2 \u003c- 0.3 - 0.1\nx1 == x2         # FALSE on most machines\nx1 %==% x2       # TRUE everywhere\n```\n\n[^1]: The `%\u003c\u003c%` and `%\u003e\u003e%` symbols are used instead of `%\u003c%` and `%\u003e%` to avoid a conflict with `magrittr`'s pipe operator (`%\u003e%`).\n\n# Installation\n\n## From CRAN\n\n```r\ninstall.packages(\"fpCompare\")\n```\n\n## From GitHub\n\n```r\nlibrary(devtools)\ninstall_github(\"PredictiveEcology/fpCompare\")\n```\n\n# Bug Reports\n\n[https://github.com/PredictiveEcology/fpCompare/issues](https://github.com/PredictiveEcology/fpCompare/issues)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpredictiveecology%2Ffpcompare","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpredictiveecology%2Ffpcompare","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpredictiveecology%2Ffpcompare/lists"}