• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

d-meiser / cgreen / 60
96%
master: 96%

Build:
Build:
LAST BUILD BRANCH: double_comparison_corrections
DEFAULT BRANCH: master
Ran 01 Nov 2017 02:21AM UTC
Jobs 2
Files 73
Run time 17s
Badge
Embed ▾
README BADGES
x

If you need to use a raster PNG badge, change the '.svg' to '.png' in the link

Markdown

Textile

RDoc

HTML

Rst

pending completion
60

push

travis-ci

d-meiser
Fix for double comparisons.

* Introduce an absolute tolerance.
* Improve implementation of accuracy function to avoid casting and make the
  logic more transparent.
* Add a test case.
* Minor cosmetic changes (e.g. renamed a test case).

Discussion

The introduction of an absolute tolerance fixes the underflow issues near 0. If
two numbers are within the absolute tolerance of one another they are considered
equal and we don't need to evaluate the problematic accuracy function. We choose
an absolute tolerance that is 10^8 times larger than the smallest double number
that can be represented. Eight is the default number of significant digits used
for relative comparisons. This prevents underflow issues when comparing numbers
near zero for the default number of significant digits.

Note that our default cannot prevent underflow if the user increases the number
of significant digits to a value larger than eight. doubles_are_equal will not
crash in this case but it may wrongly report two numbers as equal. The
problematic cases are numbers near zero.

The only general solution for the underflow problem is to expose a function to
let the user set the absolute tolerance. This would have to be accompanied by
documentation of the complicated floating point comparison issues. I doubt that
many users will find this useful.

In my opinion a better solution is to have an additional comparison function
that explicitly takes the absolute tolerance, something like

bool doubles_are_close(double tried, double expected, double tolerance);

5368 of 5586 relevant lines covered (96.1%)

194375.88 hits per line

Jobs
ID Job ID Ran Files Coverage
1 60.1 (CGREEN_WITH_STATIC_LIBRARY="OFF") 01 Nov 2017 02:21AM UTC 0
96.1
Travis Job 60.1
2 60.2 (CGREEN_WITH_STATIC_LIBRARY="ON") 01 Nov 2017 02:21AM UTC 0
96.1
Travis Job 60.2
Source Files on build 60
Detailed source file information is not available for this build.
  • Back to Repo
  • Travis Build #60
  • a12f40b9 on github
  • Prev Build on double_comparison_corrections (#55)
  • Next Build on double_comparison_corrections (#61)
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc