mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-04-15 17:33:38 +00:00
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.
22 lines
579 B
Plaintext
22 lines
579 B
Plaintext
Plus Infinity:
|
|
%e: infinity
|
|
%f: infinity
|
|
%g: infinity
|
|
%E: INFINITY
|
|
%F: INFINITY
|
|
%G: INFINITY
|
|
Minus Infinity:
|
|
%e: -infinity
|
|
%f: -infinity
|
|
%g: -infinity
|
|
%E: -INFINITY
|
|
%F: -INFINITY
|
|
%G: -INFINITY
|
|
Not a number:
|
|
%e: nan
|
|
%f: nan
|
|
%g: nan
|
|
%E: NAN
|
|
%F: NAN
|
|
%G: NAN
|