Is there a way to create a new data type where I define the number of bits and arithmetic rules in Scala? I have a program that uses 32 bit floats but am trying to study how will affect the results.
I want to rewrite the program to do addition and multiplication on fixed point (d.f) numbers and return fixed point numbers of the same precision (d.f and not d1+d2.f1+f2). Furthermore, I want to have saturation so that when there is overflow, the result sticks to the maxed value rather than wrapping around. I also want to truncate bits if there is underflow.
From what I understand, the only 8 bit number is a short, and the only decimal numbers are floats and doubles. Can I somehow define this data type in Scala, or is the only way to do regular float arithmetic and round to the nearest number that can be represented by my desired type?
Thanks