将实数值转换为大于 32 位的整数值的最佳方法?

The best way to convert a real valued number to an integer value larger than 32 bits?

System Verilog 中有支持超过 32 位的系统函数吗?我想将实数值转换为包含超过 32 位的整数值。 $rtoi() 系统函数精确地完成了我想要的可以用 32 位或更少位表示的值。有内置的吗,还是我需要自己写?

举个具体的例子,我希望能够执行如下操作:

logic [41:0] test_value;

initial begin
    test_value = $rtoi($pow(2.0, 39.5));
end

在这里,我将使用未知的系统函数来代替 $rtoi()。给定正确的功能,我希望这会导致 test_value 被初始化为位序列 42'b1011010100000100111100110011001111111001 或者可能 42'b1011010100000100111100110011001111111010 如果支持舍入。

我可以写自己的功能,但我想避免重新发明轮子,除非没有轮子。

从实数到整数的隐式转换为您提供了四舍五入的结果

test_value = 2.0**39.5;

或者您可以使用显式转换

typedef logic [41:0] uint42_t;

test_value = uint42_t'(2.0**39.5);