NT7S / Si5351

Library for the Si5351 clock generator IC in the avr-gcc environment
GNU General Public License v3.0
34 stars 11 forks source link

Use of floating point unnecessary #6

Open danak6jq opened 9 years ago

danak6jq commented 9 years ago

From pll_calc():

/* Factor calibration value into nominal crystal frequency */
/* Measured in parts-per-ten million */
ref_freq += (uint32_t)((double)(correction / 10000000.0) * (double)ref_freq)

Fixed-point is perhaps more precise, using a "long long" aka int64_t:

/* Factor calibration value into nominal crystal frequency */
/* Measured in parts-per-ten million */
ref_freq += (int32_t) ((((((int64_t)correction) << 31) /
    10000000LL) * ref_freq) >> 31);

Resulting linked binaries aren't that different in size (depending on optimization level in use). Your mileage may vary.