-
Notifications
You must be signed in to change notification settings - Fork 18
Description
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);