[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] NAN and INFINITY break in different ways
From: |
Vincent Lefevre |
Subject: |
Re: [Tinycc-devel] NAN and INFINITY break in different ways |
Date: |
Sun, 24 Dec 2017 17:17:04 +0100 |
User-agent: |
Mutt/1.9.2+41 (3b142cea) vl-104418 (2017-12-15) |
On 2017-12-24 13:18:38 +0100, Michael Matz wrote:
> On Sat, 23 Dec 2017, avih wrote:
> > Alpine:
> > $ tcc test.c
> > testinfs.c:2: error: division by zero in constant
> >
> > $ tcc test.c -E
> > ...
> > static const double infs[] = { (0.0f/0.0f), 1e5000f };
> > ...
> >
> > So clearly tcc doesn't like musl's fallback definition (if not gcc) for NAN
> > in a constant, but tcc is fine with musl's INFINITY definition.
>
> I think we could make an exception for 0.0/0.0 and always fold this into NaN
> (normally division by zero is indeed not allowable in constant expressions
> in c99).
AFAIK, the standard just implies that 0.0/0.0 is not specified as a
constant expression. But the standard also says: "An implementation
may accept other forms of constant expressions."
Moreover, if Annex F is supported, then FP division by zero is
well-defined. F7.4.2 gives examples with 0.0/0.0 in initializers,
such as:
static float x = 0.0/0.0; // does not raise an exception
Nowadays, supporting Annex F is more or less a must.
--
Vincent Lefèvre <address@hidden> - 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)