[m-rev.] for review: mercury implementation of string__format

Fergus Henderson fjh at cs.mu.OZ.AU
Thu Nov 14 03:42:41 AEDT 2002


On 13-Nov-2002, Peter Ross <pro at missioncriticalit.com> wrote:
> Add an implementation of string__format in Mercury for use on backends
> which don't support sprintf.
> 
> library/string.m:
> 	Mercury implemenation of string__format.
> 
> tests/general/string_format_e.m:
> tests/general/string_format_f.m:
> tests/general/string_format_g.m:
> tests/general/string_format_e.exp:
> tests/general/string_format_g.exp:
> 	Change the floating pointing test cases to test -Inf and +Inf
> 	more consistently.

You don't seem to have posted the diffs for the *.exp* files.

BTW, can you explain why the -max*max tests added in your previous commit
(for which the relative diff was not posted for review) were coming out
as NaN rather than -Inf?  Isn't that a bug?

> +:- pred is_denormal(string :: in) is semidet.
> +is_denormal("NaN").
> +is_denormal("Inf").

That is not what "denormal" means.
"denormal" has a precise meaning which is quite different.  (See e.g.
<http://music.calarts.edu/~glmrboy/musicdsp/musicdspFAQ.dsp.html#ct13>.)
So the name of this predicate should be changed.

The C standard allows infinity to be output as "Infinity" as well as "Inf",
so this code should probably check for that too.

> :- func convert_float_to_string(float) = string.
> convert_float_to_string(Float) = String :-
>       FloatStr = string__float_to_string(Float),
>	...

This code is relying on properties of string__float_to_string which are not
documented, and which do not hold for all implementations of
string__float_to_string.  In particular they do not hold for the C
implementation, because string__float_to_string only outputs
15 decimal digits of precision, but some floats need 17, and
this code is assuming that the output is fully precise.

The properties which it is relying on should be documented,
either in the documentation for string__float_to_string,
or in an XXX comment here, depending on what kind of assumptions
they are.

> tests/general/string_format_f.exp2:
> 	We will only get the 15 most significant digits when printing
> 	float__max using mercury, this means the output is different
> 	to using sprintf which prints all the digits.

There should be some tests that writing out floats with 17 digits
precision and reading them back in again results in the same values.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list