From d610c00dea368358edeee08cad2e330d9ebe1c30 Mon Sep 17 00:00:00 2001 From: Eric Kooistra <kooistra@astron.nl> Date: Mon, 1 Feb 2021 08:27:49 +0100 Subject: [PATCH] Improved and clarified definition of sign of resolution_w in TO_SREAL(). --- libraries/base/common/src/vhdl/common_pkg.vhd | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libraries/base/common/src/vhdl/common_pkg.vhd b/libraries/base/common/src/vhdl/common_pkg.vhd index f26318f930..79591b0b30 100644 --- a/libraries/base/common/src/vhdl/common_pkg.vhd +++ b/libraries/base/common/src/vhdl/common_pkg.vhd @@ -1793,12 +1793,13 @@ PACKAGE BODY common_pkg IS VARIABLE v_real : REAL := TO_SREAL(svec); BEGIN -- Then scale to real: - -- . The resolution_w is the number of bits that LSbit 0 in svec is after or before the fixed point. - -- . The real value is then scaled by scaling the integer value by 2**resolution_w: + -- . The resolution_w is the number of bits that LSbit 0 in svec(HIGH-1 DOWNTO 0) is after + -- (when resolution_w > 0), or before (when resolution_w < 0) the fixed point. + -- . The real value is then scaled by scaling the integer value by 2**(-1 * resolution_w): -- . resolution_w = 0 : scale by 2**0 = 1, so no scaling and the value is treated as an integer -- . resolution_w < 0 : scale up -- . resolution_w > 0 : scale down - RETURN v_real * 2.0**REAL(resolution_w); + RETURN v_real * 2.0**REAL(-1 * resolution_w); END; -- GitLab