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

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Nov 22 22:29:14 AEDT 2002


On 22-Nov-2002, Peter Ross <pro at missioncriticalit.com> wrote:
> fjh wrote:
> > On 21-Nov-2002, Peter Ross <pro at missioncriticalit.com> wrote:
> > > +:- pragma promise_pure(is_nan/1).
> > > +:- pragma foreign_proc(c, is_nan(Flt::in),
> > > + [will_not_call_mercury, thread_safe], "
> > > +#if MR_USE_SINGLE_PREC_FLOAT
> > > + SUCCESS_INDICATOR = isnanf(Flt);
> > > +#else
> > > + SUCCESS_INDICATOR = isnan(Flt);
> > > +#endif
> >
> > The use of isnan() and isnanf() need to be protected by
> > conditional compilation, since not all systems support them.
> >
> > Likewise for isinf() and isinff().
>
> I plan to to call #error if is* aren't defined, but add a comment that it
> may be safe to just return false if the system doesn't support IEEE
> arthimetic.  Is this acceptable to everyone?

I think a better fall-back is to use `(Flt != Flt)' for is_nan and
`(Flt == Flt * 2.0 && Flt != 0.0)' for is_inf.  Those should work on
any system where the C compiler supports IEEE float properly, even if
the C library doesn't have isinf() or isnan().  If the system doesn't
support IEEE arithmetic this should still do something reasonable.
If the C compiler doesn't support IEEE arithmetic properly then it may
incorrectly optimize these tests to just return false but I think
that is likely to be more useful than #error.

Also, for the MR_USE_SINGLE_PREC_FLOAT case, you should fall back to
calling isnan() and isinf() if isnanf() and isinff() are not defined.

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