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

Peter Ross pro at missioncriticalit.com
Fri Nov 22 21:00:28 AEDT 2002


pmoulder wrote:
> On Thu, Nov 21, 2002 at 04:46:36PM +0100, Peter Ross wrote:
>
> > + % returns a float which is round-tripable, ie to full precision
needed.
>
> I believe that should be trippable (double-p), as in shippable
> (egrep '[aeiou]pp?able$' /usr/share/dict/words).
Done.

> Also I've a mild preference for "i.e. to the full ...".
>

Done.

> This string occurs in two places in the diff.
>
> > -:- pred is_denormal(string :: in) is semidet.
> > -is_denormal("NaN").
> > -is_denormal("Inf").
> > +:- pred is_special_value(float::in) is semidet.
> > +
> > +is_special_value(Float) :-
> > + ( is_nan(Float)
> > + ; is_inf(Float)
> > + ).
>
> is_inf_or_nan is both shorter and clearer than is_special_value.
>
Done.

> One might even add this (or its negation, as in C99) to float.m.  C99 has
an
> isfinite macro (returning non-zero iff its argument is neither NaN nor
> infinite).  Not to be confused with BSD's `finite' function, which
> is like !isinf(x).
>
> > + call bool [mscorlib]System.Double::IsInfinity(float64)
>
> Does this return true for -Inf too?
>
Yes it does.  There are also IsPositiveInfinity() and IsNegativeInfinity().

>
> > +get_hex_int(Int) = HexStr :-
> > + ( Int < integer(10) ->
> > + HexStr = integer__to_string(Int)
> > + ; Int = integer(10) ->
> > + HexStr = "a"
> > + ; Int = integer(11) ->
> > [...]
>
> If writing in C, the obvious code would be something like
>
>   (val < 10
>    ? '0' + val
>    : 'a' - 10 + val)
>
> (after converting the integer Int to an int).  I've written some untested
> suggested replacement code below; though you may well decide that it
> isn't worth bothering over.
>
Problem when inheriting code someone else has written.  I also would write
it the C way, but I know this version works and it isn't much of a
difference so I will leave as is.



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