0

I am coding GL fractional operator in VHDL to put on FPGA. I am using IEEE.fixed_pkg package in order to have the ufixed and sfixed types and their operations

the problem is that I need at some part to to do raising to power calculation ( h**alpha) where both h and alpha are fixed numbers.

when I tried ** operator with ufixed, I got: No feasible entries for infix operator " ** ". I realized that this operation is not implemented in this package

Now, Is there a way to raise to power for fixed numbers (both base and exponent) without writing implementing the operation my self? ( as this is not the focus of the project).

Mohammed B.
  • 160
  • 1
  • 3
  • 13
  • Nope, welcome to HDL one-oh-one: if the compiler does not give it to you, you have to build it yourself. Note, with fixed numbers a simple loop will do the job, but you might need multiple clock cycles per calculation, – Oldfart Sep 18 '19 at 18:20
  • ** exists for integers, but dont try using it in real hardware unless the base is 2 – Tricky Sep 18 '19 at 19:47
  • @Oldfart Can u tell me how simple loop will do the job ? If the both base and exponent are fixed point decimals, how can a loop do the job ? – Mohammed B. Sep 18 '19 at 20:06
  • Fixed point are like standard integer multiplies, you just have to 'remember' where the decimal point is. Then a**b is the VHDL equivalent of: `p=1; while (b) { p=p*a; b--; }` – Oldfart Sep 18 '19 at 20:19
  • @Oldfart say we have 1.65 **2.1, how can u do this loop ? U are right when the exponent is integer only – Mohammed B. Sep 18 '19 at 20:46
  • To avoid confusion perhaps you could supply the declarations for `h` and `alpha` as well as how the calculation is used (and any object declarations involved). Exponentiation can be expressed as successive multiplication (IEEE Std 1076-2008 9.2.8 Miscellaneous operators). The length of the integer and fraction part products would increase for each fixed type multiplication. You could be better off using floating point types. –  Sep 18 '19 at 20:47
  • here [Power by squaring for negative exponents](https://stackoverflow.com/a/30962495/2521214) is all you need so either use power by squaring or rooting by squaring or use the `log,exp` approach if you got `log,exp` available ... – Spektre Sep 19 '19 at 07:43

0 Answers0