bugGNU Octave - Bugs: bug #33955, fscanf with -NaN, -Inf, -NA

 
 

bug #33955: fscanf with -NaN, -Inf, -NA

Submitter:  kloof <kloof>
Submitted:  Fri 05 Aug 2011 12:58:07 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Feature Request
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 3.4.0 Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 08 Aug 2011 04:19:50 PM UTC, comment #3: 

I know that +/- NA and NaN don't really make sense, but I don't have a problem with accepting and discarding the sign character.  It seems somewhat more friendly than either giving an error when trying to read numeric values.

I checked in the following change.

http://hg.savannah.gnu.org/hgweb/octave/rev/b74cb659e757

John W. Eaton <jwe>
Group administrator
Mon 08 Aug 2011 02:35:36 PM UTC, comment #2: 

I discovered this handling of -NaN accidentally: the first time my fscanf (via a 'while' loop) runs into a -NaN it converts that first occasion into 0.000 and all other (valid floating point) values in that same line of text are also converted to 0.0000.

I would think it's better to give an error message and stop (i.e. not to convert other numbers in the text to 0.000).

kloof <kloof>
Fri 05 Aug 2011 08:49:27 PM UTC, comment #1: 

Confirmed.  -Inf makes sense to me but the others don't.  I don't think we should accept "-NA" or "-NaN" inputs because we don't have a way to represent them in Octave.

For example, trying these conversions in Octave I get


x = -NA
x = NaN

x = -NaN
x = NaN


The first one is very wrong as it changes an NA value to a NaN value.  The next one is modestly wrong as it changes the sign of the NaN value.  Thus, I would vote to fix "-Inf" but leave "-NA" and "-NaN" to stop the conversion procedure and inform the user to change their input file. 

Rik <rik5>
Group administrator
Fri 05 Aug 2011 12:58:07 PM UTC, original submission:  

Reading files with fscanf doesn't work with the negative version of "NaN". I assume the same holds for "Inf" and "NA".

The positive version were addressed in:

http://octave.1599824.n4.nabble.com/reading-NaN-with-fscanf-td1622767.html

Can be done for the negative versions as well? Should this be done in the same block of oct-stream.cc as describe above, or does octave already assume it's a number when the first character is a '-'?

BTW: I think -Inf makes sense, but -NaN and -NA don't. But people put those values in data files anyway.


kloof <kloof>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by kloof (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2011-08-08 jwe StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2011-08-05 rik5 StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code