qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Mateusz Loskot <mateusz@loskot.net>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [sparc] Floating point exception issue
Date: Tue, 18 Jan 2011 15:27:04 +0000	[thread overview]
Message-ID: <4D35B148.9080003@loskot.net> (raw)

Hi,

Recently, I have reported mysterious issues on NetBSD 5.1
emulated on SPARC. The whole first thread is here:

http://lists.gnu.org/archive/html/qemu-devel/2011-01/msg01509.html

I decided to investigate the problem deeper and with great help
from NetBSD folks, I managed to find reproducible test case.
Initially, it was AWK command:

# echo NaN | awk '{print "test"}'
awk: floating point exception 8
   source line number 1

and next it boiled down to simple C program (see below).
Details of the investigation are archived in the NetBSD Problem
Report #44389 here:

http://gnats.netbsd.org/cgi-bin/query-pr-single.pl?number=44389


Here is final version of the test program which reproduces the problem:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <errno.h>

int is_number(const char *s)
{
         double r;
         char *ep;
         errno = 0;
         r = strtod(s, &ep);
         if (r == HUGE_VAL)
                 printf("X:%g\n", r);

         if (ep == s || r == HUGE_VAL || errno == ERANGE)
                 return 0;
         while (*ep == ' ' || *ep == '\t' || *ep == '\n')
                 ep++;
         if (*ep == '\0')
                 return 1;
         else
                 return 0;
}

int main(int argc, char **argv)
{
         double v;

         if (is_number("NaN")) {
                 printf("is a number\n");
                 v = atof("NaN");
         } else {
                 printf("not a number\n");
                 v = 0.0;
         }
         printf("%.4f\n", v);

         return 0;
}


On NetBSD/SPARC, the program receives SIGFPE:

$ gcc ./nan_test_2.c
  $ ./a.out
  [1]   Floating point exception (core dumped) ./a.out

Specifically, it's caused by r == HUGE_VAL condition in
   if (ep == s || r == HUGE_VAL || errno == ERANGE)
where r is NaN.

All the signs indicate there is a bug in QEMU.

Best regards,
-- 
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org
Member of ACCU, http://accu.org

             reply	other threads:[~2011-01-18 15:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-18 15:27 Mateusz Loskot [this message]
2011-01-18 17:36 ` [Qemu-devel] [sparc] Floating point exception issue Blue Swirl
2011-01-18 18:00   ` Mateusz Loskot
2011-01-18 21:51     ` Blue Swirl
2011-01-19 12:03       ` Mateusz Loskot
2011-01-22 15:30       ` Mateusz Loskot
2011-01-22 15:38         ` Blue Swirl
2011-01-22 16:45           ` Robert Reif
2011-01-22 23:03             ` Artyom Tarasenko

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=4D35B148.9080003@loskot.net \
    --to=mateusz@loskot.net \
    --cc=qemu-devel@nongnu.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 NNTP newsgroup(s).