kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

fpcmp_nan.c (795B)


      1 /* NaN-tolerant ordered/unordered double comparisons. A runtime 0.0/0.0
      2  * produces a NaN deterministically; comparisons against NaN exercise the
      3  * unordered condition codes (== false, != true, < and > false). volatile
      4  * defeats folding and keeps the divide at runtime. Exit: 20 + 22 = 42. */
      5 int test_main(void) {
      6   volatile double z = 0.0;
      7   volatile double nan = z / z; /* NaN at runtime */
      8   volatile double a = 1.0;
      9   int r = 0;
     10   if (!(nan == a)) r += 20; /* unordered: == is false, so this taken */
     11   if (nan != a) r += 22;    /* unordered: != is true, so this taken */
     12   if (nan < a) r += 100;    /* unordered: < is false, not taken */
     13   if (nan > a) r += 100;    /* unordered: > is false, not taken */
     14   if (nan >= a) r += 100;   /* unordered: >= is false, not taken */
     15   return r;
     16 }