config-rs icon indicating copy to clipboard operation
config-rs copied to clipboard

Floats in configuration probably shouldn't round to integers if theres precision loss

Open nagisa opened this issue 3 years ago • 1 comments

Currently when you Config::get an integer and config has a float specified, the config-rs crate will transparently lose the precision, potentially leading to unexpected behaviour. For instance:

frame_rate = 59.94

will transparently round up to 60, potentially giving wrong video. There are probably many more instances where loss of precision can give very invalid results.

I believe the relevant code is probably this line.

I saw a number of FIXMEs in the codebase around not succeeding when integer wraparound occurs. We most likely can utilize something similar here – if converting results in loss of precision, fail.

nagisa avatar Dec 30 '20 15:12 nagisa

Agreed. Also, the crate stores u8 in u64 (and so on), which should be fixed as well (mentioning it here because it falls into the same category of issues).

matthiasbeyer avatar Mar 04 '21 19:03 matthiasbeyer