3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-06-28 17:08:46 +00:00

improved (fixed) conversion of real values to bit vectors

This commit is contained in:
Clifford Wolf 2014-06-14 20:38:05 +02:00
parent 39eb347c67
commit 149fe83a8d
4 changed files with 30 additions and 11 deletions

View file

@ -794,6 +794,24 @@ double AstNode::asReal(bool is_signed)
log_abort();
}
RTLIL::Const AstNode::realAsConst(int width)
{
double v = round(realvalue);
RTLIL::Const result;
if (!isfinite(v)) {
result.bits = std::vector<RTLIL::State>(width, RTLIL::State::Sx);
} else {
bool is_negative = v < 0;
if (is_negative)
v *= -1;
for (int i = 0; i < width; i++, v /= 2)
result.bits.push_back((int(v) & 1) ? RTLIL::State::S1 : RTLIL::State::S0);
if (is_negative)
result = const_neg(result, result, false, false, result.bits.size());
}
return result;
}
// create a new AstModule from an AST_MODULE AST node
static AstModule* process_module(AstNode *ast, bool defer)
{