Fix fractional calculation for frequencies close to integer multiples

This commit is contained in:
Jan Käberich 2021-11-13 19:32:58 +01:00
parent b3cc97c0c9
commit e0c9f4dcee
2 changed files with 12 additions and 2 deletions

View file

@ -190,6 +190,14 @@ bool MAX2871::SetFrequency(uint64_t f) {
auto approx = Algorithm::BestRationalApproximation(fraction, 4095);
if (approx.denom == approx.num) {
// got an impossible result due to floating point limitations(?)
// Set fractional part to zero, increase integer part instead
approx.num = 0;
approx.denom = 2;
N++;
}
if(approx.denom == 1) {
// M value must be at least 2
approx.denom = 2;