Topic: On P0037 - Fixed-Point Real Numbers


Author: Robert Ramey <ramey@rrsd.com>
Date: Sun, 28 Feb 2016 14:49:04 -0800
Raw View
http://johnmcfarlane.github.io/fixed_point/papers/p0037.html

This proposal is interesting to me.  It addresses something really
missing from the C++ standard.  There are many, many, many versions
code around which address the issue, other standards proposals etc.

Basically the idea is a class:

template<typename BaseIntegerType = int, Exponent = 0>
struct fixed_point;

so a value such as 8.25 would be stored in fixed_point<int16_t, 4>
as a 16 bit integer 00001000[.]0100 where [.] is an implicit
radix point.  Arithmentic, conversion display, etc. etc. all follow
from this basic idea.

The document is well researched and is backed up by a github repo
with a reference implementation with documentation, tests and examples.

Soooo .. what's not to like?

Actually I do like it.  I like it so much that I would like to
see the author/committee think bigger. I would like to see it
generallized from representing numbers as

integer part + fractional part where fractional part is 2^n (some power
of 2)

to a more general:

integer part + fractional part where fraction part is any integer.

So the template signature would now look like:

template<typename BaseIntegerType = int, in FractionalPartMax>
struct fixed_point;

So one would use this for thinks like:

using money = fixed_point<long, -100>  // dollars and cents
using degree = fixed_point<int, -60>  // degrees and minutes
using eggs = fixed_point<int, -12>    // cartons of eggs and eggs

as well as the original uses like

using megabytes = fixed_point<long, 6> // bytes in mega bytes
using pixel_intensity fixed_point<int8_t, 8>  // small float for pixel
intensity - in this case since 8 == 2^3 it's equivalent to the
current fixed_point<int8_t, -3>

Would this be a big change?  Not nearly as much as one would think. It
turns out that most of the implementation consists of variations on
the following two operations:

a) pow<2, exponent> // render value from base^exponent
b) internal value <</>> exponent  // normalize values for arithmetic
operations

These operations would be replaced with

a) internal value * radix // convert interval value to external form
b) value / radix + value & radix// convert external value to interal form

Or something similar.

internal representation would be in radix base
1111[.]1111

In this case, the powers of two would be specializations which would
exploit bit shift operations as they do now.  So the final result would
be no less efficient than the current implementation - but more general
and much more widely useful.

Robert Ramey


--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/navth1%2467p%241%40ger.gmane.org.

.


Author: FrankHB1989 <frankhb1989@gmail.com>
Date: Sun, 28 Feb 2016 17:26:16 -0800 (PST)
Raw View
------=_Part_3110_1439742516.1456709176299
Content-Type: multipart/alternative;
 boundary="----=_Part_3111_2026518863.1456709176299"

------=_Part_3111_2026518863.1456709176299
Content-Type: text/plain; charset=UTF-8

It seems that a runtime representation of std::ratio should come first.

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/b3272c6e-1142-47bd-8bd1-621256896499%40isocpp.org.

------=_Part_3111_2026518863.1456709176299
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">It seems that a runtime representation of std::ratio shoul=
d come first.<br></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/b3272c6e-1142-47bd-8bd1-621256896499%=
40isocpp.org?utm_medium=3Demail&utm_source=3Dfooter">https://groups.google.=
com/a/isocpp.org/d/msgid/std-proposals/b3272c6e-1142-47bd-8bd1-621256896499=
%40isocpp.org</a>.<br />

------=_Part_3111_2026518863.1456709176299--
------=_Part_3110_1439742516.1456709176299--

.


Author: Marc Mutz <marc.mutz@kdab.com>
Date: Mon, 20 Jun 2016 09:24:34 +0200
Raw View
On Sunday 28 February 2016 23:49:04 Robert Ramey wrote:
> integer part + fractional part where fraction part is any integer.

.... or a std::ratio<>. I don't quite like that we'll have two independent
fixed-point implementations in the standard: duration and fixed_point.

