Mercurial > octave
diff liboctave/util/lo-array-errwarn.cc @ 25806:0360ed7c39a8
Always print non-integer part of non-integer indices in invalid index message (bug #46859).
* lo-array-errwarn.cc (gripe_invalid_index): Detect when double value index will
be printed as an integer and show the fractional part in this case.
author | Lachlan Andrew <lachlanbis@gmail.com> |
---|---|
date | Thu, 14 Jan 2016 14:03:17 +1100 |
parents | 6652d3823428 |
children | cb775c73866d |
line wrap: on
line diff
--- a/liboctave/util/lo-array-errwarn.cc Thu Aug 16 19:36:39 2018 +0200 +++ b/liboctave/util/lo-array-errwarn.cc Thu Jan 14 14:03:17 2016 +1100 @@ -24,6 +24,8 @@ # include "config.h" #endif +#include <cmath> + #include <sstream> #include "lo-array-errwarn.h" @@ -215,6 +217,11 @@ { std::ostringstream buf; buf << n + 1; + // if n not an integer, but would be printed as one, show diff + double nearest = std::floor (n + 1.5); + if (n + 1 != nearest && (buf.str ().find ('.') == std::string::npos)) + buf << std::showpos << (n + 1 - nearest); + err_invalid_index (buf.str (), nd, dim, var); }