[Bug 294719] lib/msun: Added fmaximum_mag_num

[email protected] Wed, 29 Apr 2026 16:04:11 +0000
Newsgroups gmane.os.freebsd.devel.standards
Message-ID <[email protected]/bugzilla/>
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D294719

Steve Kargl <[email protected]> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
 Attachment #270243|text/x-csrc                 |text/plain
          mime type|                            |

--- Comment #10 from Steve Kargl <[email protected]> ---
Created attachment 270243
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D270243&action=
=3Dedit
bit-twiddling implementation and test program

(In reply to Robert Clausecker from comment #9)

I thought I replies yesterday.  Anyway, here's the
bit twiddling for fmaxium_numf().  AFAICT, it meets
the 'make it work.  make it correct.' criteria.
A full self-contained test code, which works on
x86_64, is attached as h4.c.


/*
 * Return the number if one argument is a number and the other is
 * a qNaN or sNaN.  If both arguments are NaNs, a quiet NaN is returned.
 * If an argument is a sNaN, the "invalid" floating-point exception
 * is raised (even though the function returns the number when the other
 * argument is a number.
 */

float
fmaximum_numf(float x, float y)
{
   uint32_t hx, hy, ux, uy;

   GET_FLOAT_WORD(hx, x);
   ux =3D hx & 0x7fffffff;

   GET_FLOAT_WORD(hy, y);
   uy =3D hy & 0x7fffffff;

   if (ux > 0x7f800000) {              /* x is NaN. */
      if (uy > 0x7f800000)             /* y is NaN. */
         return (x + y);               /* Return qNaN, raise FE_INVALID. */

      if (ux < 0x7fc00000)             /* x is sNaN. */
         feraiseexcept(FE_INVALID);

      return (y);
   }

   if (uy > 0x7f800000) {             /* y is NaN */
      if (uy < 0x7fc00000)            /* y is sNaN */
         feraiseexcept(FE_INVALID);
      return (x);
   }

   return (((hx >> 31) < (hy >> 31)) || y < x ? x : y);
}

--=20
You are receiving this mail because:
You are the assignee for the bug.=