to_float()和分割错误 [英] to_float() and dividing errors

查看:127
本文介绍了to_float()和分割错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在评论中提出此问题后(编译器错误时编译* .vhdl到库 - Altera Quartus II )我决定它可能会更好一个单独的问题。

After bringing this issue up in a comment (compiler errors when compiling *.vhdl into a library - Altera Quartus II) I decided that it would probably be better off as a separate question.

这是代码摘录,一个过程的主要部分:

This is the code excerpt, the main part of a process:

    variable denum : integer; 
    variable num : integer; 
    variable dividend : float (4 downto -27);  

begin
    dividend := to_float(num) / to_float(denum); 
    ... 

指向to_float()函数需要额外我尝试了建议的改进,但仍然有一些错误:

After being pointed to the error that the to_float() function needs additional arguments, I tried the suggested improvements, but still got some errors:

dividend := to_float(num, dividend) / to_float(denum, dividend);

返回:float_pkg_c.vhdl的VHDL语法错误(3843):范围的右边界必须是常数

returns: "VHDL syntax error at float_pkg_c.vhdl(3843): right bound of range must be a constant"

dividend := to_float(num, 4, -27) / to_float(denum, 4, -27); 

返回:SM.vhd(93)上的VHDL错误:值-27目标约束范围(0到2147483647)

returns: "VHDL error at SM.vhd(93): value "-27" is outside the target constraint range (0 to 2147483647)"

错误消息指出问题源于错误的to_float调用,但我在方法中看不到任何问题,考虑到它是最新软件包的一部分。有人可以澄清对我吗?我也不知道是否可以用这种方式执行除法运算,我的意思是在一行,返回从特定的ints获得的浮点。

The error messages point that the problem originates in the wrong call of to_float, but I can't see any problem in the method, considering the fact that it is part of the latest package. Can someone clarify that to me? Also I'm not sure whether the divide operation can be executed in this way, I mean in one line, returning a float obtained from the particular ints.

推荐答案

我可以在这里看到一个问题:

I can see a problem right here:

dividend := to_float(num, 4, -27) / to_float(denum, 4, -27);

如果你看一下定义:

-- to_float (Integer)
function to_float (
    arg                     : INTEGER;
    constant exponent_width : NATURAL    := float_exponent_width;  -- length of FP output exponent
    constant fraction_width : NATURAL    := float_fraction_width;  -- length of FP output fraction
    constant round_style    : round_type := float_round_style)  -- rounding option
    return UNRESOLVED_float is
    variable result     : UNRESOLVED_float (exponent_width downto -fraction_width);
    ...

查看 fraction_width :自然。这是您目前得到的错误,因为您提供了 -27

Take a look at fraction_width: it's a natural. This is the error you're currently getting, as you supply -27.

当您在实施中向下看一点, em> result 使用 fraction_width 的逆。因此,您应该调用

When you look farther down in the implementation a little, result uses the inverse of fraction_width. Hence, you should be invoking

to_float(num, 4, 27)

这篇关于to_float()和分割错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