How to check if a real variable in SystemVerilog is at 'Not a Number' (NaN) or infinite (Inf)? Do system tasks exist for this purpose like isnan() or isinf() in C99?
if($realtobits(realvariable)==64'b1111111111111000000000000000000000000000000000000000000000000000) works for me. But it is awkward.
- SeblZ
2 Answers
0
votes
You could do:
let isnan(r) = {$realtobits(r)}[62:52] == '1 && {$realtobits(r)}[51:0] != '0;
Although the SystemVerilog LRM references IEEE 754 for representing floating point numbers, it does not define the results of real operations that could produce NaN or Inf. So use with caution.
0
votes
I now use
function real_is_number;
input real in;
reg [63:0] in_bits;
begin
in_bits=$realtobits(in);
real_is_number = ~&in_bits[62:52];
end
endfunction
to detect any real value which is not an ordinary number.
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.OkRead more
if($realtobits(realvariable)==64'b1111111111111000000000000000000000000000000000000000000000000000)works for me. But it is awkward. - SeblZ