The string representation of float special values is currently dependent on the
target language and, for C grades, the underlying platform. As a result,
values like NaN and Infinity are being printed or converted into strings in
variety of ways. (See, for example bug #348 in Mantis.)
This diff changes float->string conversion to detect float special values and
use a consistent string representation for them.
library/string.m:
library/io.m:
runtime/mercury_float.c:
Check if a float is not-a-number or of infinite magnitude when converting
floats into strings. If so, then use a standard representation of the
value: "nan" for not-a-number values, and "infinity" / "-infinity" for
values of infinite magnitude.
For uppercase conversion specifiers in format strings, we output the above
strings in uppercase (e.g. "NAN", "INFINITY").
library/float.m:
Add is_infinite/1 and is_nan_or_infinite/1 as synonyms for is_inf/1 and
is_nan_or_inf/1 respectively.
Group float classification predicates into their own section. Upcoming
change will add more of them.
NEWS:
Announce the above changes.
tests/general/string_format_special_floats.m:
tests/general/string_format_special_floats.exp:
Modify this test to check that we actually print float special values as
above.
tests/hard_coded/write_float_special.exp:
Conform to the above change.
tests/EXPECT_FAIL_TESTS.all_grades:
Do not expect the write_float_special test case to fail any more since
the expected outputs should be the same on every platform.
runtime/mercury_float.c:
When printing floats, do not append ".0" to nan, inf or -inf.
tests/hard_coded/Mmakefile:
tests/hard_coded/write_float_special.{m,exp,exp2}:
Add a regression test for the above.
NEWS:
Announce the above.