On Thu, Feb 26, 2015 at 02:26:18PM +0200, Petteri Aimonen wrote:
> Hi,
>
> > I think it should be easy enough to implement.
> > What do you think?
>
> The main advantage of binary fractions is that
> dividing by the denominator is fast, as it is only shifts.
> For example in multiplications you need to divide by the
> denominator.
hmm, yes binary is certainly faster. I was more thinking of it as a
high-precision alternative for finance and scientific calculations.
for instance some use decimal fixed points,
I guess you don't have those,
but SHCN's are better than them.
> Also if you allow varying denominators, you have to store
> that with every value, which basically means every 32 bit
> value becomes 64 bit instead.
>
> --
> Petteri
The denominator would always be the same for a given type.
the maximum SHCN that fits in the alloted bits.
if C is used to show SHCN: CQ16.16 would always be 16bit SHCN
adding, subtracting, multiplying and dividing with whole numbers
for the SHCN fixed-points numbers I've tried is fairly trivial.
i.e. 8bit unisigned SHCN (base 12) little-endian
0011 0010 (3+2/12) ~pi
*2 =
0110 0100 (6+4/12) ~2pi
simply apply to each, and carry overflow.
(3+2/12)+(2+10/12) =
(6+0/12)
though multiplying and dividing by fractions would certainly be more
difficult.
(3+2/12)*(2+9/12) =
(8+9/12)
not sure how to easily accomplish that.
though for high precision it may be very useful.
If precision is outside the scope of libfixmath,
please direct me to a more suitable libre software project.
--
Logan
>
> --
> You received this message because you are subscribed to the Google Groups "libfixmath" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
libfixmath+...@googlegroups.com.
> To post to this group, send email to
libfi...@googlegroups.com.
> Visit this group at
http://groups.google.com/group/libfixmath.
> For more options, visit
https://groups.google.com/d/optout.