The next code should produce a negative value (-0.007812) but instead produced (1.992188):
$itor($signed(8'hff))
I did not try exactly this code, my example code tested against ModelSim is here:
https://github.com/jeras/rp_8bit/tree/master/tmp/flags
Regards,
Iztok Jeras
I'm a little puzzled by your expected results - I would expect $itor($signed(8'hff)) to have the value -1. Indeed, if I write
Icarus outputs the result -1.0. However, if I write
Icarus outputs the result 255.0, so it does look like there's a bug here. The difference is that the first result is calculated at compile time, and the second is calculated at run time.
Note that the second example has a race in that the initialization of value and the display may happen in any order. Icarus has a deterministic order for this, but that may not hold for other simulators. SystemVerilog fixes this race, but this is normal Verilog and Icarus does not currently implement the SystemVerilog initialization step.
This should also be checked against other simulators since cvc and gplcver produce 255 for both examples. Icarus obviously has a bug since it gives different results depending on the context, but we need to make sure we pick the correct result. Though I agree, -1.0 would be what I expect for this expression.
Skipping $signed() and using signed values 8'shff and reg signed both produce -1.0.
I am attaching the example code I used.
I've checked that Cary's test case passes with several other simulators. I'm looking at this now.
I've pushed a fix for this to both the master and v0.9 branches.