[Cfp-interest 2235] Re: contradiction about the INFINITY macro

Vincent Lefevre vincent at vinc17.net
Mon Oct 11 07:01:10 PDT 2021


On 2021-10-10 17:06:54 -0700, Jim Thomas wrote:
> It is allowed for a wider standard floating type to have infinity
> (or NaN) but not a narrower type. C doesn’t have infinity and NaN
> macros for that. Is this an issue for some implementation?

Programs that use INFINITY with double would be incorrect with such
hypothetical implementations.

For instance, cairo does that in src/cairo-default-context.c:

static cairo_status_t
_cairo_default_context_clip_extents (void *abstract_cr,
                                     double *x1, double *y1, double *x2, double *y2)
{
    cairo_default_context_t *cr = abstract_cr;

    if (! _cairo_gstate_clip_extents (cr->gstate, x1, y1, x2, y2)) {
        *x1 = -INFINITY;
        *y1 = -INFINITY;
        *x2 = +INFINITY;
        *y2 = +INFINITY;
    }

    return CAIRO_STATUS_SUCCESS;
}

BTW, cairo already assumes that INFINITY is not necessarily defined:

#if !defined(INFINITY)
#define INFINITY HUGE_VAL
#endif

(thus among the C implementations with no float infinity, it would
behave better when INFINITY is not defined than when it is defined).
Said otherwise, a change of the standard would be a benefit for
software like cairo.

-- 
Vincent Lefèvre <vincent at vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)


More information about the Cfp-interest mailing list