I'm sure this has been discussed, but P0037R2 doesn't contain anything about
<ratio>.

So I'd like to ask why a fixed_point is represented by an exponent, and not a
std::ratio object:

   using dollars = fixed_point<int, ratio<1,100>>; // in units of cents

Though maybe then the fixed_point name is no longer so good, and something
containing "discrete" might be better.

If the answer is "we want to restrict to an integer number of bits for
performance", then the counter-argument would be that that can be done using
specialisation of the operations based on whether the std::ratio is of the
form 2^-N for some N.

Thanks,
Marc

--
Marc Mutz <marc.mutz@kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - Qt, C++ and OpenGL Experts

.


Author: Robert Ramey <ramey@rrsd.com>
Date: Mon, 20 Jun 2016 07:45:11 -0700
Raw View
Obviously you're absolutely correct on this.  It seems that the whole
job is aready done - and in the most general way.

But one thing bothers me - with std::ratio I can't specify the
underlying value type.  One of the fixed_binary use cases is to use it
for a pixel

fixed_binary<unsigned char, 3>  // or something like that

how could std::ration be used to address this?

Robert Ramey

On 6/20/16 12:24 AM, Marc Mutz wrote:
> On Sunday 28 February 2016 23:49:04 Robert Ramey wrote:
>> integer part + fractional part where fraction part is any integer.
>
> ... or a std::ratio<>. I don't quite like that we'll have two independent
> fixed-point implementations in the standard: duration and fixed_point.
>
> I'm sure this has been discussed, but P0037R2 doesn't contain anything about
> <ratio>.
>
> So I'd like to ask why a fixed_point is represented by an exponent, and not a
> std::ratio object:
>
>    using dollars = fixed_point<int, ratio<1,100>>; // in units of cents
>
> Though maybe then the fixed_point name is no longer so good, and something
> containing "discrete" might be better.
>
> If the answer is "we want to restrict to an integer number of bits for
> performance", then the counter-argument would be that that can be done using
> specialisation of the operations based on whether the std::ratio is of the
> form 2^-N for some N.
>
> Thanks,
> Marc
>

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/0e429c80-84d9-4c6e-93ff-6c5dcb26c9d4%40rrsd.com.

.


Author: Marc Mutz <marc.mutz@kdab.com>
Date: Mon, 20 Jun 2016 17:58:39 +0200
Raw View
On Monday 20 June 2016 16:45:11 Robert Ramey wrote:
> Obviously you're absolutely correct on this.  It seems that the whole
> job is aready done - and in the most general way.
>
> But one thing bothers me - with std::ratio I can't specify the
> underlying value type.  One of the fixed_binary use cases is to use it
> for a pixel
>
> fixed_binary<unsigned char, 3>  // or something like that
>
> how could std::ration be used to address this?

The same way as std::chrono::duration does. Ratio is just that: a ratio. The
underlying type is another template argument:

    template <Arithmetic Representation, class Period = std::ratio<1>>
    class duration;

    template <Arithmetic Representation,
               Ratio R = std::ratio<1, width<Representation>/2>>
    class fixed_point;

http://en.cppreference.com/w/cpp/chrono/duration

Thanks,
Marc

> Robert Ramey
>
> On 6/20/16 12:24 AM, Marc Mutz wrote:
> > On Sunday 28 February 2016 23:49:04 Robert Ramey wrote:
> >> integer part + fractional part where fraction part is any integer.
> >
> > ... or a std::ratio<>. I don't quite like that we'll have two independent
> > fixed-point implementations in the standard: duration and fixed_point.
> >
> > I'm sure this has been discussed, but P0037R2 doesn't contain anything
> > about <ratio>.
> >
> > So I'd like to ask why a fixed_point is represented by an exponent, and
> > not a
> >
> > std::ratio object:
> >    using dollars = fixed_point<int, ratio<1,100>>; // in units of cents
> >
> > Though maybe then the fixed_point name is no longer so good, and
> > something containing "discrete" might be better.
> >
> > If the answer is "we want to restrict to an integer number of bits for
> > performance", then the counter-argument would be that that can be done
> > using specialisation of the operations based on whether the std::ratio
> > is of the form 2^-N for some N.
> >
> > Thanks,
> > Marc

--
Marc Mutz <marc.mutz@kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - Qt, C++ and OpenGL Experts

.


Author: Robert Ramey <ramey@rrsd.com>
Date: Mon, 20 Jun 2016 09:26:54 -0700
Raw View
On 6/20/16 8:58 AM, Marc Mutz wrote:
> On Monday 20 June 2016 16:45:11 Robert Ramey wrote:
>> Obviously you're absolutely correct on this.  It seems that the whole
>> job is aready done - and in the most general way.
>>
>> But one thing bothers me - with std::ratio I can't specify the
>> underlying value type.  One of the fixed_binary use cases is to use it
>> for a pixel
>>
>> fixed_binary<unsigned char, 3>  // or something like that
>>
>> how could std::ration be used to address this?
>
> The same way as std::chrono::duration does. Ratio is just that: a ratio. The
> underlying type is another template argument:
>
>     template <Arithmetic Representation, class Period = std::ratio<1>>
>     class duration;
>
>     template <Arithmetic Representation,
>                Ratio R = std::ratio<1, width<Representation>/2>>
>     class fixed_point;

hmmmm - ration takes two arguments which must both be std::intmax_t.
This suggests to me that the internal representation is ... an
std::intmax_t ?  I don't see a way to change this to say and unsigned char.


>
> http://en.cppreference.com/w/cpp/chrono/duration
>
> Thanks,
> Marc
>
>> Robert Ramey
>>
>> On 6/20/16 12:24 AM, Marc Mutz wrote:
>>> On Sunday 28 February 2016 23:49:04 Robert Ramey wrote:
>>>> integer part + fractional part where fraction part is any integer.
>>>
>>> ... or a std::ratio<>. I don't quite like that we'll have two independent
>>> fixed-point implementations in the standard: duration and fixed_point.
>>>
>>> I'm sure this has been discussed, but P0037R2 doesn't contain anything
>>> about <ratio>.
>>>
>>> So I'd like to ask why a fixed_point is represented by an exponent, and
>>> not a
>>>
>>> std::ratio object:
>>>    using dollars = fixed_point<int, ratio<1,100>>; // in units of cents
>>>
>>> Though maybe then the fixed_point name is no longer so good, and
>>> something containing "discrete" might be better.
>>>
>>> If the answer is "we want to restrict to an integer number of bits for
>>> performance", then the counter-argument would be that that can be done
>>> using specialisation of the operations based on whether the std::ratio
>>> is of the form 2^-N for some N.
>>>
>>> Thanks,
>>> Marc
>

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/d31c1e2c-3520-b801-84f3-384848ec0e5b%40rrsd.com.

.


Author: Anthony Williams <anthony.ajw@gmail.com>
Date: Mon, 20 Jun 2016 17:34:38 +0100
Raw View
On 20/06/16 17:26, Robert Ramey wrote:
> On 6/20/16 8:58 AM, Marc Mutz wrote:
>> On Monday 20 June 2016 16:45:11 Robert Ramey wrote:
>>> Obviously you're absolutely correct on this.  It seems that the whole
>>> job is aready done - and in the most general way.
>>>
>>> But one thing bothers me - with std::ratio I can't specify the
>>> underlying value type.  One of the fixed_binary use cases is to use it
>>> for a pixel
>>>
>>> fixed_binary<unsigned char, 3>  // or something like that
>>>
>>> how could std::ration be used to address this?
>>
>> The same way as std::chrono::duration does. Ratio is just that: a
>> ratio. The
>> underlying type is another template argument:
>>
>>     template <Arithmetic Representation, class Period = std::ratio<1>>
>>     class duration;
>>
>>     template <Arithmetic Representation,
>>                Ratio R = std::ratio<1, width<Representation>/2>>
>>     class fixed_point;
>
> hmmmm - ration takes two arguments which must both be std::intmax_t.
> This suggests to me that the internal representation is ... an
> std::intmax_t ?  I don't see a way to change this to say and unsigned char.

The ratio is a fraction i.e. numerator/denominator. The numerator and
denominator are both intmax_t, but they are static members and
compile-time constants.

The value of the duration or fixed_point or whatever can be any
arithmetic type.

So, for duration, we can have duration<double,std::ratio<1,10>>, which
is 1/10ths of a second, stored as a double. duration<unsigned
char,std::ratio<1,10>> is 1/10ths of a second, stored as an unsigned char.

The same could apply to fixed_point<unsigned char,std::ratio<1,100>>,
which would store the number of 100ths, in an unsigned char.

Anthony
--
Author of C++ Concurrency in Action     http://www.stdthread.co.uk/book/
just::thread C++11 thread library             http://www.stdthread.co.uk
Just Software Solutions Ltd       http://www.justsoftwaresolutions.co.uk
15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/57681B1E.70008%40gmail.com.

.


Author: Andrey Semashev <andrey.semashev@gmail.com>
Date: Mon, 20 Jun 2016 19:40:22 +0300
Raw View
On Monday, 20 June 2016 19:34:39 MSK Robert Ramey wrote:
> On 6/20/16 8:58 AM, Marc Mutz wrote:
> > On Monday 20 June 2016 16:45:11 Robert Ramey wrote:
> >> Obviously you're absolutely correct on this.  It seems that the whole
> >> job is aready done - and in the most general way.
> >>
> >> But one thing bothers me - with std::ratio I can't specify the
> >> underlying value type.  One of the fixed_binary use cases is to use it
> >> for a pixel
> >>
> >> fixed_binary<unsigned char, 3>  // or something like that
> >>
> >> how could std::ration be used to address this?
> >
> > The same way as std::chrono::duration does. Ratio is just that: a ratio.
> > The>
> > underlying type is another template argument:
> >     template <Arithmetic Representation, class Period = std::ratio<1>>
> >     class duration;
> >
> >     template <Arithmetic Representation,
> >
> >                Ratio R = std::ratio<1, width<Representation>/2>>
> >
> >     class fixed_point;
>
> hmmmm - ration takes two arguments which must both be std::intmax_t.
> This suggests to me that the internal representation is ... an
> std::intmax_t ?  I don't see a way to change this to say and unsigned char.

std::ratio is a compile time (rational) constant. It doesn't matter what types
are used to represent that constant, as long as they are large enough.

The representation of fixed_point and chrono::duration is defined solely by
the first template argument.

By the way, I'm not sure why the first template argument of fixed_point is an
arithmetic type. Shouldn't it be an integral type? If the representation is a
floating point type then the fixed_point name is misleading.

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/2631120.mvYlf7T0AQ%40lastique-pc.

.


Author: Robert Ramey <ramey@rrsd.com>
Date: Mon, 20 Jun 2016 10:24:25 -0700
Raw View
On 6/20/16 9:34 AM, Anthony Williams wrote:
> On 20/06/16 17:26, Robert Ramey wrote:
>> On 6/20/16 8:58 AM, Marc Mutz wrote:
>>> On Monday 20 June 2016 16:45:11 Robert Ramey wrote:
>>>> Obviously you're absolutely correct on this.  It seems that the whole
>>>> job is aready done - and in the most general way.
>>>>
>>>> But one thing bothers me - with std::ratio I can't specify the
>>>> underlying value type.  One of the fixed_binary use cases is to use it
>>>> for a pixel
>>>>
>>>> fixed_binary<unsigned char, 3>  // or something like that
>>>>
>>>> how could std::ration be used to address this?
>>>
>>> The same way as std::chrono::duration does. Ratio is just that: a
>>> ratio. The
>>> underlying type is another template argument:
>>>
>>>     template <Arithmetic Representation, class Period = std::ratio<1>>
>>>     class duration;
>>>
>>>     template <Arithmetic Representation,
>>>                Ratio R = std::ratio<1, width<Representation>/2>>
>>>     class fixed_point;
>>
>> hmmmm - ration takes two arguments which must both be std::intmax_t.
>> This suggests to me that the internal representation is ... an
>> std::intmax_t ?  I don't see a way to change this to say and unsigned char.
>
> The ratio is a fraction i.e. numerator/denominator. The numerator and
> denominator are both intmax_t, but they are static members and
> compile-time constants.
>
> The value of the duration or fixed_point or whatever can be any
> arithmetic type.
>
> So, for duration, we can have duration<double,std::ratio<1,10>>, which
> is 1/10ths of a second, stored as a double. duration<unsigned
> char,std::ratio<1,10>> is 1/10ths of a second, stored as an unsigned char.
>
> The same could apply to fixed_point<unsigned char,std::ratio<1,100>>,
> which would store the number of 100ths, in an unsigned char.

