mirror of
https://github.com/verilator/verilator.git
synced 2026-10-02 16:13:34 +02:00
Suppress REALCVT for small whole real numbers.
This commit is contained in:
@@ -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 {
|
||||
|
||||
+5
-2
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user