public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "florian at schanda dot org.uk" <sourceware-bugzilla@sourceware.org>
To: glibc-bugs@sourceware.org
Subject: [Bug math/26045] New: fmaxf(inf, nan) does not always work
Date: Tue, 26 May 2020 12:43:10 +0000	[thread overview]
Message-ID: <bug-26045-131@http.sourceware.org/bugzilla/> (raw)

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.

             reply	other threads:[~2020-05-26 12:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-26 12:43 florian at schanda dot org.uk [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-26045-131@http.sourceware.org/bugzilla/ \
    --to=sourceware-bugzilla@sourceware.org \
    --cc=glibc-bugs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).