From 2535aa4f1be563a1764c0d6f680bc1361f7161f7 Mon Sep 17 00:00:00 2001 From: Niels Garibaldi Date: Thu, 20 Feb 2025 17:26:53 +0100 Subject: [PATCH] fpga: sim: Add coerce function to PkgMath Original-commit: 1f7ea94d8f9f1b9007fa1cd1d808f385139e264d --- sim/packages/PkgMath.sv | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sim/packages/PkgMath.sv b/sim/packages/PkgMath.sv index db5c158..49245c4 100644 --- a/sim/packages/PkgMath.sv +++ b/sim/packages/PkgMath.sv @@ -125,6 +125,12 @@ package PkgMath; return b; endfunction : fmin + // Coerce from real to 16-bit signed integer + function automatic shortint coerce_to_int16(real num); + if (num > SHORT_MAX) return SHORT_MAX; + if (num < SHORT_MIN) return SHORT_MIN; + return shortint'(num); + endfunction : coerce_to_int16 //--------------------------------------------------------------------------- // Template Functions (For any data type)