Suppress REALCVT for small whole real numbers.

This commit is contained in:
Wilson Snyder 2020-04-01 19:23:52 -04:00
parent 19abce5535
commit bd5d4c61c6
2 changed files with 14 additions and 2 deletions

View File

@ -22,10 +22,19 @@
#include "V3Error.h"
#include <cmath>
#include <limits>
#include <vector>
//============================================================================
// Return if two numbers within Epsilon of each other
inline bool v3EpsilonEqual(double a, double b) {
return fabs(a - b) <= (std::numeric_limits<double>::epsilon() * std::max(1.0, std::max(a, b)));
}
//============================================================================
class AstNode;
class V3Number {

View File

@ -4342,9 +4342,12 @@ private:
AstNRelinker linker;
nodep->unlinkFrBack(&linker);
if (AstConst* constp = VN_CAST(nodep, Const)) {
// Ignore obvious conversions of whole real numbers, e.g. 1.0 -> 1
// We convert to/from vlsint32 rather than use floor() as want to make sure is
// representable in integer's number of bits
if (constp->isDouble()
&& constp->num().toDouble() == floor(constp->num().toDouble())) {
&& v3EpsilonEqual(constp->num().toDouble(),
static_cast<double>(
static_cast<vlsint32_t>(constp->num().toDouble())))) {
warnOn = false;
}
}