【发布时间】:2012-10-05 08:02:14
【问题描述】:
我生成了随机浮点数(十进制格式)并将它们保存在一个文本文件中。我编写了一个代码来用 VHDL 读取该文件。现在我想将这些浮点数转换为 IEEE 格式(32 bir 或 64 位)。是否有任何可用的图书馆可以用于我的工作。 还是有VHDL代码?
谢谢
【问题讨论】:
标签: floating-point vhdl ieee-754
我生成了随机浮点数(十进制格式)并将它们保存在一个文本文件中。我编写了一个代码来用 VHDL 读取该文件。现在我想将这些浮点数转换为 IEEE 格式(32 bir 或 64 位)。是否有任何可用的图书馆可以用于我的工作。 还是有VHDL代码?
谢谢
【问题讨论】:
标签: floating-point vhdl ieee-754
您可以通过纯软件脚本将浮点数转换为 IEEE 754(例如 1.0 -> 0x3F800000):
matlab 脚本:
将实数转换为 IEEE 754 浮点格式的数字的 Matlab 程序 http://users.eecs.northwestern.edu/~ismail/courses/c92/fpu/
lisp 脚本:http://common-lisp.net/project/ieee-floats/
使用 ieee-floats 中定义的 encode-float32,可以快速转换。
(defun fix2float (fp)
(format t "~%~x~T~x" fp (ieee-floats:encode-float32 fp)))
(fix2float 1.1)
至于硬件库,Vfloat(王晓军,2010)值得一试。
【讨论】:
有一个VHDL浮点包:
【讨论】:
如果您想在 VHDL 中使用随机数,为什么不使用 *math_real* 库中的 UNIFORM 函数? Uniform 是你的函数,用法在定义中解释
procedure UNIFORM (variable Seed1,Seed2:inout integer; variable X:out real);
-- returns a pseudo-random number with uniform distribution in the
-- interval (0.0, 1.0).
-- Before the first call to UNIFORM, the seed values (Seed1, Seed2) must
-- be initialized to values in the range [1, 2147483562] and
-- [1, 2147483398] respectively. The seed values are modified after
-- each call to UNIFORM.
-- This random number generator is portable for 32-bit computers, and
-- it has period ~2.30584*(10**18) for each set of seed values.
--
-- For VHDL-1992, the seeds will be global variables, functions to
-- initialize their values (INIT_SEED) will be provided, and the UNIFORM
-- procedure call will be modified accordingly.
如果这不是您需要的,请使用 *std_textio* 包读取数据:
procedure READ(L:inout LINE; VALUE: out real; GOOD : out BOOLEAN);
procedure READ(L:inout LINE; VALUE: out real);
【讨论】: