-
Notifications
You must be signed in to change notification settings - Fork 199
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
Infinity, Negative Infinity, and Not a Number output values #108
Comments
Handling of standard C NaN and Inf will be always better and easier for programmers, so this change is welcome. Just some hints, floating point support is problematic for me, because every architecture and compiler impleents them differently. Yes, there is C standard and an IEEE 754 but not all parts are mandatory and not all compilers obey them. And there is IEEE 488 and SCPI defining something different or some subset. So, please, take this into account. I have created some macros to test nans and infs in the past (useing native support or fallback to naive implementation). Please, use them or extend/fix them as needed. Please use native compilers definitions of NaN an Inf where possible and not some single precision constants defined in SCPI. I would like to support double precision numbers even if they are not defined in SCPI. Please also take into account, that it should work on e.g. 8-bit AVR, where in AVRGCC only float exists (doube is mapped to float), it should be agnostic to Little and Big endian architectures and it should be possible to exted the support to some other compilers, like C compilers for PIC16/24, proprietary compilers for ARM, NI LabWindows/CVI, MS Visual C etc. |
Wow, this sounds like a much bigger task than I had originally imagined. I was simply thinking I could change the SCPI_dtostre function (here) to return floats instead of "NAN" and "INF". You've alerted me to the fact that there are systems that don't use that function. However, looking at it again, it seems that I could still simply insert a comparison into each of the SCPI_FloatToStr and SCPI_DoubleToStr functions to compare the float value against INF or NAN, and short circuit the function when these values are found by returning the appropriate string for each value (i.e. "9.9e+37", "-9.9e+37", and 9.91e+37"). So the implementation of SCPI_DoubleToStr would look like this:
Would this do it, or am I missing something? |
It seems that it is not so easy.
|
According to the SCPI specification, Infinity, Negative Infinity, and Not a Number each have special floating point values which should be returned to the user, however the parser will return strings of "INF" or "NAN" (minus the quotes) in these cases. Is this intentional, or would you agree that this is incorrect with respect to the standard? (See section 7.2.1.4 of the SCPI-99 standard specification)
@j123b567, if you agree, I can create a pull request to fix this issue, however this may be considered a breaking change since current users are likely parsing the output for INF or NAN to determine these special cases rather than the 9.9e+37, -9.9e+37, and 9.91e+37 special values defined by the standard. For my customers, we have determined that the special float values would be better, probably for the same reason the standard specifies them, which is that the return value can always be parsed as a double, making the programming easier for our customers.
Feedback would be much appreciated!
The text was updated successfully, but these errors were encountered: