Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Apr 2026 16:04:11 +0000
From:      bugzilla-noreply@freebsd.org
To:        standards@FreeBSD.org
Subject:   [Bug 294719] lib/msun: Added fmaximum_mag_num
Message-ID:  <bug-294719-99-sFuz4ulNsZ@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-294719-99@https.bugs.freebsd.org/bugzilla/>

index | next in thread | previous in thread | raw e-mail

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=294719

Steve Kargl <kargl@FreeBSD.org> changed:

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

--- Comment #10 from Steve Kargl <kargl@FreeBSD.org> ---
Created attachment 270243
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=270243&action=edit
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 = hx & 0x7fffffff;

   GET_FLOAT_WORD(hy, y);
   uy = 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);
}

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

home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-294719-99-sFuz4ulNsZ>