浮点数加法不满足结合律,数很小时也出现。
2021-10-26 本文已影响0人
Poisson_Lee
program flt_zero;
initial begin
bit[31:0] a,b,sum;
shortreal fa, fb, fsum;
a = 'hbfe61122; b= 'h3fe61122;
fa = $bitstoshortreal(a);
fb = $bitstoshortreal(b);
fsum = fa + fa + fa + fb + fb +fb;
sum = $shortrealtobits(fsum);
$display("fsum is %f, sum is %h", fsum, sum);
end
endprogram
仿真结果:
fsum is -0.000000, sum is b4800000