Boost logo

Boost :

Subject: Re: [boost] Fixed point integer proposal
From: Phil Endecott (spam_from_boost_dev_at_[hidden])
Date: 2009-06-25 17:52:53


John Bytheway wrote:
> Phil Endecott wrote:
>> I chose to try to behave as closely as possible to how built-in integer
>> types work. If I multiply uint8_t * uint8_t and assign the result to a
>> uint32_t, it works.
>
> Yes, but if you multiply a uint32_t by a uint32_t and assign to a
> uint64_t, then it doesn't work (assuming int == uint32_t). Do you want
> a fixed point library to mimic these apparent inconsistencies? It would
> probably make it less portable, since sizeof(int) isn't the same everywhere.

Here's another example: say I add two 8-bit values and assign the
result to a 16-bit value. Do I want to truncate the result of the
addition to 8 bits before the assignment? I found other corner-cases
where it's not obvious what to do. Using expression templates makes
some of these choices easier (specifically because you know the type
being assigned to) but it is much more complex to implement.

Phil.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk