Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of floating point unnecessary #6

Open
danak6jq opened this issue Jan 23, 2015 · 0 comments
Open

Use of floating point unnecessary #6

danak6jq opened this issue Jan 23, 2015 · 0 comments

Comments

@danak6jq
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant