#24 bugs in itfile.cpp

release_3.6.x
closed
None
5
2012-09-15
2002-10-21
No

itfile.cpp, line 781:

the function implementation following \c

it_ifile &operator>>(it_ifile &f, float &x)

should be the definition of the operator \c

it_ifile &operator>>(it_ifile &f, double &x)

otherwise it leads to wrong results when reading "float64"
data

itfile.cpp, line 799:

the function implementation following \c

it_ifile &operator>>(it_ifile &f, double &x)

should be the definition of \c

it_ifile &operator>>(it_ifile &f, float &x)

accordingly. However the implizit typecast from \c double
f64 to \c float x is problematic and might yield unexpected
results, see for instance \c f64 = 1e300

Discussion

  • jens röhner

    jens röhner - 2002-10-21

    Logged In: YES
    user_id=627421

    there is a further bug in
    itfile.cpp line 834: \c

    it_ifile &operator>>(it_ifile &f, double_complex &x)

    the definition of this op should read \code

    {
    it_file::data_header h;

    f.read_data_header(h);
    if (h.type == "float64_complex")
    f.low_level_read(x);
    else if (h.type == "float32_complex") {
    float_complex f32_c;
    f.low_level_read(f32_c);
    x = f32_c;
    }
    else
    throw it_file_base::Error("Wrong type");
    
    return f;
    

    }

    \endcode

     
  • Tony Ottosson Gadd

    Logged In: YES
    user_id=326034

    This is indeed a bug. Writing float and reading double and
    vice versa may give errors if outside the precision of the
    reading variable.

    The fix suggested has been implemented, with one difference.
    It is not allowed anymore to read a double into a float. An
    error occurs instead.

    The same problem was also present it reading into a
    double_complex if saved as float_complex. Also fixed.

    All fixes are checked into the CVS.

    /Tony

     

Log in to post a comment.