chiark / gitweb /
@@@ doc wip
[mLib] / utils / fltfmt.c
index 89c705d79dd0504054eba2386a70da98aa68fa93..deaf553667bbaee00acd68673766ed64852640a2 100644 (file)
@@ -535,12 +535,12 @@ unsigned fltfmt_round(struct floatbits *z_out, const struct floatbits *x,
 
 /* IEEE (and related) format descriptions. */
 const struct fltfmt_ieeefmt
-  fltfmt_mini = { IEEEF_HIDDEN, 4, 4 },
-  fltfmt_bf16 = { IEEEF_HIDDEN, 8, 8 },
-  fltfmt_f16 = { IEEEF_HIDDEN, 5, 11 },
-  fltfmt_f32 = { IEEEF_HIDDEN, 8, 24 },
-  fltfmt_f64 = { IEEEF_HIDDEN, 11, 53 },
-  fltfmt_f128 = { IEEEF_HIDDEN, 15, 113 },
+  fltfmt_mini = { FLTIF_HIDDEN, 4, 4 },
+  fltfmt_bf16 = { FLTIF_HIDDEN, 8, 8 },
+  fltfmt_f16 = { FLTIF_HIDDEN, 5, 11 },
+  fltfmt_f32 = { FLTIF_HIDDEN, 8, 24 },
+  fltfmt_f64 = { FLTIF_HIDDEN, 11, 53 },
+  fltfmt_f128 = { FLTIF_HIDDEN, 15, 113 },
   fltfmt_idblext80 = { 0, 15, 64 };
 
 /* --- @fltfmt_encieee@ ---
@@ -585,7 +585,7 @@ unsigned fltfmt_encieee(const struct fltfmt_ieeefmt *fmt,
 
   /* Determine the output size. */
   nb = fmt->prec + fmt->expwd + 1;
-  if (fmt->f&IEEEF_HIDDEN) nb--;
+  if (fmt->f&FLTIF_HIDDEN) nb--;
   nw = (nb + 31)/32;
 
   /* Determine the top bits. */
@@ -603,7 +603,7 @@ unsigned fltfmt_encieee(const struct fltfmt_ieeefmt *fmt,
      */
 
     z0 |= M32(fmt->expwd) << esh;
-    if (!(fmt->f&IEEEF_HIDDEN)) z0 |= B32(esh - 1);
+    if (!(fmt->f&FLTIF_HIDDEN)) z0 |= B32(esh - 1);
 
   } else if (f&FLTF_NANMASK) {
     /* Not-a-number.
@@ -629,13 +629,13 @@ unsigned fltfmt_encieee(const struct fltfmt_ieeefmt *fmt,
     n = x->n; if (n > mw) n = nw;
     t = shr(z + i, x->frac, n, sh); i += n;
     if (i < nw) z[i++] = t;
-    sh = esh - 2; if (fmt->f&IEEEF_HIDDEN) sh++;
+    sh = esh - 2; if (fmt->f&FLTIF_HIDDEN) sh++;
     if (f&FLTF_QNAN) z0 |= B32(sh);
     else if (!fracwd) { ERR(FLTERR_INEXACT); z[nw - 1] |= 1; }
 
     /* Set the exponent and, for non-hidden-bit formats, the unit bit. */
     z0 |= M32(fmt->expwd) << esh;
-    if (!(fmt->f&IEEEF_HIDDEN)) z0 |= B32(esh - 1);
+    if (!(fmt->f&FLTIF_HIDDEN)) z0 |= B32(esh - 1);
 
   } else {
     /* A finite value.
@@ -711,15 +711,14 @@ unsigned fltfmt_encieee(const struct fltfmt_ieeefmt *fmt,
         * the rounding mode.
         */
 
+       ERR(FLTERR_OFLOW | FLTERR_INEXACT);
        rf = FRPF_ODD | FRPF_HALF | FRPF_LOW;
        if (f&FLTF_NEG) rf |= FRPF_NEG;
-       if ((r >> rf)&1) {
-         ERR(FLTERR_OFLOW | FLTERR_INEXACT);
+       if ((r >> rf)&1)
          z0 |= M32(fmt->expwd) << esh;
-       } else {
-         ERR(FLTERR_INEXACT);
+       else {
          z0 |= (B32(fmt->expwd) - 2) << esh;
-         mb = fmt->prec; if (fmt->f&IEEEF_HIDDEN) mb--;
+         mb = fmt->prec; if (fmt->f&FLTIF_HIDDEN) mb--;
          mw = (mb + 31)/32;
          i = nw - mw;
          z[i++] = M32(mb%32);
@@ -741,7 +740,7 @@ unsigned fltfmt_encieee(const struct fltfmt_ieeefmt *fmt,
        z0 |= (exp + maxexp) << esh;
 
        /* Clear the unit bit if we're suppose to use a hidden-bit convention. */
-       if (fmt->f&IEEEF_HIDDEN) {
+       if (fmt->f&FLTIF_HIDDEN) {
          mb = fmt->prec - 1; mw = (mb + 31)/32; mb = mb%32;
          z[nw - mw] &= ~B32(mb);
        }
@@ -944,7 +943,7 @@ unsigned fltfmt_decieee(const struct fltfmt_ieeefmt *fmt,
    */
   assert(fmt->expwd + 3 <= 32);
   esh = 31 - fmt->expwd; emask = M32(fmt->expwd);
-  sigwd = fmt->prec; if (fmt->f&IEEEF_HIDDEN) sigwd--;
+  sigwd = fmt->prec; if (fmt->f&FLTIF_HIDDEN) sigwd--;
 
   /* Determine the input size. */
   nb = sigwd + fmt->expwd + 1; nw = (nb + 31)/32;
@@ -964,7 +963,7 @@ unsigned fltfmt_decieee(const struct fltfmt_ieeefmt *fmt,
      * Note that we don't include the quiet bit in our decoded payload.
      */
 
-    if (!(fmt->f&IEEEF_HIDDEN)) {
+    if (!(fmt->f&FLTIF_HIDDEN)) {
       /* No hidden bit, so we expect the unit bit to be set.  If it isn't,
        * that's technically invalid, and its absence won't survive a round
        * trip, since the bit isn't considered part of a NaN payload -- or
@@ -980,7 +979,7 @@ unsigned fltfmt_decieee(const struct fltfmt_ieeefmt *fmt,
     if (ms_set_bit(x + nw, 0, sigwd) == ALLCLEAR)
       f |= FLTF_INF;
     else {
-      sh = esh - 2; if (fmt->f&IEEEF_HIDDEN) sh++;
+      sh = esh - 2; if (fmt->f&FLTIF_HIDDEN) sh++;
       if (x0&B32(sh)) f |= FLTF_QNAN;
       else f |= FLTF_SNAN;
       sigwd--; mw = (sigwd + 31)/32;
@@ -998,7 +997,7 @@ unsigned fltfmt_decieee(const struct fltfmt_ieeefmt *fmt,
    * Otherwise, we'll normalize the incoming value regardless, but report
    * settings of the unit bit which are inconsistent with the exponent.
    */
-  if (fmt->f&IEEEF_HIDDEN) {
+  if (fmt->f&FLTIF_HIDDEN) {
     if (!t) { exp = minexp; goto normalize; }
     else { exp = t - maxexp; goto hidden; }
   } else {