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

d-meiser / cgreen / 61 / 2
96%
master: 96%

Build:
Build:
LAST BUILD BRANCH: double_comparison_corrections
DEFAULT BRANCH: master
Ran 02 Nov 2017 03:01AM UTC
Files 73
Run time 2s
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

02 Nov 2017 02:53AM UTC coverage: 96.201% (+0.1%) from 96.097%
CGREEN_WITH_STATIC_LIBRARY="ON"

push

travis-ci

d-meiser
Fix double comparisons for small numbers

* Introduce an absolute tolerance.
* Improve implementation of accuracy function to avoid casting and make the
  logic more transparent.
* Add discussion of floating point comparisons to manual.
* Add a test case.
* Minor cosmetic changes (e.g. renamed a test case).
* Remove a test case that compares a small number with 0 because this is
  expected behavior.

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.

We have added a discussion of our floating point comparison algorithm to the
manual. We point out the problems that can occur when comparing numbers close to
zero and we propose to use constraints of the form

assert_that_double(fabs(x - y), is_less_than_double(abs_tolerance));

in that case.

5368 of 5580 relevant lines covered (96.2%)

97404.65 hits per line

Source Files on job 61.2 (CGREEN_WITH_STATIC_LIBRARY="ON")
  • Tree
  • List 0
  • Changed 14
  • Source Changed 2
  • Coverage Changed 14
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Build 61
  • Travis Job 61.2
  • 5b40aa6a on github
  • Prev Job for CGREEN_WITH_STATIC_LIBRARY="ON" on double_comparison_corrections (#60.2)
  • Next Job for CGREEN_WITH_STATIC_LIBRARY="ON" on double_comparison_corrections (#62.2)
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