MITHaystack / digital_rf

Read, write, and interact with data in the Digital RF and Digital Metadata formats
Other
102 stars 31 forks source link

Use integer math only, dropping use of long double sample rate #20

Open ryanvolz opened 4 years ago

ryanvolz commented 4 years ago

This does away with use of long doubles for calculations with the sample rate. In the C library, this was used in digital_rf_get_subdir_file to determine file names and sample bounds. The np.longdouble sample rate was similarly used in the Python library to get the list of files containing a given sample index range.

The reason for this change is that not all platforms support long doubles with at least a 64-bit mantissa. This caused at least one bug on the aarch64 platform which resulted in incorrect file bounds from digital_rf_get_subdir_file. By using integer math that is implemented uniformly on all platforms, any bugs in the calculation should be more noticeable.

This commit also adds two new functions to the C API: digital_rf_get_timestamp_floor and digital_rf_get_sample_ceil. These are now used to do the file sample bound calculations, and they are exposed so that users of the library can perform these calculations in a way that is consistent with what is done internally. These functions have also been exposed in the Python binding, and a test that verifies that the sample index round-trips through them is included in the Python testing suite.

Because of the added C functions, the library version has been bumped to 2.7, which means the next release of Digital RF will be 2.7.0.