【问题标题】:Conversion of scientific notation into real in systemverilog在systemverilog中将科学记数法转换为实数
【发布时间】:2017-07-05 21:45:50
【问题描述】:

我有一个格式如下的字符串

str = "1e-06"

字符串的内容是以科学计数法表示的数字。我想以真实格式获取字符串的内容,以便在我的 systemverilog 代码的下一个块中使用。谁能帮我找到解决办法?

例子:

string str = "1e-06";
real number;
number = str.atoreal();
$display("%f", number);

在这个 sn-p 的输出中,我期待 1e-06 但我得到 1

【问题讨论】:

  • 如何显示small example 来显示您获得的输出与您期望的输出。
  • 特别是,您是如何格式化输出的?
  • 您好 dave_59,感谢您的回复。我在下面给出一个例子: string str = "1e-06";实数; number = str.atorial(); $display("%f", number);在这个 sn-p 的输出中,我期待 1e-06 但我得到 1
  • 它只是一个常规字符串dave_59,其内容是以科学计数法表示的数字。

标签: string system-verilog


【解决方案1】:

使用%e 代替%f。这就是为什么展示一个完整的例子非常重要。

这是一个完整示例的示例

module top;
string str = "1e-06";
real number;
initial begin 
  number = str.atoreal();
  $display("%e", number); // %f displays a fixed point number, you want %e or %g
  end
endmodule

【讨论】:

  • 我仍然得到相同的结果 dave_59。对不起。 :(
  • 4 个模拟器中有 3 个给我 1.000000e-06%e。我想你正在使用 4 中的 1 :(
  • 哈哈,好的。不管怎么说,还是要谢谢你。 :)
猜你喜欢
  • 2015-07-03
  • 2014-09-25
  • 2021-12-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-04-21
  • 2012-11-29
  • 1970-01-01
相关资源
最近更新 更多