Commit Graph

3 Commits

Author SHA1 Message Date
Mark Olesen
c1c4e91ffb ENH: handle underflow (rounding) of float/double as zero (issue #625)
- The problem occurs when using atof to parse values such as "1e-39"
  since this is out of range for a float and _can_ set errno to
  ERANGE.

  Similar to parsing of integers, now parse with the longest floating
  point representation "long double" via strtold (guaranteed to be
  part of C++11) and verify against the respective VGREAT values for
  overflow. Treat anything smaller than VSMALL to be zero.
2017-10-25 20:55:37 +02:00
Mark Olesen
f116217466 STYLE: remove FULLDEBUG output on readLabel, readScalar
- used in various places to test if the input can be parsed as a
  label/scalar, so warnings tend to flood the output.

- be more explicit when encountering range errors
2017-10-12 12:15:56 +02:00
Mark Olesen
accebc74ee ENH: improve consistency in parsing primitives from strings (issue #590)
- Any trailing whitespace when parsing from strings or character buffers
  is ignored rather than being treated as an error. This is consistent
  with behaviour when reading from an Istream and with leading whitespace
  being ignored in the underlying atof/atod, strtof/strtod... functions.

- Allow parsing directly from a std::string instead of just from a 'char*'.
  This reflects the C++11 addition of std::stod to complement the C
  functions strtod. This also makes it easier to parse string directly
  without using an IStringStream.

- Two-parameter parsing methods return success/failure.
  Eg,

      if (readInt32(str, &int32Val)) ...

- One-parameter parsing methods return the value on success or
  emit a FatalIOError.
  Eg,

      const char* buf;
      int32Val = readInt32(buf, &);

- Improved consistency when parsing unsigned ints.
  Use strtoimax and strtoumax throughout.

- Rename readDoubleScalar -> readDouble, readFloatScalar -> readFloat.
  Using the primitive name directly instead of the Foam typedef for
  better consistency with readInt32 etc.

- Clean/improve parseNasScalar.
  Handle normal numbers directly, reduce some operations.
2017-09-18 10:47:07 +02:00