From fd44c8a605919d66695380ca62906915f486016f Mon Sep 17 00:00:00 2001 From: Eric Kooistra <kooistra@astron.nl> Date: Sat, 5 Feb 2022 13:39:28 +0100 Subject: [PATCH] Added atan2(y, x) with atan2(0, 0) = 0.0 without Error message. --- libraries/base/common/src/vhdl/common_pkg.vhd | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/libraries/base/common/src/vhdl/common_pkg.vhd b/libraries/base/common/src/vhdl/common_pkg.vhd index fb94e8a8be..7a3b48ecc0 100644 --- a/libraries/base/common/src/vhdl/common_pkg.vhd +++ b/libraries/base/common/src/vhdl/common_pkg.vhd @@ -210,6 +210,8 @@ PACKAGE common_pkg IS FUNCTION unpack_complex_im(data : INTEGER; w : NATURAL) RETURN INTEGER; -- pack order: im & re FUNCTION unpack_complex_im(data : STD_LOGIC_VECTOR; w : NATURAL) RETURN INTEGER; -- pack order: im & re + FUNCTION atan2(Y, X: REAL) RETURN REAL; -- = ARCTAN(Y, X) but returns 0 when Y = X = 0, without reporting Error: ARCTAN(0.0, 0.0) is undetermined + FUNCTION to_natural_arr(n : t_integer_arr; to_zero : BOOLEAN) RETURN t_natural_arr; -- if to_zero=TRUE then negative numbers are forced to zero, otherwise they will give a compile range error FUNCTION to_natural_arr(n : t_nat_natural_arr) RETURN t_natural_arr; FUNCTION to_integer_arr(n : t_natural_arr) RETURN t_integer_arr; @@ -756,6 +758,14 @@ PACKAGE BODY common_pkg IS RETURN TO_SINT(c_complex_slv(c_complex_w-1 DOWNTO w)); -- Im in MS part END; + FUNCTION atan2(Y, X: REAL) RETURN REAL IS + BEGIN + IF Y = 0.0 AND X = 0.0 THEN + RETURN 0.0; + ELSE + RETURN ARCTAN(Y, X); + END IF; + END; FUNCTION to_natural_arr(n : t_integer_arr; to_zero : BOOLEAN) RETURN t_natural_arr IS VARIABLE vN : t_integer_arr(n'LENGTH-1 DOWNTO 0); -- GitLab