OK - so instead of

fixed_binary<T, exp>

or

fixed_binary<T, radix>

one would use

fixed_binary<T, std::ratio<1, 100>>

Soooooo - as things stand down, there is not component in the standard
library which implements the functionality of the proposed fixed_binary.
  The ideas in this thread suggest that the interface of such an object
should be based on std::ratio rather than the current proposals and my
subsequent suggestion.  Correct?

Robert Ramey

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/f5a1d980-daa5-83ef-5aae-f662372e184f%40rrsd.com.

.


Author: John McFarlane <mcfarlane.john@gmail.com>
Date: Mon, 20 Jun 2016 13:17:02 -0700
Raw View
--94eb2c128ec233d31c0535bb630b
Content-Type: text/plain; charset=UTF-8

If `fixed_point` took a `ratio` object, its range would be reduced to the
range of `maxint_t`. Here's an example of functionality what would not be
possible with such a limitation: [
https://github.com/johnmcfarlane/fixed_point/blob/5d1a016b865ecbcf8479059fdabae9406cff984a/src/test/index.cpp#L94
].

On Mon, Jun 20, 2016 at 12:24 AM, Marc Mutz <marc.mutz@kdab.com> wrote:

> On Sunday 28 February 2016 23:49:04 Robert Ramey wrote:
> > integer part + fractional part where fraction part is any integer.
>
> ... or a std::ratio<>. I don't quite like that we'll have two independent
> fixed-point implementations in the standard: duration and fixed_point.
>
> I'm sure this has been discussed, but P0037R2 doesn't contain anything
> about
> <ratio>.
>
> So I'd like to ask why a fixed_point is represented by an exponent, and
> not a
> std::ratio object:
>
>    using dollars = fixed_point<int, ratio<1,100>>; // in units of cents
>
> Though maybe then the fixed_point name is no longer so good, and something
> containing "discrete" might be better.
>
> If the answer is "we want to restrict to an integer number of bits for
> performance", then the counter-argument would be that that can be done
> using
> specialisation of the operations based on whether the std::ratio is of the
> form 2^-N for some N.
>
> Thanks,
> Marc
>
> --
> Marc Mutz <marc.mutz@kdab.com> | Senior Software Engineer
> KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
> Tel: +49-30-521325470
> KDAB - Qt, C++ and OpenGL Experts
>

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CABPJVnRchMhpJ31FjGo9NW5tvwJUP8KuExBRtc_yXNJGsqU7hA%40mail.gmail.com.

