Mercury Bugs - mercury
View Issue Details
0000348mercuryBugpublic2014-07-18 15:072015-07-08 13:15
Reporterjuliensf 
Assigned Tojuliensf 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0000348: Failure of tests/general/string_format_special_floats with MSVC
DescriptionWhen using MSVC as a C compiler, the test case tests/general/string_format_special_float fails as the MS libc doesn't appear to
implement the C99 behaviour for printing nan, inf etc.

With VS2012 we get:

Plus Infinity:
                  %e: failure '1.#INF00
                  %f: failure '1.#INF00
                  %g: failure '1.#INF'
                  %E: failure '1.#INF00
                  %F: failure ''
                  %G: failure '1.#INF'
Minus Infinity:
                  %e: failure '-1.#INF0
                  %f: failure '-1.#INF0
                  %g: failure '-1.#INF'
                  %E: failure '-1.#INF0
                  %F: failure ''
                  %G: failure '-1.#INF'
Not a number:
                  %e: failure '-1.#IND0
                  %f: failure '-1.#IND0
                  %g: failure '-1.#IND'
                  %E: failure '-1.#IND0
                  %F: failure ''
                  %G: failure '-1.#IND'

We should probably check for special float values before calling sprintf
and just handle them directly using Mercury. (This would also avoid some
inconsistencies in the output of these tests due to do differences in C
libraries.)
TagsNo tags attached.
Attached Files

Notes
(0000747)
juliensf   
2014-07-18 15:46   
The same problem also affects tests/hard_coded/write_float_special.
(0000748)
wangp   
2014-07-18 16:23   
For what it's worth, NaNs were printed on AIX as "NaNQ", where 'Q' stands for quiet.
(0000750)
juliensf   
2014-07-18 17:01   
C99 says they should be printed as: nan, -nan, nan(...) or -nan(...) where "..." is an implementation-defined sequence of letters, digits or underscores. (Or in uppercase if %F is used.)
(0000755)
juliensf   
2014-08-06 10:37   
I intend to address this one by checking for, and handling, inf and nan (although nan should really cause an exception to be thrown) in Mercury rather than relying on sprintf. Even with C99 there are too many annoying little differences in how inf and nan are handled. Dealing with Java and C# just complicates things further.
(0000838)
juliensf   
2015-07-08 13:15   
Fixed in commit 4e15777.

Issue History
2014-07-18 15:07juliensfNew Issue
2014-07-18 15:46juliensfNote Added: 0000747
2014-07-18 16:23wangpNote Added: 0000748
2014-07-18 17:01juliensfNote Added: 0000750
2014-08-06 10:37juliensfNote Added: 0000755
2014-08-06 10:37juliensfAssigned To => juliensf
2014-08-06 10:37juliensfStatusnew => assigned
2015-07-08 13:15juliensfNote Added: 0000838
2015-07-08 13:15juliensfStatusassigned => resolved
2015-07-08 13:15juliensfResolutionopen => fixed