mirror of
https://github.com/steveicarus/iverilog.git
synced 2026-09-04 00:31:42 +02:00
Check that the vvp code generator emits a -0.0 real constant with its sign bit set, so the compiled value matches the runtime real value. The sign used to be detected with (value < 0), which is false for IEEE 754 -0.0, and a -0.0 constant was turned into +0.0. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
36 lines
936 B
Verilog
36 lines
936 B
Verilog
// Check that the vvp code generator preserves the sign of a negative zero
|
|
// real constant. The sign used to be detected with (value < 0), which is
|
|
// false for IEEE 754 -0.0, so a -0.0 constant was emitted as +0.0 and the
|
|
// compiled value no longer matched the runtime real value.
|
|
|
|
module test;
|
|
|
|
real nz;
|
|
real pz;
|
|
|
|
initial begin
|
|
nz = -0.0;
|
|
pz = 0.0;
|
|
|
|
// The sign bit is the only thing that tells -0.0 from +0.0.
|
|
if ($realtobits(nz) !== 64'h8000_0000_0000_0000) begin
|
|
$display("FAILED: -0.0 stored as %h", $realtobits(nz));
|
|
$finish;
|
|
end
|
|
|
|
if ($realtobits(pz) !== 64'h0000_0000_0000_0000) begin
|
|
$display("FAILED: 0.0 stored as %h", $realtobits(pz));
|
|
$finish;
|
|
end
|
|
|
|
// The reciprocal makes the sign observable: 1.0/-0.0 is -inf.
|
|
if (1.0 / nz >= 0.0) begin
|
|
$display("FAILED: 1.0/-0.0 = %g", 1.0 / nz);
|
|
$finish;
|
|
end
|
|
|
|
$display("PASSED");
|
|
end
|
|
|
|
endmodule
|