kit

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

conv_fp_fp.c (642B)


      1 /* float <-> double precision conversion: FCVT s->d (widen) and FCVT d->s
      2  * (narrow). Values chosen so both directions are exact (no rounding), keeping
      3  * the result deterministic. volatile operands defeat folding.
      4  *
      5  *   f = 21.0f : d = (double)f = 21.0   (fcvt d,s widen)
      6  *   d2 = 84.0 : f2 = (float)d2 = 84.0f (fcvt s,d narrow) */
      7 int test_main(void) {
      8   volatile float f = 21.0f;
      9   volatile double d2 = 84.0;
     10   double d = (double)f;     /* fcvt d,s (widen) */
     11   float f2 = (float)d2;     /* fcvt s,d (narrow) */
     12   int a = (int)d;           /* 21 */
     13   int b = (int)(f2 / 4.0f); /* 21 */
     14   return a + b;             /* 21 + 21 = 42 */
     15 }