|
Boost : |
Subject: Re: [boost] [Boost.FixedPoint] Choose notation
From: Michael Marcin (mike.marcin_at_[hidden])
Date: 2013-04-28 21:52:43
On 4/28/2013 5:18 PM, Dmitriy Gorbel wrote:
> Hello, community!
>
> I propose extending the Boost Libraries to provide binary
> fixed-point arithmetic, within GSOC project.
>
> Fixed-point library will provide nonnegative and negatable
> class templates for fractional arithmetic, and cardinal
> and integral for integer arithmetic. In total, four class templates.
>
> Fixed-point arithmetic use more than one notation, and I want
> to provide several notation to make happy all.
>
> Now I plan to implement two notations - Q notation and
> notation from C++1y proposal.
> Examples:
>
> C++1y proposal notation:
> cardinal<16> 0 <= n < 65536
> integral<4> -16 < n < 16
> nonnegative<8,-4> 0 <= n < 256 in increments of 2^-4 = 1/16
> negatable<16,-8> -65536 < n < 65536 in increments of 2^-8 = 1/256
>
> Q notation:
> cardinal<16> 0 <= n < 65536
> integral<4> -16 < n < 16
> nonnegative<8, 4> 0 <= n < 256 has 4 bit for fractional part
> negatable<16, 8> -65536 < n < 65536 has 8 bit for fractional part
>
> Please, help me to choose default notation, propose other
> notation, or just make any feedback.
>
I dislike the names. I don't really understand what the first 2 types
have to do with fixed-point math, other than maybe as an implementation
detail or degenerate fixed-point type (0 fractional bits).
As i understand it:
cardinal = fixed-width unsigned int
integral = fixed-width signed int
nonnegative = cardinal with radix point
negatable = integral with radix point
At least for Q notation which expects normal 2s complement binary
numbers under the hood I still think the ranges are incorrect.
The range on negatable<16, 8> should be (in binary)
[ 1<<(16+8-1), ~(1<<(16+8-1)) ]
convert to real by dividing by (1<<8) gives
[ -32768, 32,767.99609375 ]
The range on nonnegative<8,4> should be (in binary)
[ 0, (1<<(8+4))-1 ]
convert to real by dividing by (1<<4) gives
[ 0, 255.9375 ]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk