I wanted to calculate and simulate clock phase shifting, when I ran into the problem that VHDL has no mod
operator defined for REAL values.
I check my old VHDL book and this online source. Both mention mod
for integers, but not for numbers (including floats).
GHDL also reports mod
as unknown.
Example calculation:
constant Period : TIME := 10.0 ns;
constant PhaseDelay : TIME := Period * (((Phase + 360.0) mod 360.0) / 360.0);
Why is the mod operator not defined for real values?
Modulo/Remainer definition for positive integer values a, b:a = (a/b)*b + (a REM b)
This equation can be used for remainer calculation on negative numers, too. The modulo operation on negative numbers need some tricks to handle the sign, but it's also base on add, sub, mult, div.
IEEE.math_real
comes with amod
operator defined as:X = Y*N + mod (X, Y)
. As far as I can see it was introduced in VHDL-93. – Paebbels