public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug math/26045] New: fmaxf(inf, nan) does not always work
@ 2020-05-26 12:43 florian at schanda dot org.uk
  2020-05-27  9:59 ` [Bug math/26045] " amonakov at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: florian at schanda dot org.uk @ 2020-05-26 12:43 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=26045

            Bug ID: 26045
           Summary: fmaxf(inf, nan) does not always work
           Product: glibc
           Version: 2.28
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: math
          Assignee: unassigned at sourceware dot org
          Reporter: florian at schanda dot org.uk
  Target Milestone: ---

Created attachment 12570
  --> https://sourceware.org/bugzilla/attachment.cgi?id=12570&action=edit
example showing fmaxf does not always work

Hi

The gcc people sent me here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95329

I believe the fmaxf function does not always work correctly (I am on Debian
stable, amd64). The following piece of code produces the wrong output when
compile with no optimisation (and hence fmaxf from libm is called):

$ gcc bug.c -lm
$ ./a.out

max(-inf, nan) = nan
max(-inf, nan) = -inf

The code in question uses a special hand-crafted NaN:

#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include <string.h>

int main()
{
  uint32_t bv = 0x7FACBA7E;
  // (0 11111111 01011001011101001111110)

  float a, b;
  a = -INFINITY;
  memcpy(&b, &bv, 4);

  printf("max(%f, %f) = %f\n", a, b, fmaxf(a, b));

  b = NAN;
  printf("max(%f, %f) = %f\n", a, b, fmaxf(a, b));
}

Thanks in advance, and good luck! :)

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-09-29 16:19 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-26 12:43 [Bug math/26045] New: fmaxf(inf, nan) does not always work florian at schanda dot org.uk
2020-05-27  9:59 ` [Bug math/26045] " amonakov at gmail dot com
2020-06-01 22:52 ` joseph at codesourcery dot com
2020-06-02  6:18 ` amonakov at gmail dot com
2020-06-02 13:59 ` joseph at codesourcery dot com
2021-09-29 16:19 ` jsm28 at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).