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

Float and double conversions when logging #29

Open
anjohnson opened this issue Jun 3, 2024 · 0 comments
Open

Float and double conversions when logging #29

anjohnson opened this issue Jun 3, 2024 · 0 comments
Labels
bug Something isn't working codeathon Task suitable for an EPICS Codeathon

Comments

@anjohnson
Copy link
Member

Another bug we've found at APS which I was planning to fix when I have time: The code here for both JSON and old-style logs uses the simple printf() format string "%g" to convert both double and float values. This loses precision for doubles at least, which matters for some applications.

The yajl JSON generator uses "%.17g" for converting doubles and appends ".0" if the resulting string only contains digits and/or a minus sign, which may be necessary for strict JSON. We don't care about the old-style logging format, but we do want the JSON output fixed.

This is the code used by yajl_gen:

sprintf(i, "%.17g", number);
if (strspn(i, "0123456789-") == strlen(i)) {
    strcat(i, ".0");
}

The caPutLog code has already handled ±Infinity and NaN values so they never get to the fieldVal2Str() routine.

@anjohnson anjohnson added bug Something isn't working codeathon Task suitable for an EPICS Codeathon labels Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working codeathon Task suitable for an EPICS Codeathon
Projects
None yet
Development

No branches or pull requests

1 participant