[m-rev.] for review: fix float_to_string so that roundtripping works
Fergus Henderson
fjh at cs.mu.OZ.AU
Thu Nov 21 04:20:04 AEDT 2002
On 20-Nov-2002, Peter Ross <pro at missioncriticalit.com> wrote:
> +++ library/string.m 20 Nov 2002 16:42:19 -0000
> @@ -1826,45 +1826,21 @@
> :- pragma foreign_proc("C",
> string__float_to_string(Flt::in, Str::uo),
> [will_not_call_mercury, promise_pure, thread_safe], "{
> + char buf[ML_SPRINTF_FLOAT_BUF_SIZE];
> + ML_sprintf_float(buf, Flt);
> + MR_make_aligned_string(Str, buf);
That needs to be MR_make_aligned_string_copy().
> +:- pragma foreign_code(c, "
> +void
> +ML_sprintf_float(char *buf, MR_Float f)
> +{
> + MR_Float round;
> + int i = ML_MIN_PRECISION;
> +
> + do {
> + sprintf(buf, ""%#.*g"", i, f);
> + if (i >= ML_MAX_PRECISION) {
> + /*
> + ** This should be sufficient precision to
> + ** round-trip any value. Don't bother checking
> + ** whether it can actually be round-tripped,
> + ** since if it can't, this is a bug in the C
> + ** implementation.
> + */
> + break;
> + }
> + sscanf(buf, ML_FMT, &round);
> + i++;
> + } while (round != f);
> +}
> +").
This routine should be documented.
Otherwise the interdiff looks good.
But I'd like to double-check the full diff.
--
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