Reputation: 377
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);
...
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);
returns: "VHDL syntax error at float_pkg_c.vhdl(3843): right bound of range must be a constant"
and
dividend := to_float(num, 4, -27) / to_float(denum, 4, -27);
returns: "VHDL error at SM.vhd(93): value "-27" is outside the target constraint range (0 to 2147483647)"
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.
Upvotes: 2
Views: 903
Reputation: 4041
I can see a problem right here:
dividend := to_float(num, 4, -27) / to_float(denum, 4, -27);
If you take a look at the definition:
-- 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);
...
Take a look at fraction_width: it's a natural. This is the error you're currently getting, as you supply -27.
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)
Upvotes: 1