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

kbandla / dpkt / 513 / 3
100%
master: 100%

Build:
DEFAULT BRANCH: master
Ran 30 Nov 2016 03:59AM UTC
Files 71
Run time 3s
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

30 Nov 2016 03:57AM UTC coverage: 84.986% (-0.03%) from 85.011%
TOXENV=pypy,coveralls

push

travis-ci

obormot
Fixed floating point rounding error in PCAP Writer (#308)

* Fixed floating point rounding error in PCAP Writer

When converting a floating point timestamp into integer seconds and microseconds,
the microsecond component was being calculated by:
1. Using mod 1 to remove the integral component of the timestamp
2. Using round(x,6) to knock the number down to 6 digits of precision
3. Pushing the microseconds into the integral space by multiplying by 10^6
4. Converting to an integer

By rounding and then performing an additional floating point operation (multiplication),
there is a potential for error to be introduced.

For example, say you start with timestamp 1332502747.5209900094 (2012-03-23 11:39:07AM UTC):
1. mod 1 gives you 0.5209900094
2. round(x,6) gives you 0.520990
3. Multiplying by 10^6 then gives you 520989.99999999994 (should be 520990 but floating point error was introduced)
4. Casting to an int truncates the value to 520989
In the end, the error of 6e-11us in step 3 resulted in a 1us error at the end. That's significant.

To fix this, the rounding just needs to be done after the microseconds are shifted into the integral space, giving the following modified procedure:
1. Using mod 1 to remove the integral component of the timestamp
2. Pushing the microseconds into the integral space by multiplying by 10^6
3. round(x,0) to eliminate the the non-integral (consisting of residual precision from the input and floating point error)
4. Converting to an integer

Returning the the previous example, starting with the same input, the new prodedure goes as follows
1. mod 1 gives you 0.5209900094
2. Multiplying by 10^6 then gives you 520990.00939999998
3. round(x,0) gives you 520990.0
4. Casting to an int truncates the value to 520990
We end up with zero error at the end because the 2e-11us error was rounded off

* Made PCAPNG Writer timestamp handling consistent with PCAP

In PCAP Writer, the timestamp is being rounded to the nearest microsecond. PCAPNG Writer was updated to perform that rounding as well.

5887 of 6927 relevant lines covered (84.99%)

0.85 hits per line

Source Files on job 513.3 (TOXENV=pypy,coveralls)
  • Tree
  • List 0
  • Changed 2
  • Source Changed 2
  • Coverage Changed 1
Coverage ∆ File Lines Relevant Covered Missed Hits/Line
  • Back to Build 513
  • Travis Job 513.3
  • efa3c10b on github
  • Prev Job for TOXENV=pypy,coveralls on master (#510.3)
  • Next Job for TOXENV=pypy,coveralls on master (#523.3)
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