--94eb2c128ec233d31c0535bb630b
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">If `=
fixed_point` took a `ratio` object, its range would be reduced to the range=
 of `maxint_t`. Here&#39;s an example of functionality what would not be po=
ssible with such a limitation: [<a href=3D"https://github.com/johnmcfarlane=
/fixed_point/blob/5d1a016b865ecbcf8479059fdabae9406cff984a/src/test/index.c=
pp#L94">https://github.com/johnmcfarlane/fixed_point/blob/5d1a016b865ecbcf8=
479059fdabae9406cff984a/src/test/index.cpp#L94</a>].<br></div><div class=3D=
"gmail_quote"><br>On Mon, Jun 20, 2016 at 12:24 AM, Marc Mutz <span dir=3D"=
ltr">&lt;<a href=3D"mailto:marc.mutz@kdab.com" target=3D"_blank">marc.mutz@=
kdab.com</a>&gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=
=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding=
-left:1ex">On Sunday 28 February 2016 23:49:04 Robert Ramey wrote:<br>
&gt; integer part + fractional part where fraction part is any integer.<br>
<br>
.... or a std::ratio&lt;&gt;. I don&#39;t quite like that we&#39;ll have two=
 independent<br>
fixed-point implementations in the standard: duration and fixed_point.<br>
<br>
I&#39;m sure this has been discussed, but P0037R2 doesn&#39;t contain anyth=
ing about<br>
&lt;ratio&gt;.<br>
<br>
So I&#39;d like to ask why a fixed_point is represented by an exponent, and=
 not a<br>
std::ratio object:<br>
<br>
=C2=A0 =C2=A0using dollars =3D fixed_point&lt;int, ratio&lt;1,100&gt;&gt;; =
// in units of cents<br>
<br>
Though maybe then the fixed_point name is no longer so good, and something<=
br>
containing &quot;discrete&quot; might be better.<br>
<br>
If the answer is &quot;we want to restrict to an integer number of bits for=
<br>
performance&quot;, then the counter-argument would be that that can be done=
 using<br>
specialisation of the operations based on whether the std::ratio is of the<=
br>
form 2^-N for some N.<br>
<br>
Thanks,<br>
Marc<br>
<span class=3D""><font color=3D"#888888"><br>
--<br>
Marc Mutz &lt;<a href=3D"mailto:marc.mutz@kdab.com">marc.mutz@kdab.com</a>&=
gt; | Senior Software Engineer<br>
KDAB (Deutschland) GmbH &amp; Co.KG, a KDAB Group Company<br>
Tel: <a href=3D"tel:%2B49-30-521325470" value=3D"+4930521325470">+49-30-521=
325470</a><br>
KDAB - Qt, C++ and OpenGL Experts<br>
</font></span></blockquote></div><br></div></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CABPJVnRchMhpJ31FjGo9NW5tvwJUP8KuExBR=
tc_yXNJGsqU7hA%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter">htt=
ps://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CABPJVnRchMhpJ31F=
jGo9NW5tvwJUP8KuExBRtc_yXNJGsqU7hA%40mail.gmail.com</a>.<br />

--94eb2c128ec233d31c0535bb630b--

.


Author: Anthony Williams <anthony.ajw@gmail.com>
Date: Tue, 21 Jun 2016 08:16:57 +0100
Raw View
--001a1144b7d045c7000535c49b40
Content-Type: text/plain; charset=UTF-8

On 20 Jun 2016 9:17 p.m., "John McFarlane" <mcfarlane.john@gmail.com> wrote:
>
> If `fixed_point` took a `ratio` object, its range would be reduced to the
range of `maxint_t`. Here's an example of functionality what would not be
possible with such a limitation: [
https://github.com/johnmcfarlane/fixed_point/blob/5d1a016b865ecbcf8479059fdabae9406cff984a/src/test/index.cpp#L94
].
>

It could be specified to take either a std::ratio or a new
exponent<base,power> template.

Anthony

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAMWMAmXSX%2Biou48Yv-OiNFtiSGoWp2GHJcsbDfszA%2BvC92fnzQ%40mail.gmail.com.

--001a1144b7d045c7000535c49b40
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<p dir=3D"ltr"><br>
On 20 Jun 2016 9:17 p.m., &quot;John McFarlane&quot; &lt;<a href=3D"mailto:=
mcfarlane.john@gmail.com">mcfarlane.john@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; If `fixed_point` took a `ratio` object, its range would be reduced to =
the range of `maxint_t`. Here&#39;s an example of functionality what would =
not be possible with such a limitation: [<a href=3D"https://github.com/john=
mcfarlane/fixed_point/blob/5d1a016b865ecbcf8479059fdabae9406cff984a/src/tes=
t/index.cpp#L94">https://github.com/johnmcfarlane/fixed_point/blob/5d1a016b=
865ecbcf8479059fdabae9406cff984a/src/test/index.cpp#L94</a>].<br>
&gt;</p>
<p dir=3D"ltr">It could be specified to take either a std::ratio or a new e=
xponent&lt;base,power&gt; template.</p>
<p dir=3D"ltr">Anthony</p>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CAMWMAmXSX%2Biou48Yv-OiNFtiSGoWp2GHJc=
sbDfszA%2BvC92fnzQ%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfooter"=
>https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CAMWMAmXSX%2B=
iou48Yv-OiNFtiSGoWp2GHJcsbDfszA%2BvC92fnzQ%40mail.gmail.com</a>.<br />

--001a1144b7d045c7000535c49b40--

.


Author: Marc Mutz <marc.mutz@kdab.com>
Date: Tue, 21 Jun 2016 10:04:02 +0200
Raw View
On Monday 20 June 2016 22:17:02 John McFarlane wrote:
> If `fixed_point` took a `ratio` object, its range would be reduced to the
> range of `maxint_t`. Here's an example of functionality what would not be
> possible with such a limitation: [
> https://github.com/johnmcfarlane/fixed_point/blob/5d1a016b865ecbcf8479059fd
> abae9406cff984a/src/test/index.cpp#L94 ].

The same limitation exists for std::chrono::duration and it, too, would benefit
from a fix. This is a reason to extend/fix std::ratio, not one for not using it.

Thanks,
Marc

--
Marc Mutz <marc.mutz@kdab.com> | Senior Software Engineer
KDAB (Deutschland) GmbH & Co.KG, a KDAB Group Company
Tel: +49-30-521325470
KDAB - Qt, C++ and OpenGL Experts

.


Author: John McFarlane <mcfarlane.john@gmail.com>
Date: Tue, 21 Jun 2016 01:06:47 -0700
Raw View
--94eb2c089a927457910535c54dc3
Content-Type: text/plain; charset=UTF-8

This does sound like something more general than fixed-point.

Continuing on from (
https://github.com/johnmcfarlane/fixed_point/blob/master/doc/p0037r2.md#non-binary-radixes
):

    template<typename Rep, typename Scale>
    class discrete;

    template<typename Rep, int Exp, int Radix>
    class basic_fixed_point : public discrete<Rep, exponent<Exp, Radix>>;

    template<typename Rep, int Exp>
    using fixed_point = basic_fixed_point<Rep, Exp, 2>;

Scale would be a concept which performs static upscale and downscale and
implements arithmetic operators. `ratio` could maybe be adapted to this
task alongside `exponent`.

On Tue, Jun 21, 2016 at 12:16 AM, Anthony Williams <anthony.ajw@gmail.com>
wrote:

>
> On 20 Jun 2016 9:17 p.m., "John McFarlane" <mcfarlane.john@gmail.com>
> wrote:
> >
> > If `fixed_point` took a `ratio` object, its range would be reduced to
> the range of `maxint_t`. Here's an example of functionality what would not
> be possible with such a limitation: [
> https://github.com/johnmcfarlane/fixed_point/blob/5d1a016b865ecbcf8479059fdabae9406cff984a/src/test/index.cpp#L94
> ].
> >
>
> It could be specified to take either a std::ratio or a new
> exponent<base,power> template.
>
> Anthony
>

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CABPJVnQ%3Dqj9LwnY12RbQ%2BTgovnvES57SsPhbzt%2BqsVtpgoJnzg%40mail.gmail.com.

--94eb2c089a927457910535c54dc3
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div><div><div><div><div>This does sound like something mo=
re general than fixed-point. <br><br>Continuing on from (<a href=3D"https:/=
/github.com/johnmcfarlane/fixed_point/blob/master/doc/p0037r2.md#non-binary=
-radixes">https://github.com/johnmcfarlane/fixed_point/blob/master/doc/p003=
7r2.md#non-binary-radixes</a>):<br><br></div>=C2=A0=C2=A0=C2=A0 template&lt=
;typename Rep, typename Scale&gt;<br></div>=C2=A0=C2=A0=C2=A0 class discret=
e;<br><br></div>=C2=A0=C2=A0=C2=A0 template&lt;typename Rep, int Exp, int R=
adix&gt;<br>=C2=A0=C2=A0=C2=A0 class basic_fixed_point : public discrete&lt=
;Rep, exponent&lt;Exp, Radix&gt;&gt;;<br><br>=C2=A0=C2=A0=C2=A0 template&lt=
;typename Rep, int Exp&gt;<br>=C2=A0=C2=A0=C2=A0 using fixed_point =3D basi=
c_fixed_point&lt;Rep, Exp, 2&gt;;<br><br></div>Scale would be a concept whi=
ch performs static upscale and downscale and implements arithmetic operator=
s. `ratio` could maybe be adapted to this task alongside `exponent`.<br></d=
iv></div><div class=3D"gmail_extra"><br><div class=3D"gmail_quote">On Tue, =
Jun 21, 2016 at 12:16 AM, Anthony Williams <span dir=3D"ltr">&lt;<a href=3D=
"mailto:anthony.ajw@gmail.com" target=3D"_blank">anthony.ajw@gmail.com</a>&=
gt;</span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:0 0 =
0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=3D""><p dir=
=3D"ltr"><br>
On 20 Jun 2016 9:17 p.m., &quot;John McFarlane&quot; &lt;<a href=3D"mailto:=
mcfarlane.john@gmail.com" target=3D"_blank">mcfarlane.john@gmail.com</a>&gt=
; wrote:<br>
&gt;<br>
&gt; If `fixed_point` took a `ratio` object, its range would be reduced to =
the range of `maxint_t`. Here&#39;s an example of functionality what would =
not be possible with such a limitation: [<a href=3D"https://github.com/john=
mcfarlane/fixed_point/blob/5d1a016b865ecbcf8479059fdabae9406cff984a/src/tes=
t/index.cpp#L94" target=3D"_blank">https://github.com/johnmcfarlane/fixed_p=
oint/blob/5d1a016b865ecbcf8479059fdabae9406cff984a/src/test/index.cpp#L94</=
a>].<br>
&gt;</p>
</span><p dir=3D"ltr">It could be specified to take either a std::ratio or =
a new exponent&lt;base,power&gt; template.</p><span class=3D"HOEnZb"><font =
color=3D"#888888">
<p dir=3D"ltr">Anthony</p>
</font></span></blockquote></div><br></div>

<p></p>

-- <br />
You received this message because you are subscribed to the Google Groups &=
quot;ISO C++ Standard - Future Proposals&quot; group.<br />
To unsubscribe from this group and stop receiving emails from it, send an e=
mail to <a href=3D"mailto:std-proposals+unsubscribe@isocpp.org">std-proposa=
ls+unsubscribe@isocpp.org</a>.<br />
To post to this group, send email to <a href=3D"mailto:std-proposals@isocpp=
..org">std-proposals@isocpp.org</a>.<br />
To view this discussion on the web visit <a href=3D"https://groups.google.c=
om/a/isocpp.org/d/msgid/std-proposals/CABPJVnQ%3Dqj9LwnY12RbQ%2BTgovnvES57S=
sPhbzt%2BqsVtpgoJnzg%40mail.gmail.com?utm_medium=3Demail&utm_source=3Dfoote=
r">https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/CABPJVnQ%3D=
qj9LwnY12RbQ%2BTgovnvES57SsPhbzt%2BqsVtpgoJnzg%40mail.gmail.com</a>.<br />

--94eb2c089a927457910535c54dc3--

.