kit

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

conv_int_float_u.c (817B)


      1 /* Unsigned int <-> float round-trip: UCVTF (uint->float) and FCVTZU
      2  * (float->uint). A source above INT_MAX exercises the unsigned-specific
      3  * encoding rather than the signed path. volatile operands defeat folding.
      4  *
      5  *   u = 0x80000000 : f = (float)u = 2147483648.0f   (ucvtf s,w)
      6  *   back           : (unsigned)(f / k) reduces deterministically (fcvtzu). */
      7 int test_main(void) {
      8   volatile unsigned int u = 0x80000000u; /* 2147483648 */
      9   volatile unsigned int v = 126u;
     10   float f = (float)u;                         /* ucvtf s,w (unsigned) */
     11   float g = (float)v;                         /* ucvtf s,w */
     12   unsigned int bu = (unsigned int)(f / f);    /* 1,  fcvtzu w,s */
     13   unsigned int bv = (unsigned int)(g / 3.0f); /* 42, fcvtzu w,s */
     14   return (int)(bv + bu - 1);                  /* 42 + 1 - 1 = 42 */
     15 }