[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] NAN and INFINITY break in different ways

From: avih
Subject: [Tinycc-devel] NAN and INFINITY break in different ways
Date: Sat, 23 Dec 2017 15:10:13 +0000 (UTC)

I've raised the subject of NAN in the past and did get some suggestions, but
it never ended in any upstream fix. There also appears to be a somewhat related
issue with INFINITY.

I'm testing with Ubuntu 16.04 LTS 64 (glibc) and Alpine Linux (edge) 64 (musl),
with the following test.c program:

#include <math.h>
static const double infs[] = { NAN, INFINITY };
int main(int argc, char **argv) {
  return infs[0] && infs[1];

The above program compiles and works with gcc on both test systems.

With tcc, it fails.

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

$ tcc test.c
test.c:2: error: initializer element is not constant

$ tcc test.c -E
static const double infs[] = { (__qnan_union.__d), (__huge_valf.__f) };

Here it's less clear to me how come tcc doesn't complain about undefined
symbols, but nevertheless, it seems (I'm guessing) to be some definition which
gcc can use.

Now, tcc does have tokens __nan__ and __inf__, however, I don't think they get
used when a program includes <math.h>, observed on those two systems.

But the following does seem to solve it relatively correctly I think.
Is there an objection to install this as <prefix>/lib/tcc/include/math.h ?

/* override NAN and INFINITY with tcc tokens */

#include_next <math.h>

#ifdef NAN
#  undef NAN
#define NAN __nan__

#  undef INFINITY
#define INFINITY __inf__

reply via email to

[Prev in Thread] Current Thread [Next in Thread]