[m-rev.] for review: fix float_to_string so that roundtripping works

Peter Ross pro at missioncriticalit.com
Wed Nov 20 05:13:25 AEDT 2002


fjh wrote:
> > +#ifdef MR_USE_SINGLE_PREC_FLOAT
> > + const char *format_a = ""%.7g"";
> > + const char *format_b = ""%.9g"";
> > + const char *format_r = ""%f"";
> > + float round;
> > +#else
> > + const char *format_a = ""%.15g"";
> > + const char *format_b = ""%.17g"";
> > + const char *format_r = ""%lf"";
> > + double round;
> > +#endif
>
> I'd be tempted to do
>
> MR_Float round;
>
> outside the #ifdef.
>
> The way we actually read floats (string__to_float, etc.)
> is to scan them in to a double using "%lf", and then
> assign this double to a value of type MR_Float.
> In the MR_USE_SINGLE_PREC_FLOAT case, this may produce different results
> than scanning in directly as a float.  The code here should match
> the technique used in string__to_float.  (Add comments mentioning this
> in both places.)
>
Why not instead change to code in string__to_float to match the behaviour I
implemented?  What is the advantage of reading it in as a double first?  To
me it seems worse that we use single precision floats everywhere, except for
reading them in and that could lead to slightly different behaviour.  I
would prefer to be consistently use single precision floats everywhere.

> > -:- pragma foreign_proc("MC++",
> > +:- pragma foreign_proc("C#",
> >  string__float_to_string(FloatVal::in, FloatString::uo),
> >  [will_not_call_mercury, promise_pure, thread_safe], "{
> > - FloatString = System::Convert::ToString(FloatVal);
> > + FloatString = FloatVal.ToString(""R"");
> >  }").
>
> What's that for?
>
> That change was not mentioned in the log message,
> and is not acceptable without some rationale.
> Also, it would help to document what the "R" argument to ToString() means.
>
The R option outputs the float in a format such that it will roundtrip, so
we don't need to jump through the hoops that we need to for the C backend.
In fact this is what gave me the idea for how to solve the problem in the
first place.  I will add a line to the log message and comment the meaning o
f the R option.


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.419 / Virus Database: 235 - Release Date: 11/13/2002

--------------------------------------------------------------------------
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