Full precision arithmetic
Hi,
I hope I'm not missing something obvious, but I have a feature request.
Most of my work with fixed point numbers is in the realm of digital hardware for FPGAs, specifically the IEEE VHDL fixed point libraries. There, all operations are full precision. You get access to all bits of the result, and you manually trim away those you don't need. I'm working with the fixed
crate in an embedded ARM system, and I wanted to use the same approach. I was multiplying two instances of I1F15
and I wanted to get the result as I2F30
. But I couldn't find a direct way to do that.
Instead, it seems like you have to first cast each I1F15
to I2F30
and then perform the multiplication. However, the code here seems to indicate that the data size is doubled again before multiplication. So to multiply two 16-bit numbers with full precision, I have to cast them to 32-bit, then to 64-bit, perform the 64-bit multiplication, and cast back to 32-bit. Is the compiler able to optimize this down to a 32-bit multiplication? That seems tricky and therefore unlikely.
In any event, this all seems like a rather roundabout way to do full-precision multiplication. Would it be possible to add a way to directly access the double-width result of multiplication? That would also allow you to guarantee the Fixed
result is correct, e.g. multiplying an I3F13
by an I7F9
would yield an I10F22
.