[m-rev.] diff: broken generic string_to_float
Peter Wang
novalazy at gmail.com
Mon Mar 7 13:29:23 AEDT 2011
Branches: main, 11.01
library/string.m:
Revert a bad change to the generic implementation of
`string.float_to_string' intended to trim redundant trailing zeros.
However, it also trimmed digits from the exponent!
e.g. "1e-10" to "1e-1"
(C, C# and Java backends have their own foreign_procs)
diff --git a/library/string.m b/library/string.m
index 8ab5454..1f25dc8 100644
--- a/library/string.m
+++ b/library/string.m
@@ -3658,7 +3658,7 @@ string.float_to_string(Float, unsafe_promise_unique(String)) :-
% XXX The unsafe_promise_unique is needed because in
% string.float_to_string_2 the call to string.to_float doesn't
% have a (ui, out) mode hence the output string cannot be unique.
- String = trim_float_string(string.float_to_string_2(min_precision, Float)).
+ String = string.float_to_string_2(min_precision, Float).
:- func string.float_to_string_2(int, float) = (string) is det.
@@ -3858,34 +3858,6 @@ string.det_to_float(FloatString) =
end
").
- % Trim redundant trailing zeroes from the fractional part of the
- % string representation of a float.
- %
-:- func trim_float_string(string) = string.
-
-trim_float_string(FloatStr0) = FloatStr :-
- L = string.length(FloatStr0),
- N = count_extra_trailing_zeroes(FloatStr0, L - 1, 0),
- FloatStr = string.left(FloatStr0, L - N).
-
-:- func count_extra_trailing_zeroes(string, int, int) = int.
-
-count_extra_trailing_zeroes(FloatStr, I, N0) = N :-
- ( if I < 0 then
- N = N0
- else
- C = FloatStr ^ elem(I),
- ( if C = ('0') then
- N = count_extra_trailing_zeroes(FloatStr, I - 1, N0 + 1)
- else if C = ('.') then
- N = int.max(N0 - 1, 0)
- else if char.is_digit(C) then
- N = N0
- else
- N = 0
- )
- ).
-
/*-----------------------------------------------------------------------*/
% strchr always returns true when searching for '\0',
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list