[m-rev.] for review: Java implementation of string library

James Goddard goddardjames at yahoo.com
Fri Dec 12 12:29:19 AEDT 2003


 --- Peter Ross <pro at missioncriticalit.com> wrote: >
On Thu, Dec 11, 2003 at 06:06:23PM +1100, James
> Goddard wrote:
> > +:- pragma foreign_proc("Java",
> > +	string__lowlevel_float_to_string(FloatVal::in,
> FloatString::uo),
> > +	[will_not_call_mercury, promise_pure,
> thread_safe],
> > +"
> > +	FloatString =
> java.lang.Double.toString(FloatVal);
> > +").
> > +
> 
> One thing to be aware of here is that the string
> generated by this
> predicate must be round-trippable, i.e. when
> converting the string back
> to a float one gets exactly the same floating point
> number.
> 
> Have you checked this?
> 

Yes, this is the case.  The Java API promises that
Double.toString() will return a string with "...as
many, more digits as are needed to uniquely
distinguish the argument value from adjacent values of
type double."  Also, Double.parseDouble() (which
string__to_float/2 uses) parses strings of the format
which toString() uses.

I've also checked that it round-trips a few values.
(pi, e, pi+epsilon)

However it doesn't work the other way around - that
is, it is possible to convert a string to a float and
then convert back to a string and get a different
string.
For example, both "+1" and "1" will convert to the
same floating point number, as will "0.5" and "0.50".

I assume this is ok?  Otherwise float_to_string will
need to be modified to accept a stricter set of
strings.

Another issue (which I discovered testing the stuff
above) is that Double.parseDouble() doesn't actually
parse "NaN" or "Infinity", which is annoying because
the API says it does, so I've had to change the
implementation of string__to_float/2.

I'll post a new diff in a minute.

http://personals.yahoo.com.au - Yahoo! Personals
New people, new possibilities. FREE for a limited time.
--------------------------------------------------------------------------
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