From patchwork Sun Jun 27 19:40:25 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerry DeLisle X-Patchwork-Id: 57099 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 53E58B6EF2 for ; Mon, 28 Jun 2010 05:40:47 +1000 (EST) Received: (qmail 12791 invoked by alias); 27 Jun 2010 19:40:45 -0000 Received: (qmail 12774 invoked by uid 22791); 27 Jun 2010 19:40:44 -0000 X-SWARE-Spam-Status: No, hits=2.6 required=5.0 tests=AWL, BAYES_40, BOTNET, RCVD_IN_DNSWL_NONE, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from vms173001pub.verizon.net (HELO vms173001pub.verizon.net) (206.46.173.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 27 Jun 2010 19:40:39 +0000 Received: from [192.168.1.5] ([unknown] [71.115.219.138]) by vms173001.mailsrvcs.net (Sun Java(tm) System Messaging Server 7u2-7.02 32bit (built Apr 16 2009)) with ESMTPA id <0L4O000HLUNDIYS2@vms173001.mailsrvcs.net>; Sun, 27 Jun 2010 14:40:27 -0500 (CDT) Message-id: <4C27A929.8010702@verizon.net> Date: Sun, 27 Jun 2010 12:40:25 -0700 From: Jerry DeLisle User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.9) Gecko/20100423 Thunderbird/3.0.4 MIME-version: 1.0 To: gfortran Cc: gcc patches Subject: [patch, libfortran] PR43298 Fortran library does not read in NaN -Inf or Inf Content-type: multipart/mixed; boundary=------------010507070009030708020109 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This attached patch adds code to read these special cases. The code is self explanatory. This added feature is for formatted READ. As a follow-up patch we can consider the contents of the parenthesis with NAN() and explicitly set the result. I will also be looking at how to handle signs. Regression tested on x86-64. testing on other platforms would be appreciated. OK for trunk? Regards, Jerry 2010-06-27 Jerry DeLisle PR libfortran/43298 * io/read.c: Add code to parse and read Inf, Infinity, NaN, and Nan with optional parenthesis. Index: read.c =================================================================== --- read.c (revision 161472) +++ read.c (working copy) @@ -810,6 +810,60 @@ read_f (st_parameter_dt *dtp, const fnode *f, char if (w == 0) goto zero; + + /* Check for Infinity or NaN. */ + if (unlikely ((w >= 3 && (*p == 'i' || *p == 'I' || *p == 'n' || *p == 'N')))) + { + int i; + int seen_space = 0; + int seen_paren = 0; + + /* Scan through the buffer keeping track of spaces and parenthesis. We + null terminate the string as soon as we see a left paren or if we are + BLANK_NULL mode. Leading spaces have already been skipped above, + trailing spaces spaces are ignored by converrting to '\0'. A space + between "NaN" and the optional perenthesis is not permitted. */ + for (i = 0; i < w; i++) + { + buffer[i] = tolower (p[i]); + if (!seen_paren && seen_space && buffer[i] != ' ') + goto bad_float; + if (buffer[i] == '(') + { + seen_paren = 1; + buffer[i] = '\0'; + } + if (buffer[i] == ')') + { + if (!seen_paren) + goto bad_float; + else + seen_paren = 0; + } + if (buffer[i] == ' ' && !seen_paren) + { + seen_space = 1; + if (dtp->u.p.blank_status == BLANK_ZERO) + buffer[i] = '0'; + else /* Ignore leading and trailing blanks. */ + buffer[i] = '\0'; + } + } + + buffer[w] = '\0'; + + /* If we did not see a closing parenthesis, we have a bad float. */ + if (seen_paren) + goto bad_float; + if (strcmp (buffer, "inf") != 0 + && strcmp (buffer, "nan") != 0 + && strcmp (buffer, "infinity") != 0) + goto bad_float; + + convert_real (dtp, dest, buffer, length); + return; + } + /* Process the mantissa string. */ while (w > 0) {