@FRob's answer to my recent question (to_float() and dividing errors) led me to analyze the float_pkg_c.vhdl, particularly the to_float method.
When trying the following operation:
variable denum : integer;
variable num : integer;
variable dividend : float (4 downto -27);
begin
dividend := to_float(num, 4, 27) / to_float(denum, 4, 27);
...
I keep getting this error: "Error (10454): VHDL syntax error at float_pkg_c.vhdl(3840): right bound of range must be a constant"
Now, at the mentioned line:
for I in fract'high downto maximum (fract'high - shift + 1, 0) loop
The variable fract is calculated based on the parameter fraction_width
, which is 27 in my case, therefore a constant.
However, the shift
variable is calculated based on the arg
parameter (basically, a log2 of the absolute value of arg
), which is the num
variable in my case, therefore not a constant.
So, the error is clear, but my question is: How can I cast a integer variable to float?
This is the definition of to_float:
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
What is even more confusing to me is that arg
in the above definition is not required ti be a constant.