Skip to content

Issue Check failed: fabs(num_samples_count - *total_samples_per_channel) <= kErrorTolerance #39

@carlmarc

Description

@carlmarc

Related to Issue CHECK_LE(processed_seg_length, total_samples)

The problems still persists at different part. It is a matter of precision with doubles.
in my case having a file with length 7866720 samples (18 channels if matters), processed_seg_length stores 7866719.
const auto processed_seg_length = std::floor(this_seg_length);
this_seg_length as double should store 7866720, but a double seems to store 7866719.99999999906867742538,
Therefore when doing std::floor just takes 7866719.
One curiossity is that printing:

LOG(INFO) << "*** this_seg_length: " << this_seg_length;
LOG(INFO) << "*** setprecision this_seg_length: " << std::fixed << std::setprecision(20)
          << "this_seg_length = " << processed_seg_length;
LOG(INFO) << "*** processed_seg_length: " << processed_seg_length;
LOG(INFO) << "*** setprecision processed_seg_length: " << std::fixed << std::setprecision(20)
          << "processed_seg_length = " << processed_seg_length;
LOG(INFO) << "*** type processed_seg_length: " << typeid(processed_seg_length).name();
      
LOG(INFO) << "*** num_samples_count: " << num_samples_count;

it outputs:

*** this_seg_length: 7.86672e+06
*** setprecision this_seg_length: this_seg_length = 7866719.99999999906867742538
*** processed_seg_length: 7.86672e+06
*** setprecision processed_seg_length: processed_seg_length = 7866719.00000000000000000000
*** type processed_seg_length: d
*** num_samples_count: 7866719

then
Check failed: fabs(num_samples_count - *total_samples_per_channel) <= kErrorTolerance (1.84467e+19 vs. 1e-05)

So far I use the following line to solve the issue:
const auto processed_seg_length = static_cast<size_t>(std::round(this_seg_length));
instead of:
const auto processed_seg_length = std::floor(this_seg_length);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions