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

 
 

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

Submitted by:  kloof <kloof>
Submitted on:  Fri 05 Aug 2011 12:58:07 PM UTC  
 
Category: InterpreterSeverity: 3 - Normal
Priority: 5 - NormalItem Group: Feature Request
Status: FixedAssigned to: None
Originator Name: Open/Closed: Closed
Release: 3.4.0Operating System: GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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>
Project 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

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>
Project 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 File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

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

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 3 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 08 Aug 2011 04:19:50 PM UTCjweStatusConfirmed=>Fixed
      Open/ClosedOpen=>Closed
    Fri 05 Aug 2011 08:49:27 PM UTCrik5StatusNone=>Confirmed

    Back to the top


    Powered by Savane 3.1-cleanup1