Topic: Rationals


Author: Douglas Boffey <douglas.boffey@gmail.com>
Date: Sat, 31 Jan 2015 13:05:02 -0800 (PST)
Raw View
------=_Part_2140_1584828887.1422738302797
Content-Type: multipart/alternative;
 boundary="----=_Part_2141_979430068.1422738302797"

------=_Part_2141_979430068.1422738302797
Content-Type: text/plain; charset=UTF-8

I would like to see a rational class:

namespace std {
  template <typename T>
  class rational {
  public:
    using numerator_type = T;
    using denominator_type = typename make_unsigned<T>::type;
  private:
    numerator_type num;
    denominator_type den;
  public:
    // ctors & dtors
    rational(numerator_type n = 0, denominator_type d = 1);
    template <typename U>
    rational(const rational<U> &);
    rational(const rational<T> &) = default;
    template <typename U>
    rational(rational<U> &&);
    rational(rational<T> &&) = default;
    ~rational() = default;

    // assignment
    template <typename U>
    rational &operator=(const rational<U> &);
    rational &operator=(const rational<T> &) = default;
    template <typename U>
    rational &operator=(rational<U> &&);
    rational &operator=(rational<T> &&) = default;

    // standard operators
    template <typename U>
    rational &operator+=(const rational<U> &rhs);
    template <typename U>
    rational &operator-=(const rational<U> &rhs);
    template <typename U>
    rational &operator*=(const rational<U> &rhs);
    template <typename U>
    rational &operator/=(const rational<U> &rhs);
    rational operator+() const;
    enable_if<is_signed<T>::type, rational operator-()>;

    // member accessors
    numerator_type numerator() const; // Note: r-value
    denominator_type denominator() const; // Nate: r-value

    // conversion
    explicit operator bool() const; // num != 0 || den == 0
    explicit operator float() const;
    explicit operator double() const;
    explicit operator long double() const;

    numerator_type floor() const;
    numerator_type ceiling() const;
  };
  template <typename T, typename U>
  auto operator+(const rational<T> &lhs, const rational<T> &rhs);
  // sim. for operators -, * and /

  template <typename T>
  ostream &operator<<(ostream &, const rational<T> &);
  template <typename T>
  istream &operator>>(istream &, const rational<T> &);

  // Comparison operators
  template <typename T, typename U>
  bool operator==(const rational<T> &, const rational<U> &);
  // sim. for operators !=, <, >, <= and >=
} // namespace std



Three values would be represented by den == 0:
-infinity, if num == -1
NaN, if num == 0
+infinity, if num == +1

Otherwise, gcd(num, den) == 1 if num != 0, or den == 1 if num == 0.

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

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

<div dir=3D"ltr">I would like to see a rational class:<br><br><div class=3D=
"prettyprint" style=3D"background-color: rgb(250, 250, 250); border-color: =
rgb(187, 187, 187); border-style: solid; border-width: 1px; word-wrap: brea=
k-word;"><code class=3D"prettyprint"><div class=3D"subprettyprint"><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">namespace</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> std </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">{</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"><br>&nbsp; </span><span style=3D"color: =
#008;" class=3D"styled-by-prettify">template</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">typename</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"><br>&nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">class</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
rational </span><span style=3D"color: #660;" class=3D"styled-by-prettify">{=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp;=
 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">public</s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">:</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">using</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> numerator_type </s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">using</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"> denominator_type </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> make_unsigned</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify">T</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">&gt;::</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify">type</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br>&nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettif=
y">private</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
:</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp=
; &nbsp; numerator_type num</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">;</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"><br>&nbsp; &nbsp; denominator_type den</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" cl=
ass=3D"styled-by-prettify"><br>&nbsp; </span><span style=3D"color: #008;" c=
lass=3D"styled-by-prettify">public</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">:</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #800;" class=
=3D"styled-by-prettify">// ctors &amp; dtors</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; rational</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">(</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">numerator_type n </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #066=
;" class=3D"styled-by-prettify">0</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">,</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"> denominator_type d </span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> </span><span style=3D"color: #066;" class=3D"styled-by-p=
rettify">1</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
);</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbs=
p; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
template</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span>=
<span style=3D"color: #008;" class=3D"styled-by-prettify">typename</span><s=
pan style=3D"color: #000;" class=3D"styled-by-prettify"> U</span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"c=
olor: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; rational</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">const</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> rational</span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color:=
 #000;" class=3D"styled-by-prettify">U</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&amp;);</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify"><br>&nbsp; &nbsp; rational</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">(</span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">const</span><span style=3D"color: #000;" class=3D"styled=
-by-prettify"> rational</span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-pre=
ttify">T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&g=
t;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;)</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;=
" class=3D"styled-by-prettify">default</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">template</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> U</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&n=
bsp; &nbsp; rational</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">(</span><span style=3D"color: #000;" class=3D"styled-by-prettify"=
>rational</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&=
lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">U</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">&amp;&amp;);</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; rational</=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">(</span><spa=
n style=3D"color: #000;" class=3D"styled-by-prettify">rational</span><span =
style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&amp;&amp;)</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">=3D</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">=
default</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &=
nbsp; </span><span style=3D"color: #660;" class=3D"styled-by-prettify">~</s=
pan><span style=3D"color: #000;" class=3D"styled-by-prettify">rational</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">default</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br><br>&nbsp; &nbsp; </span><span style=3D"color: #800;" cl=
ass=3D"styled-by-prettify">// assignment</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">template</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cl=
ass=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">typename</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> U</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br>&nbsp; &nbsp; rational </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&amp;</span><span style=3D"color: #008;" class=3D"s=
tyled-by-prettify">operator</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">=3D(</span><span style=3D"color: #008;" class=3D"styled-by=
-prettify">const</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> rational</span><span style=3D"color: #660;" class=3D"styled-by-prett=
ify">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">U=
</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span=
><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">&amp;);</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; rational <=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">operator</span><=
span style=3D"color: #660;" class=3D"styled-by-prettify">=3D(</span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">const</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> rational</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">&amp;)</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">default</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span=
><span style=3D"color: #008;" class=3D"styled-by-prettify">template</span><=
span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span styl=
e=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">typename</span><span style=3D"col=
or: #000;" class=3D"styled-by-prettify"> U</span><span style=3D"color: #660=
;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>&nbsp; &nbsp; rational </span><span style=3D"=
color: #660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">operator</span><span style=3D"color: =
#660;" class=3D"styled-by-prettify">=3D(</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify">rational</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">U</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&amp;&amp;);</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br>&nbsp; &nbsp; rational </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">&amp;</span><span style=3D"color: #008;" class=3D"styled=
-by-prettify">operator</span><span style=3D"color: #660;" class=3D"styled-b=
y-prettify">=3D(</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify">rational</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">&lt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify">T<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">&amp;&amp;)</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #660;" class=3D"styled-by-prettify">=3D</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" clas=
s=3D"styled-by-prettify">default</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify"><br><br>&nbsp; &nbsp; </span><span style=3D"color: #800;" cl=
ass=3D"styled-by-prettify">// standard operators</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">template</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008=
;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> U</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>&nbsp; &nbsp; rational </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">operator</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">+=3D(</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> rational</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">U</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">rhs</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">template</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> U</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>&nbsp; &nbsp; rational </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">operator</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">-=3D(</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> rational</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">U</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">rhs</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">template</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> U</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>&nbsp; &nbsp; rational </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">operator</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">*=3D(</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> rational</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">U</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">rhs</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span s=
tyle=3D"color: #008;" class=3D"styled-by-prettify">template</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #0=
08;" class=3D"styled-by-prettify">typename</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"> U</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"><br>&nbsp; &nbsp; rational </span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">operator</span><span style=3D"color: #660;" c=
lass=3D"styled-by-prettify">/=3D(</span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">const</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> rational</span><span style=3D"color: #660;" class=3D"st=
yled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"styled-b=
y-prettify">U</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </=
span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;</span>=
<span style=3D"color: #000;" class=3D"styled-by-prettify">rhs</span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">);</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; rational </spa=
n><span style=3D"color: #008;" class=3D"styled-by-prettify">operator</span>=
<span style=3D"color: #660;" class=3D"styled-by-prettify">+()</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"c=
olor: #008;" class=3D"styled-by-prettify">const</span><span style=3D"color:=
 #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"><br>&nbsp; &nbsp; enable_if</span><span style=
=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify">is_signed</span><span style=3D"col=
or: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify">T</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">&gt;::</span><span style=3D"color: #000;" class=3D=
"styled-by-prettify">type</span><span style=3D"color: #660;" class=3D"style=
d-by-prettify">,</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> rational </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">operator</span><span style=3D"color: #660;" class=3D"styled-by-pretti=
fy">-()&gt;;</span><span style=3D"color: #000;" class=3D"styled-by-prettify=
"><br><br>&nbsp; &nbsp; </span><span style=3D"color: #800;" class=3D"styled=
-by-prettify">// member accessors</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>&nbsp; &nbsp; numerator_type numerator</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">const</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"styl=
ed-by-prettify">// Note: r-value</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"><br>&nbsp; &nbsp; denominator_type denominator</spa=
n><span style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span =
style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"=
color: #008;" class=3D"styled-by-prettify">const</span><span style=3D"color=
: #660;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #800;" class=3D"=
styled-by-prettify">// Nate: r-value</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br><br>&nbsp; &nbsp; </span><span style=3D"color=
: #800;" class=3D"styled-by-prettify">// conversion</span><span style=3D"co=
lor: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span sty=
le=3D"color: #008;" class=3D"styled-by-prettify">explicit</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color=
: #008;" class=3D"styled-by-prettify">operator</span><span style=3D"color: =
#000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">bool</span><span style=3D"color: #660;" class=3D=
"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styled-=
by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pretti=
fy">const</span><span style=3D"color: #660;" class=3D"styled-by-prettify">;=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #800;" class=3D"styled-by-prettify">// num !=3D 0 || de=
n =3D=3D 0</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
<br>&nbsp; &nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">explicit</span><span style=3D"color: #000;" class=3D"styled-by-pret=
tify"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">ope=
rator</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </sp=
an><span style=3D"color: #008;" class=3D"styled-by-prettify">float</span><s=
pan style=3D"color: #660;" class=3D"styled-by-prettify">()</span><span styl=
e=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"colo=
r: #008;" class=3D"styled-by-prettify">const</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">;</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"><br>&nbsp; &nbsp; </span><span style=3D"color: #00=
8;" class=3D"styled-by-prettify">explicit</span><span style=3D"color: #000;=
" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=
=3D"styled-by-prettify">operator</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D"style=
d-by-prettify">double</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">()</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #008;" class=3D"styled-by-prettify">const<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">;</span><sp=
an style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; &nbsp; </=
span><span style=3D"color: #008;" class=3D"styled-by-prettify">explicit</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span =
style=3D"color: #008;" class=3D"styled-by-prettify">operator</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"co=
lor: #008;" class=3D"styled-by-prettify">long</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" cla=
ss=3D"styled-by-prettify">double</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">const</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br><br=
>&nbsp; &nbsp; numerator_type floor</span><span style=3D"color: #660;" clas=
s=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">const</span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&n=
bsp; &nbsp; numerator_type ceiling</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">()</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> </span><span style=3D"color: #008;" class=3D"styled-by-pre=
ttify">const</span><span style=3D"color: #660;" class=3D"styled-by-prettify=
">;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nb=
sp; </span><span style=3D"color: #660;" class=3D"styled-by-prettify">};</sp=
an><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; </s=
pan><span style=3D"color: #008;" class=3D"styled-by-prettify">template</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span s=
tyle=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=
=3D"color: #008;" class=3D"styled-by-prettify">typename</span><span style=
=3D"color: #000;" class=3D"styled-by-prettify"> T</span><span style=3D"colo=
r: #660;" class=3D"styled-by-prettify">,</span><span style=3D"color: #000;"=
 class=3D"styled-by-prettify"> </span><span style=3D"color: #008;" class=3D=
"styled-by-prettify">typename</span><span style=3D"color: #000;" class=3D"s=
tyled-by-prettify"> U</span><span style=3D"color: #660;" class=3D"styled-by=
-prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify"><br>&nbsp; </span><span style=3D"color: #008;" class=3D"styled-by-pret=
tify">auto</span><span style=3D"color: #000;" class=3D"styled-by-prettify">=
 </span><span style=3D"color: #008;" class=3D"styled-by-prettify">operator<=
/span><span style=3D"color: #660;" class=3D"styled-by-prettify">+(</span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">const</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> rational</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">&amp;</span><span style=3D"color: #000;" class=3D"style=
d-by-prettify">lhs</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">const</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> rational</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">T</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&amp;</span><span style=3D"color: #000;" class=
=3D"styled-by-prettify">rhs</span><span style=3D"color: #660;" class=3D"sty=
led-by-prettify">);</span><span style=3D"color: #000;" class=3D"styled-by-p=
rettify"><br>&nbsp; </span><span style=3D"color: #800;" class=3D"styled-by-=
prettify">// sim. for operators -, * and /</span><span style=3D"color: #000=
;" class=3D"styled-by-prettify"><br><br>&nbsp; </span><span style=3D"color:=
 #008;" class=3D"styled-by-prettify">template</span><span style=3D"color: #=
000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" cla=
ss=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"=
styled-by-prettify">typename</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-=
prettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-pretti=
fy"><br>&nbsp; ostream </span><span style=3D"color: #660;" class=3D"styled-=
by-prettify">&amp;</span><span style=3D"color: #008;" class=3D"styled-by-pr=
ettify">operator</span><span style=3D"color: #660;" class=3D"styled-by-pret=
tify">&lt;&lt;(</span><span style=3D"color: #000;" class=3D"styled-by-prett=
ify">ostream </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&amp;,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">const</spa=
n><span style=3D"color: #000;" class=3D"styled-by-prettify"> rational</span=
><span style=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify">T</span><span style=3D=
"color: #660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color=
: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" =
class=3D"styled-by-prettify">&amp;);</span><span style=3D"color: #000;" cla=
ss=3D"styled-by-prettify"><br>&nbsp; </span><span style=3D"color: #008;" cl=
ass=3D"styled-by-prettify">template</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"styl=
ed-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"styled-by-=
prettify">typename</span><span style=3D"color: #000;" class=3D"styled-by-pr=
ettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-prettify">=
&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br>&n=
bsp; istream </span><span style=3D"color: #660;" class=3D"styled-by-prettif=
y">&amp;</span><span style=3D"color: #008;" class=3D"styled-by-prettify">op=
erator</span><span style=3D"color: #660;" class=3D"styled-by-prettify">&gt;=
&gt;(</span><span style=3D"color: #000;" class=3D"styled-by-prettify">istre=
am </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;,<=
/span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><sp=
an style=3D"color: #008;" class=3D"styled-by-prettify">const</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"> rational</span><span sty=
le=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D"=
color: #000;" class=3D"styled-by-prettify">T</span><span style=3D"color: #6=
60;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" c=
lass=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"s=
tyled-by-prettify">&amp;);</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"><br><br>&nbsp; </span><span style=3D"color: #800;" class=3D=
"styled-by-prettify">// Comparison operators</span><span style=3D"color: #0=
00;" class=3D"styled-by-prettify"><br>&nbsp; </span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">template</span><span style=3D"color: #00=
0;" class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;</span><span style=3D"color: #008;" class=3D"st=
yled-by-prettify">typename</span><span style=3D"color: #000;" class=3D"styl=
ed-by-prettify"> T</span><span style=3D"color: #660;" class=3D"styled-by-pr=
ettify">,</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> =
</span><span style=3D"color: #008;" class=3D"styled-by-prettify">typename</=
span><span style=3D"color: #000;" class=3D"styled-by-prettify"> U</span><sp=
an style=3D"color: #660;" class=3D"styled-by-prettify">&gt;</span><span sty=
le=3D"color: #000;" class=3D"styled-by-prettify"><br>&nbsp; </span><span st=
yle=3D"color: #008;" class=3D"styled-by-prettify">bool</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D"color: #=
008;" class=3D"styled-by-prettify">operator</span><span style=3D"color: #66=
0;" class=3D"styled-by-prettify">=3D=3D(</span><span style=3D"color: #008;"=
 class=3D"styled-by-prettify">const</span><span style=3D"color: #000;" clas=
s=3D"styled-by-prettify"> rational</span><span style=3D"color: #660;" class=
=3D"styled-by-prettify">&lt;</span><span style=3D"color: #000;" class=3D"st=
yled-by-prettify">T</span><span style=3D"color: #660;" class=3D"styled-by-p=
rettify">&gt;</span><span style=3D"color: #000;" class=3D"styled-by-prettif=
y"> </span><span style=3D"color: #660;" class=3D"styled-by-prettify">&amp;,=
</span><span style=3D"color: #000;" class=3D"styled-by-prettify"> </span><s=
pan style=3D"color: #008;" class=3D"styled-by-prettify">const</span><span s=
tyle=3D"color: #000;" class=3D"styled-by-prettify"> rational</span><span st=
yle=3D"color: #660;" class=3D"styled-by-prettify">&lt;</span><span style=3D=
"color: #000;" class=3D"styled-by-prettify">U</span><span style=3D"color: #=
660;" class=3D"styled-by-prettify">&gt;</span><span style=3D"color: #000;" =
class=3D"styled-by-prettify"> </span><span style=3D"color: #660;" class=3D"=
styled-by-prettify">&amp;);</span><span style=3D"color: #000;" class=3D"sty=
led-by-prettify"><br>&nbsp; </span><span style=3D"color: #800;" class=3D"st=
yled-by-prettify">// sim. for operators !=3D, &lt;, &gt;, &lt;=3D and &gt;=
=3D</span><span style=3D"color: #000;" class=3D"styled-by-prettify"><br></s=
pan><span style=3D"color: #660;" class=3D"styled-by-prettify">}</span><span=
 style=3D"color: #000;" class=3D"styled-by-prettify"> </span><span style=3D=
"color: #800;" class=3D"styled-by-prettify">// namespace std</span><span st=
yle=3D"color: #000;" class=3D"styled-by-prettify"><br></span><span style=3D=
"color: #000;" class=3D"styled-by-prettify"><br></span></div></code></div><=
br><br>Three values would be represented by den =3D=3D 0:<br>-infinity, if =
num =3D=3D -1<br>NaN, if num =3D=3D 0<br>+infinity, if num =3D=3D +1<br><br=
>Otherwise, gcd(num, den) =3D=3D 1 if num !=3D 0, or den =3D=3D 1 if num =
=3D=3D 0.<br><br></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_2141_979430068.1422738302797--
------=_Part_2140_1584828887.1422738302797--

.


Author: Scott Prager <splinterofchaos@gmail.com>
Date: Sat, 31 Jan 2015 18:19:47 -0800 (PST)
Raw View
------=_Part_2221_656624101.1422757187927
Content-Type: multipart/alternative;
 boundary="----=_Part_2222_2110287221.1422757187928"

------=_Part_2222_2110287221.1422757187928
Content-Type: text/plain; charset=UTF-8

On Saturday, January 31, 2015 at 4:05:02 PM UTC-5, Douglas Boffey wrote:
>
> I would like to see a rational class:
>

I was about to point out std::ratio, but then I realized it's compile time
only, which is odd because I don't think it pre-dated constexpr. Is there a
reason that template meta-programming was chosen over a constexpr/runtime
interface?


> namespace std {
>   template <typename T>
>   class rational {
>

Shouldn't the numerator and denominator be separately typed?


>
>   public:
>     using numerator_type = T;
>     using denominator_type = typename make_unsigned<T>::type;
>

Why should the denominator be unsigned, but the numerator be signed? Seems
uneven. Also, if one wanted to use this with a vector--or some custom
numeric--then "make_unsigned" might not be valid. One might claim I should
define "make_unsigned" for my type, but if its data isn't templated, that
wouldn't make any sense.


>
>   private:
>     numerator_type num;
>     denominator_type den;
>   public:
>     // ctors & dtors
>     rational(numerator_type n = 0, denominator_type d = 1);
>     template <typename U>
>     rational(const rational<U> &);
>     rational(const rational<T> &) = default;
>     template <typename U>
>     rational(rational<U> &&);
>     rational(rational<T> &&) = default;
>     ~rational() = default;
>
>     // assignment
>     template <typename U>
>     rational &operator=(const rational<U> &);
>     rational &operator=(const rational<T> &) = default;
>     template <typename U>
>     rational &operator=(rational<U> &&);
>     rational &operator=(rational<T> &&) = default;
>
>     // standard operators
>     template <typename U>
>     rational &operator+=(const rational<U> &rhs);
>     template <typename U>
>     rational &operator-=(const rational<U> &rhs);
>     template <typename U>
>     rational &operator*=(const rational<U> &rhs);
>     template <typename U>
>     rational &operator/=(const rational<U> &rhs);
>     rational operator+() const;
>     enable_if<is_signed<T>::type, rational operator-()>;
>

Again, "is_signed<T>" might not make sense for all T's, though the
condition I have in mind is a little obtuse:
*enable_if_t<is_same<decltype(-num), numerator_type>::value, rational>*


>
>
>     // member accessors
>     numerator_type numerator() const; // Note: r-value
>     denominator_type denominator() const; // Nate: r-value
>
>     // conversion
>     explicit operator bool() const; // num != 0 || den == 0
>     explicit operator float() const;
>     explicit operator double() const;
>     explicit operator long double() const;
>
>     numerator_type floor() const;
>     numerator_type ceiling() const;
>   };
>   template <typename T, typename U>
>   auto operator+(const rational<T> &lhs, const rational<T> &rhs);
>   // sim. for operators -, * and /
>
>   template <typename T>
>   ostream &operator<<(ostream &, const rational<T> &);
>   template <typename T>
>   istream &operator>>(istream &, const rational<T> &);
>

Inconsistent. Most C++ types don't define their own "operator>>". Correct
me if I'm wrong, but wouldn't it be ambiguous if the user tried to define
their own and ADL pulled in this definition?


>
>
>   // Comparison operators
>   template <typename T, typename U>
>   bool operator==(const rational<T> &, const rational<U> &);
>   // sim. for operators !=, <, >, <= and >=
> } // namespace std
>
>
>
> Three values would be represented by den == 0:
> -infinity, if num == -1
> NaN, if num == 0
> +infinity, if num == +1
>
> Otherwise, gcd(num, den) == 1 if num != 0, or den == 1 if num == 0.
>
>
Think any of the <cmath> functions should have an overload for this? At the
least, hypot comes to mind. You mentioned floor and ceil, but as member
functions. (They should be overloads.) Perhaps std::div as well.

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

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

<div dir=3D"ltr">On Saturday, January 31, 2015 at 4:05:02 PM UTC-5, Douglas=
 Boffey wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-l=
eft: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"=
>I would like to see a rational class:<br></div></blockquote><div><br></div=
><div>I was about to point out std::ratio, but then I realized it's compile=
 time only, which is odd because I don't think it pre-dated constexpr. Is t=
here a reason that template meta-programming was chosen over a constexpr/ru=
ntime interface?</div><div>&nbsp;</div><blockquote class=3D"gmail_quote" st=
yle=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-lef=
t: 1ex;"><div dir=3D"ltr"><div style=3D"background-color:rgb(250,250,250);b=
order-color:rgb(187,187,187);border-style:solid;border-width:1px;word-wrap:=
break-word"><code><div><span style=3D"color:#008">namespace</span><span sty=
le=3D"color:#000"> std </span><span style=3D"color:#660">{</span><span styl=
e=3D"color:#000"><br>&nbsp; </span><span style=3D"color:#008">template</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">&lt;</span>=
<span style=3D"color:#008">typename</span><span style=3D"color:#000"> T</sp=
an><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"><br>&nb=
sp; </span><span style=3D"color:#008">class</span><span style=3D"color:#000=
"> rational </span><span style=3D"color:#660">{</span></div></code></div></=
div></blockquote><div><span style=3D"font-size: 13px;"><br></span></div><di=
v><span style=3D"font-size: 13px;">Shouldn't the numerator and denominator =
be separately typed?</span></div><div><span style=3D"font-size: 13px;">&nbs=
p;</span><br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;mar=
gin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D=
"ltr"><div style=3D"background-color:rgb(250,250,250);border-color:rgb(187,=
187,187);border-style:solid;border-width:1px;word-wrap:break-word"><code><d=
iv><span style=3D"color:#000"><br>&nbsp; </span><span style=3D"color:#008">=
public</span><span style=3D"color:#660">:</span><span style=3D"color:#000">=
<br>&nbsp; &nbsp; </span><span style=3D"color:#008">using</span><span style=
=3D"color:#000"> numerator_type </span><span style=3D"color:#660">=3D</span=
><span style=3D"color:#000"> T</span><span style=3D"color:#660">;</span><sp=
an style=3D"color:#000"><br>&nbsp; &nbsp; </span><span style=3D"color:#008"=
>using</span><span style=3D"color:#000"> denominator_type </span><span styl=
e=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> make_unsigned</s=
pan><span style=3D"color:#660">&lt;</span><span style=3D"color:#000">T</spa=
n><span style=3D"color:#660">&gt;::</span><span style=3D"color:#000">type</=
span><span style=3D"color:#660">;</span></div></code></div></div></blockquo=
te><div><br></div><div>Why should the denominator be unsigned, but the nume=
rator be signed? Seems uneven. Also, if one wanted to use this with a vecto=
r--or some custom numeric--then "make_unsigned" might not be valid. One mig=
ht claim I should define "make_unsigned" for my type, but if its data isn't=
 templated, that wouldn't make any sense.</div><div>&nbsp;</div><blockquote=
 class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1=
px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div style=3D"background=
-color:rgb(250,250,250);border-color:rgb(187,187,187);border-style:solid;bo=
rder-width:1px;word-wrap:break-word"><code><div><span style=3D"color:#000">=
<br>&nbsp; </span><span style=3D"color:#008">private</span><span style=3D"c=
olor:#660">:</span><span style=3D"color:#000"><br>&nbsp; &nbsp; numerator_t=
ype num</span><span style=3D"color:#660">;</span><span style=3D"color:#000"=
><br>&nbsp; &nbsp; denominator_type den</span><span style=3D"color:#660">;<=
/span><span style=3D"color:#000"><br>&nbsp; </span><span style=3D"color:#00=
8">public</span><span style=3D"color:#660">:</span><span style=3D"color:#00=
0"><br>&nbsp; &nbsp; </span><span style=3D"color:#800">// ctors &amp; dtors=
</span><span style=3D"color:#000"><br>&nbsp; &nbsp; rational</span><span st=
yle=3D"color:#660">(</span><span style=3D"color:#000">numerator_type n </sp=
an><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span>=
<span style=3D"color:#066">0</span><span style=3D"color:#660">,</span><span=
 style=3D"color:#000"> denominator_type d </span><span style=3D"color:#660"=
>=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#066">1<=
/span><span style=3D"color:#660">);</span><span style=3D"color:#000"><br>&n=
bsp; &nbsp; </span><span style=3D"color:#008">template</span><span style=3D=
"color:#000"> </span><span style=3D"color:#660">&lt;</span><span style=3D"c=
olor:#008">typename</span><span style=3D"color:#000"> U</span><span style=
=3D"color:#660">&gt;</span><span style=3D"color:#000"><br>&nbsp; &nbsp; rat=
ional</span><span style=3D"color:#660">(</span><span style=3D"color:#008">c=
onst</span><span style=3D"color:#000"> rational</span><span style=3D"color:=
#660">&lt;</span><span style=3D"color:#000">U</span><span style=3D"color:#6=
60">&gt;</span><span style=3D"color:#000"> </span><span style=3D"color:#660=
">&amp;);</span><span style=3D"color:#000"><br>&nbsp; &nbsp; rational</span=
><span style=3D"color:#660">(</span><span style=3D"color:#008">const</span>=
<span style=3D"color:#000"> rational</span><span style=3D"color:#660">&lt;<=
/span><span style=3D"color:#000">T</span><span style=3D"color:#660">&gt;</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">&amp;)</s=
pan><span style=3D"color:#000"> </span><span style=3D"color:#660">=3D</span=
><span style=3D"color:#000"> </span><span style=3D"color:#008">default</spa=
n><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>&nbsp; =
&nbsp; </span><span style=3D"color:#008">template</span><span style=3D"colo=
r:#000"> </span><span style=3D"color:#660">&lt;</span><span style=3D"color:=
#008">typename</span><span style=3D"color:#000"> U</span><span style=3D"col=
or:#660">&gt;</span><span style=3D"color:#000"><br>&nbsp; &nbsp; rational</=
span><span style=3D"color:#660">(</span><span style=3D"color:#000">rational=
</span><span style=3D"color:#660">&lt;</span><span style=3D"color:#000">U</=
span><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#660">&amp;&amp;);</span><span style=3D"color:#000"=
><br>&nbsp; &nbsp; rational</span><span style=3D"color:#660">(</span><span =
style=3D"color:#000">rational</span><span style=3D"color:#660">&lt;</span><=
span style=3D"color:#000">T</span><span style=3D"color:#660">&gt;</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#660">&amp;&amp;)</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#660">=3D</span><=
span style=3D"color:#000"> </span><span style=3D"color:#008">default</span>=
<span style=3D"color:#660">;</span><span style=3D"color:#000"><br>&nbsp; &n=
bsp; </span><span style=3D"color:#660">~</span><span style=3D"color:#000">r=
ational</span><span style=3D"color:#660">()</span><span style=3D"color:#000=
"> </span><span style=3D"color:#660">=3D</span><span style=3D"color:#000"> =
</span><span style=3D"color:#008">default</span><span style=3D"color:#660">=
;</span><span style=3D"color:#000"><br><br>&nbsp; &nbsp; </span><span style=
=3D"color:#800">// assignment</span><span style=3D"color:#000"><br>&nbsp; &=
nbsp; </span><span style=3D"color:#008">template</span><span style=3D"color=
:#000"> </span><span style=3D"color:#660">&lt;</span><span style=3D"color:#=
008">typename</span><span style=3D"color:#000"> U</span><span style=3D"colo=
r:#660">&gt;</span><span style=3D"color:#000"><br>&nbsp; &nbsp; rational </=
span><span style=3D"color:#660">&amp;</span><span style=3D"color:#008">oper=
ator</span><span style=3D"color:#660">=3D(</span><span style=3D"color:#008"=
>const</span><span style=3D"color:#000"> rational</span><span style=3D"colo=
r:#660">&lt;</span><span style=3D"color:#000">U</span><span style=3D"color:=
#660">&gt;</span><span style=3D"color:#000"> </span><span style=3D"color:#6=
60">&amp;);</span><span style=3D"color:#000"><br>&nbsp; &nbsp; rational </s=
pan><span style=3D"color:#660">&amp;</span><span style=3D"color:#008">opera=
tor</span><span style=3D"color:#660">=3D(</span><span style=3D"color:#008">=
const</span><span style=3D"color:#000"> rational</span><span style=3D"color=
:#660">&lt;</span><span style=3D"color:#000">T</span><span style=3D"color:#=
660">&gt;</span><span style=3D"color:#000"> </span><span style=3D"color:#66=
0">&amp;)</span><span style=3D"color:#000"> </span><span style=3D"color:#66=
0">=3D</span><span style=3D"color:#000"> </span><span style=3D"color:#008">=
default</span><span style=3D"color:#660">;</span><span style=3D"color:#000"=
><br>&nbsp; &nbsp; </span><span style=3D"color:#008">template</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">&lt;</span><span sty=
le=3D"color:#008">typename</span><span style=3D"color:#000"> U</span><span =
style=3D"color:#660">&gt;</span><span style=3D"color:#000"><br>&nbsp; &nbsp=
; rational </span><span style=3D"color:#660">&amp;</span><span style=3D"col=
or:#008">operator</span><span style=3D"color:#660">=3D(</span><span style=
=3D"color:#000">rational</span><span style=3D"color:#660">&lt;</span><span =
style=3D"color:#000">U</span><span style=3D"color:#660">&gt;</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#660">&amp;&amp;);</span><s=
pan style=3D"color:#000"><br>&nbsp; &nbsp; rational </span><span style=3D"c=
olor:#660">&amp;</span><span style=3D"color:#008">operator</span><span styl=
e=3D"color:#660">=3D(</span><span style=3D"color:#000">rational</span><span=
 style=3D"color:#660">&lt;</span><span style=3D"color:#000">T</span><span s=
tyle=3D"color:#660">&gt;</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#660">&amp;&amp;)</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">=3D</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#008">default</span><span style=3D"color:#660">;</span><span =
style=3D"color:#000"><br><br>&nbsp; &nbsp; </span><span style=3D"color:#800=
">// standard operators</span><span style=3D"color:#000"><br>&nbsp; &nbsp; =
</span><span style=3D"color:#008">template</span><span style=3D"color:#000"=
> </span><span style=3D"color:#660">&lt;</span><span style=3D"color:#008">t=
ypename</span><span style=3D"color:#000"> U</span><span style=3D"color:#660=
">&gt;</span><span style=3D"color:#000"><br>&nbsp; &nbsp; rational </span><=
span style=3D"color:#660">&amp;</span><span style=3D"color:#008">operator</=
span><span style=3D"color:#660">+=3D(</span><span style=3D"color:#008">cons=
t</span><span style=3D"color:#000"> rational</span><span style=3D"color:#66=
0">&lt;</span><span style=3D"color:#000">U</span><span style=3D"color:#660"=
>&gt;</span><span style=3D"color:#000"> </span><span style=3D"color:#660">&=
amp;</span><span style=3D"color:#000">rhs</span><span style=3D"color:#660">=
);</span><span style=3D"color:#000"><br>&nbsp; &nbsp; </span><span style=3D=
"color:#008">template</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">&lt;</span><span style=3D"color:#008">typename</span><span =
style=3D"color:#000"> U</span><span style=3D"color:#660">&gt;</span><span s=
tyle=3D"color:#000"><br>&nbsp; &nbsp; rational </span><span style=3D"color:=
#660">&amp;</span><span style=3D"color:#008">operator</span><span style=3D"=
color:#660">-=3D(</span><span style=3D"color:#008">const</span><span style=
=3D"color:#000"> rational</span><span style=3D"color:#660">&lt;</span><span=
 style=3D"color:#000">U</span><span style=3D"color:#660">&gt;</span><span s=
tyle=3D"color:#000"> </span><span style=3D"color:#660">&amp;</span><span st=
yle=3D"color:#000">rhs</span><span style=3D"color:#660">);</span><span styl=
e=3D"color:#000"><br>&nbsp; &nbsp; </span><span style=3D"color:#008">templa=
te</span><span style=3D"color:#000"> </span><span style=3D"color:#660">&lt;=
</span><span style=3D"color:#008">typename</span><span style=3D"color:#000"=
> U</span><span style=3D"color:#660">&gt;</span><span style=3D"color:#000">=
<br>&nbsp; &nbsp; rational </span><span style=3D"color:#660">&amp;</span><s=
pan style=3D"color:#008">operator</span><span style=3D"color:#660">*=3D(</s=
pan><span style=3D"color:#008">const</span><span style=3D"color:#000"> rati=
onal</span><span style=3D"color:#660">&lt;</span><span style=3D"color:#000"=
>U</span><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"> =
</span><span style=3D"color:#660">&amp;</span><span style=3D"color:#000">rh=
s</span><span style=3D"color:#660">);</span><span style=3D"color:#000"><br>=
&nbsp; &nbsp; </span><span style=3D"color:#008">template</span><span style=
=3D"color:#000"> </span><span style=3D"color:#660">&lt;</span><span style=
=3D"color:#008">typename</span><span style=3D"color:#000"> U</span><span st=
yle=3D"color:#660">&gt;</span><span style=3D"color:#000"><br>&nbsp; &nbsp; =
rational </span><span style=3D"color:#660">&amp;</span><span style=3D"color=
:#008">operator</span><span style=3D"color:#660">/=3D(</span><span style=3D=
"color:#008">const</span><span style=3D"color:#000"> rational</span><span s=
tyle=3D"color:#660">&lt;</span><span style=3D"color:#000">U</span><span sty=
le=3D"color:#660">&gt;</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">&amp;</span><span style=3D"color:#000">rhs</span><span styl=
e=3D"color:#660">);</span><span style=3D"color:#000"><br>&nbsp; &nbsp; rati=
onal </span><span style=3D"color:#008">operator</span><span style=3D"color:=
#660">+()</span><span style=3D"color:#000"> </span><span style=3D"color:#00=
8">const</span><span style=3D"color:#660">;</span><span style=3D"color:#000=
"><br>&nbsp; &nbsp; enable_if</span><span style=3D"color:#660">&lt;</span><=
span style=3D"color:#000">is_signed</span><span style=3D"color:#660">&lt;</=
span><span style=3D"color:#000">T</span><span style=3D"color:#660">&gt;::</=
span><span style=3D"color:#000">type</span><span style=3D"color:#660">,</sp=
an><span style=3D"color:#000"> rational </span><span style=3D"color:#008">o=
perator</span><span style=3D"color:#660">-()&gt;;</span></div></code></div>=
</div></blockquote><div><br></div><div>Again, "is_signed&lt;T&gt;" might no=
t make sense for all T's, though the condition I have in mind is a little o=
btuse:</div><div><i>enable_if_t&lt;is_same&lt;decltype(-num), numerator_typ=
e&gt;::value, rational&gt;</i></div><div>&nbsp;</div><blockquote class=3D"g=
mail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px #ccc sol=
id;padding-left: 1ex;"><div dir=3D"ltr"><div style=3D"background-color:rgb(=
250,250,250);border-color:rgb(187,187,187);border-style:solid;border-width:=
1px;word-wrap:break-word"><code><div><span style=3D"color:#000"><br><br>&nb=
sp; &nbsp; </span><span style=3D"color:#800">// member accessors</span><spa=
n style=3D"color:#000"><br>&nbsp; &nbsp; numerator_type numerator</span><sp=
an style=3D"color:#660">()</span><span style=3D"color:#000"> </span><span s=
tyle=3D"color:#008">const</span><span style=3D"color:#660">;</span><span st=
yle=3D"color:#000"> </span><span style=3D"color:#800">// Note: r-value</spa=
n><span style=3D"color:#000"><br>&nbsp; &nbsp; denominator_type denominator=
</span><span style=3D"color:#660">()</span><span style=3D"color:#000"> </sp=
an><span style=3D"color:#008">const</span><span style=3D"color:#660">;</spa=
n><span style=3D"color:#000"> </span><span style=3D"color:#800">// Nate: r-=
value</span><span style=3D"color:#000"><br><br>&nbsp; &nbsp; </span><span s=
tyle=3D"color:#800">// conversion</span><span style=3D"color:#000"><br>&nbs=
p; &nbsp; </span><span style=3D"color:#008">explicit</span><span style=3D"c=
olor:#000"> </span><span style=3D"color:#008">operator</span><span style=3D=
"color:#000"> </span><span style=3D"color:#008">bool</span><span style=3D"c=
olor:#660">()</span><span style=3D"color:#000"> </span><span style=3D"color=
:#008">const</span><span style=3D"color:#660">;</span><span style=3D"color:=
#000"> </span><span style=3D"color:#800">// num !=3D 0 || den =3D=3D 0</spa=
n><span style=3D"color:#000"><br>&nbsp; &nbsp; </span><span style=3D"color:=
#008">explicit</span><span style=3D"color:#000"> </span><span style=3D"colo=
r:#008">operator</span><span style=3D"color:#000"> </span><span style=3D"co=
lor:#008">float</span><span style=3D"color:#660">()</span><span style=3D"co=
lor:#000"> </span><span style=3D"color:#008">const</span><span style=3D"col=
or:#660">;</span><span style=3D"color:#000"><br>&nbsp; &nbsp; </span><span =
style=3D"color:#008">explicit</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#008">operator</span><span style=3D"color:#000"> </span><s=
pan style=3D"color:#008">double</span><span style=3D"color:#660">()</span><=
span style=3D"color:#000"> </span><span style=3D"color:#008">const</span><s=
pan style=3D"color:#660">;</span><span style=3D"color:#000"><br>&nbsp; &nbs=
p; </span><span style=3D"color:#008">explicit</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#008">operator</span><span style=3D"color:=
#000"> </span><span style=3D"color:#008">long</span><span style=3D"color:#0=
00"> </span><span style=3D"color:#008">double</span><span style=3D"color:#6=
60">()</span><span style=3D"color:#000"> </span><span style=3D"color:#008">=
const</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><=
br><br>&nbsp; &nbsp; numerator_type floor</span><span style=3D"color:#660">=
()</span><span style=3D"color:#000"> </span><span style=3D"color:#008">cons=
t</span><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>&=
nbsp; &nbsp; numerator_type ceiling</span><span style=3D"color:#660">()</sp=
an><span style=3D"color:#000"> </span><span style=3D"color:#008">const</spa=
n><span style=3D"color:#660">;</span><span style=3D"color:#000"><br>&nbsp; =
</span><span style=3D"color:#660">};</span><span style=3D"color:#000"><br>&=
nbsp; </span><span style=3D"color:#008">template</span><span style=3D"color=
:#000"> </span><span style=3D"color:#660">&lt;</span><span style=3D"color:#=
008">typename</span><span style=3D"color:#000"> T</span><span style=3D"colo=
r:#660">,</span><span style=3D"color:#000"> </span><span style=3D"color:#00=
8">typename</span><span style=3D"color:#000"> U</span><span style=3D"color:=
#660">&gt;</span><span style=3D"color:#000"><br>&nbsp; </span><span style=
=3D"color:#008">auto</span><span style=3D"color:#000"> </span><span style=
=3D"color:#008">operator</span><span style=3D"color:#660">+(</span><span st=
yle=3D"color:#008">const</span><span style=3D"color:#000"> rational</span><=
span style=3D"color:#660">&lt;</span><span style=3D"color:#000">T</span><sp=
an style=3D"color:#660">&gt;</span><span style=3D"color:#000"> </span><span=
 style=3D"color:#660">&amp;</span><span style=3D"color:#000">lhs</span><spa=
n style=3D"color:#660">,</span><span style=3D"color:#000"> </span><span sty=
le=3D"color:#008">const</span><span style=3D"color:#000"> rational</span><s=
pan style=3D"color:#660">&lt;</span><span style=3D"color:#000">T</span><spa=
n style=3D"color:#660">&gt;</span><span style=3D"color:#000"> </span><span =
style=3D"color:#660">&amp;</span><span style=3D"color:#000">rhs</span><span=
 style=3D"color:#660">);</span><span style=3D"color:#000"><br>&nbsp; </span=
><span style=3D"color:#800">// sim. for operators -, * and /</span><span st=
yle=3D"color:#000"><br><br>&nbsp; </span><span style=3D"color:#008">templat=
e</span><span style=3D"color:#000"> </span><span style=3D"color:#660">&lt;<=
/span><span style=3D"color:#008">typename</span><span style=3D"color:#000">=
 T</span><span style=3D"color:#660">&gt;</span><span style=3D"color:#000"><=
br>&nbsp; ostream </span><span style=3D"color:#660">&amp;</span><span style=
=3D"color:#008">operator</span><span style=3D"color:#660">&lt;&lt;(</span><=
span style=3D"color:#000">ostream </span><span style=3D"color:#660">&amp;,<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#008">const</=
span><span style=3D"color:#000"> rational</span><span style=3D"color:#660">=
&lt;</span><span style=3D"color:#000">T</span><span style=3D"color:#660">&g=
t;</span><span style=3D"color:#000"> </span><span style=3D"color:#660">&amp=
;);</span><span style=3D"color:#000"><br>&nbsp; </span><span style=3D"color=
:#008">template</span><span style=3D"color:#000"> </span><span style=3D"col=
or:#660">&lt;</span><span style=3D"color:#008">typename</span><span style=
=3D"color:#000"> T</span><span style=3D"color:#660">&gt;</span><span style=
=3D"color:#000"><br>&nbsp; istream </span><span style=3D"color:#660">&amp;<=
/span><span style=3D"color:#008">operator</span><span style=3D"color:#660">=
&gt;&gt;(</span><span style=3D"color:#000">istream </span><span style=3D"co=
lor:#660">&amp;,</span><span style=3D"color:#000"> </span><span style=3D"co=
lor:#008">const</span><span style=3D"color:#000"> rational</span><span styl=
e=3D"color:#660">&lt;</span><span style=3D"color:#000">T</span><span style=
=3D"color:#660">&gt;</span><span style=3D"color:#000"> </span><span style=
=3D"color:#660">&amp;);</span></div></code></div></div></blockquote><div><b=
r></div><div>Inconsistent. Most C++ types don't define their own "operator&=
gt;&gt;". Correct me if I'm wrong, but wouldn't it be ambiguous if the user=
 tried to define their own and ADL pulled in this definition?</div><div>&nb=
sp;</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: =
0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div=
 style=3D"background-color:rgb(250,250,250);border-color:rgb(187,187,187);b=
order-style:solid;border-width:1px;word-wrap:break-word"><code><div><span s=
tyle=3D"color:#000"><br><br>&nbsp; </span><span style=3D"color:#800">// Com=
parison operators</span><span style=3D"color:#000"><br>&nbsp; </span><span =
style=3D"color:#008">template</span><span style=3D"color:#000"> </span><spa=
n style=3D"color:#660">&lt;</span><span style=3D"color:#008">typename</span=
><span style=3D"color:#000"> T</span><span style=3D"color:#660">,</span><sp=
an style=3D"color:#000"> </span><span style=3D"color:#008">typename</span><=
span style=3D"color:#000"> U</span><span style=3D"color:#660">&gt;</span><s=
pan style=3D"color:#000"><br>&nbsp; </span><span style=3D"color:#008">bool<=
/span><span style=3D"color:#000"> </span><span style=3D"color:#008">operato=
r</span><span style=3D"color:#660">=3D=3D(</span><span style=3D"color:#008"=
>const</span><span style=3D"color:#000"> rational</span><span style=3D"colo=
r:#660">&lt;</span><span style=3D"color:#000">T</span><span style=3D"color:=
#660">&gt;</span><span style=3D"color:#000"> </span><span style=3D"color:#6=
60">&amp;,</span><span style=3D"color:#000"> </span><span style=3D"color:#0=
08">const</span><span style=3D"color:#000"> rational</span><span style=3D"c=
olor:#660">&lt;</span><span style=3D"color:#000">U</span><span style=3D"col=
or:#660">&gt;</span><span style=3D"color:#000"> </span><span style=3D"color=
:#660">&amp;);</span><span style=3D"color:#000"><br>&nbsp; </span><span sty=
le=3D"color:#800">// sim. for operators !=3D, &lt;, &gt;, &lt;=3D and &gt;=
=3D</span><span style=3D"color:#000"><br></span><span style=3D"color:#660">=
}</span><span style=3D"color:#000"> </span><span style=3D"color:#800">// na=
mespace std</span><span style=3D"color:#000"><br></span><span style=3D"colo=
r:#000"><br></span></div></code></div><br><br>Three values would be represe=
nted by den =3D=3D 0:<br>-infinity, if num =3D=3D -1<br>NaN, if num =3D=3D =
0<br>+infinity, if num =3D=3D +1<br><br>Otherwise, gcd(num, den) =3D=3D 1 i=
f num !=3D 0, or den =3D=3D 1 if num =3D=3D 0.<br><br></div></blockquote><d=
iv><br></div><div>Think any of the &lt;cmath&gt; functions should have an o=
verload for this? At the least, hypot comes to mind. You mentioned floor an=
d ceil, but as member functions. (They should be overloads.) Perhaps std::d=
iv as well.</div></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_2222_2110287221.1422757187928--
------=_Part_2221_656624101.1422757187927--

.


Author: Howard Hinnant <howard.hinnant@gmail.com>
Date: Sat, 31 Jan 2015 21:44:20 -0500
Raw View
On Jan 31, 2015, at 9:19 PM, Scott Prager <splinterofchaos@gmail.com> wrote=
:

> I was about to point out std::ratio, but then I realized it's compile tim=
e only, which is odd because I don't think it pre-dated constexpr. Is there=
 a reason that template meta-programming was chosen over a constexpr/runtim=
e interface?

http://stackoverflow.com/a/12326164/576911

I=E2=80=99m allergic to proposals without an implementation.

Howard

--=20

---=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

.


Author: Douglas Boffey <douglas.boffey@gmail.com>
Date: Mon, 2 Feb 2015 04:52:53 -0800 (PST)
Raw View
------=_Part_3463_506603990.1422881573329
Content-Type: multipart/alternative;
 boundary="----=_Part_3464_1868083222.1422881573330"

------=_Part_3464_1868083222.1422881573330
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable


On Sunday, 1 February 2015 02:19:48 UTC, Scott Prager wrote:=20
>
> On Saturday, January 31, 2015 at 4:05:02 PM UTC-5, Douglas Boffey wrote:=
=20
>>
>> I would like to see a rational class:
>>
>
> I was about to point out std::ratio, but then I realized it's compile tim=
e=20
> only, which is odd because I don't think it pre-dated constexpr. Is there=
 a=20
> reason that template meta-programming was chosen over a constexpr/runtime=
=20
> interface?
>
=20
Eh?  I don=E2=80=99t see anywhere in my posting where I=E2=80=99ve used TMP=
..  Certainly, I=20
have omitted any constexprs in my draft, just like I=E2=80=99ve not specifi=
ed any=20
exception specifications.

>  =20
>
>>  namespace std {
>>   template <typename T>
>>   class rational {
>>
>
> Shouldn't the numerator and denominator be separately typed?
>
=20
Possibly (mayby defaulted to typename make_unsigned<T>::type?)  I would=20
certainly object to a library where the numerator and denominator were=20
forced to be the same type (why would you want negative denominators?)

>  =20
>
>> =20
>>   public:
>>     using numerator_type =3D T;
>>     using denominator_type =3D typename make_unsigned<T>::type;
>>
>
> Why should the denominator be unsigned, but the numerator be signed? Seem=
s=20
> uneven. Also, if one wanted to use this with a vector--or some custom=20
> numeric--then "make_unsigned" might not be valid. One might claim I shoul=
d=20
> define "make_unsigned" for my type, but if its data isn't templated, that=
=20
> wouldn't make any sense.
>
=20
True, but see my response to your first point.

>  =20
>
>> =20
>>   private:
>>     numerator_type num;
>>     denominator_type den;
>>   public:
>>     // ctors & dtors
>>     rational(numerator_type n =3D 0, denominator_type d =3D 1);
>>     template <typename U>
>>     rational(const rational<U> &);
>>     rational(const rational<T> &) =3D default;
>>     template <typename U>
>>     rational(rational<U> &&);
>>     rational(rational<T> &&) =3D default;
>>     ~rational() =3D default;
>>
>>     // assignment
>>     template <typename U>
>>     rational &operator=3D(const rational<U> &);
>>     rational &operator=3D(const rational<T> &) =3D default;
>>     template <typename U>
>>     rational &operator=3D(rational<U> &&);
>>     rational &operator=3D(rational<T> &&) =3D default;
>>
>>     // standard operators
>>     template <typename U>
>>     rational &operator+=3D(const rational<U> &rhs);
>>     template <typename U>
>>     rational &operator-=3D(const rational<U> &rhs);
>>     template <typename U>
>>     rational &operator*=3D(const rational<U> &rhs);
>>     template <typename U>
>>     rational &operator/=3D(const rational<U> &rhs);
>>     rational operator+() const;
>>     enable_if<is_signed<T>::type, rational operator-()>;
>>
>
> Again, "is_signed<T>" might not make sense for all T's, though the=20
> condition I have in mind is a little obtuse:
> *enable_if_t<is_same<decltype(-num), numerator_type>::value, rational>*
>
=20
Should I have something like:
=20
=20
 auto operator-()->rational<decltype(-num), denominator_type>

=20

>  =20
>
>> =20
>>
>>     // member accessors
>>     numerator_type numerator() const; // Note: r-value
>>     denominator_type denominator() const; // Nate: r-value
>>
>>     // conversion
>>     explicit operator bool() const; // num !=3D 0 || den =3D=3D 0
>>     explicit operator float() const;
>>     explicit operator double() const;
>>     explicit operator long double() const;
>>
>>     numerator_type floor() const;
>>     numerator_type ceiling() const;
>>   };
>>   template <typename T, typename U>
>>   auto operator+(const rational<T> &lhs, const rational<T> &rhs);
>>   // sim. for operators -, * and /
>>
>>   template <typename T>
>>   ostream &operator<<(ostream &, const rational<T> &);
>>   template <typename T>
>>   istream &operator>>(istream &, const rational<T> &);
>>
>
> Inconsistent. Most C++ types don't define their own "operator>>". Correct=
=20
> me if I'm wrong, but wouldn't it be ambiguous if the user tried to define=
=20
> their own and ADL pulled in this definition?
>
=20
Accepted.

>  =20
>
>> =20
>>
>>   // Comparison operators
>>   template <typename T, typename U>
>>   bool operator=3D=3D(const rational<T> &, const rational<U> &);
>>   // sim. for operators !=3D, <, >, <=3D and >=3D
>> } // namespace std
>>
>>
>>
>> Three values would be represented by den =3D=3D 0:
>> -infinity, if num =3D=3D -1
>> NaN, if num =3D=3D 0
>> +infinity, if num =3D=3D +1
>>
>> Otherwise, gcd(num, den) =3D=3D 1 if num !=3D 0, or den =3D=3D 1 if num =
=3D=3D 0.
>>
>>
> Think any of the <cmath> functions should have an overload for this? At=
=20
> the least, hypot comes to mind. You mentioned floor and ceil, but as memb=
er=20
> functions. (They should be overloads.) Perhaps std::div as well.
>
=20
What would std::div do?
=20
Other functions that could be added are:
=20
=20
T round() const; // round to even  =20
  =20
bool is_finite() const {return den !=3D 0; }  =20
bool is_nan() const {return den =3D=3D 0 && num =3D=3D 0; }

=20
=20
given that I have specified representations for NaN and =C2=B1=E2=88=9E.
=20
I have specifically not followed boost::rational in including=20
pre/post-inc/decrement operators, as they seem somewhat incongruous.
=20
Doug.

--=20

---=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

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

<div dir=3D"ltr"><BR>On Sunday, 1 February 2015 02:19:48 UTC, Scott Prager =
wrote:=20
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>On Saturday, January 31, 2015 at 4:05:02 PM UTC-5, Douglas B=
offey wrote:=20
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>I would like to see a rational class:<BR></DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>I was about to point out std::ratio, but then I realized it's compile =
time only, which is odd because I don't think it pre-dated constexpr. Is th=
ere a reason that template meta-programming was chosen over a constexpr/run=
time interface?</DIV></DIV></BLOCKQUOTE>
<DIV>&nbsp;</DIV>
<DIV>Eh?&nbsp; I don=E2=80=99t see anywhere in my posting where I=E2=80=99v=
e used&nbsp;TMP.&nbsp; Certainly, I have omitted any constexprs in my draft=
, just like I=E2=80=99ve not specified any exception specifications.</DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV style=3D"BORDER-BOTTOM: rgb(187,187,187) 1px solid; BORDER-LEFT: rgb(1=
87,187,187) 1px solid; BACKGROUND-COLOR: rgb(250,250,250); WORD-WRAP: break=
-word; BORDER-TOP: rgb(187,187,187) 1px solid; BORDER-RIGHT: rgb(187,187,18=
7) 1px solid"><CODE>
<DIV><SPAN style=3D"COLOR: #008">namespace</SPAN><SPAN style=3D"COLOR: #000=
"> std </SPAN><SPAN style=3D"COLOR: #660">{</SPAN><SPAN style=3D"COLOR: #00=
0"><BR>&nbsp; </SPAN><SPAN style=3D"COLOR: #008">template</SPAN><SPAN style=
=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><SPAN style=
=3D"COLOR: #008">typename</SPAN><SPAN style=3D"COLOR: #000"> T</SPAN><SPAN =
style=3D"COLOR: #660">&gt;</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; </S=
PAN><SPAN style=3D"COLOR: #008">class</SPAN><SPAN style=3D"COLOR: #000"> ra=
tional </SPAN><SPAN style=3D"COLOR: #660">{</SPAN></DIV></CODE></DIV></DIV>=
</BLOCKQUOTE>
<DIV><SPAN style=3D"FONT-SIZE: 13px"><BR></SPAN></DIV>
<DIV><SPAN style=3D"FONT-SIZE: 13px">Shouldn't the numerator and denominato=
r be separately typed?</SPAN></DIV></DIV></BLOCKQUOTE>
<DIV>&nbsp;</DIV>
<DIV>Possibly (mayby defaulted to <CODE class=3Dprettyprint><SPAN style=3D"=
COLOR: #008" class=3Dstyled-by-prettify>typename</SPAN><SPAN style=3D"COLOR=
: #000" class=3Dstyled-by-prettify> make_unsigned</SPAN><SPAN style=3D"COLO=
R: #660" class=3Dstyled-by-prettify>&lt;</SPAN><SPAN style=3D"COLOR: #000" =
class=3Dstyled-by-prettify>T</SPAN><SPAN style=3D"COLOR: #660" class=3Dstyl=
ed-by-prettify>&gt;::</SPAN><SPAN style=3D"COLOR: #000" class=3Dstyled-by-p=
rettify>type?</SPAN></CODE>)&nbsp; I would certainly object to a library wh=
ere the numerator and denominator were forced to be the same type (why woul=
d you want negative denominators?)</DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV><SPAN style=3D"FONT-SIZE: 13px">&nbsp;</SPAN><BR></DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV style=3D"BORDER-BOTTOM: rgb(187,187,187) 1px solid; BORDER-LEFT: rgb(1=
87,187,187) 1px solid; BACKGROUND-COLOR: rgb(250,250,250); WORD-WRAP: break=
-word; BORDER-TOP: rgb(187,187,187) 1px solid; BORDER-RIGHT: rgb(187,187,18=
7) 1px solid"><CODE>
<DIV><SPAN style=3D"COLOR: #000"><BR>&nbsp; </SPAN><SPAN style=3D"COLOR: #0=
08">public</SPAN><SPAN style=3D"COLOR: #660">:</SPAN><SPAN style=3D"COLOR: =
#000"><BR>&nbsp; &nbsp; </SPAN><SPAN style=3D"COLOR: #008">using</SPAN><SPA=
N style=3D"COLOR: #000"> numerator_type </SPAN><SPAN style=3D"COLOR: #660">=
=3D</SPAN><SPAN style=3D"COLOR: #000"> T</SPAN><SPAN style=3D"COLOR: #660">=
;</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; </SPAN><SPAN style=3D=
"COLOR: #008">using</SPAN><SPAN style=3D"COLOR: #000"> denominator_type </S=
PAN><SPAN style=3D"COLOR: #660">=3D</SPAN><SPAN style=3D"COLOR: #000"> </SP=
AN><SPAN style=3D"COLOR: #008">typename</SPAN><SPAN style=3D"COLOR: #000"> =
make_unsigned</SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><SPAN style=3D"C=
OLOR: #000">T</SPAN><SPAN style=3D"COLOR: #660">&gt;::</SPAN><SPAN style=3D=
"COLOR: #000">type</SPAN><SPAN style=3D"COLOR: #660">;</SPAN></DIV></CODE><=
/DIV></DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>Why should the denominator be unsigned, but the numerator be signed? S=
eems uneven. Also, if one wanted to use this with a vector--or some custom =
numeric--then "make_unsigned" might not be valid. One might claim I should =
define "make_unsigned" for my type, but if its data isn't templated, that w=
ouldn't make any sense.</DIV></DIV></BLOCKQUOTE>
<DIV>&nbsp;</DIV>
<DIV>True, but see my response to your first point.</DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV style=3D"BORDER-BOTTOM: rgb(187,187,187) 1px solid; BORDER-LEFT: rgb(1=
87,187,187) 1px solid; BACKGROUND-COLOR: rgb(250,250,250); WORD-WRAP: break=
-word; BORDER-TOP: rgb(187,187,187) 1px solid; BORDER-RIGHT: rgb(187,187,18=
7) 1px solid"><CODE>
<DIV><SPAN style=3D"COLOR: #000"><BR>&nbsp; </SPAN><SPAN style=3D"COLOR: #0=
08">private</SPAN><SPAN style=3D"COLOR: #660">:</SPAN><SPAN style=3D"COLOR:=
 #000"><BR>&nbsp; &nbsp; numerator_type num</SPAN><SPAN style=3D"COLOR: #66=
0">;</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; denominator_type d=
en</SPAN><SPAN style=3D"COLOR: #660">;</SPAN><SPAN style=3D"COLOR: #000"><B=
R>&nbsp; </SPAN><SPAN style=3D"COLOR: #008">public</SPAN><SPAN style=3D"COL=
OR: #660">:</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; </SPAN><SPA=
N style=3D"COLOR: #800">// ctors &amp; dtors</SPAN><SPAN style=3D"COLOR: #0=
00"><BR>&nbsp; &nbsp; rational</SPAN><SPAN style=3D"COLOR: #660">(</SPAN><S=
PAN style=3D"COLOR: #000">numerator_type n </SPAN><SPAN style=3D"COLOR: #66=
0">=3D</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #066=
">0</SPAN><SPAN style=3D"COLOR: #660">,</SPAN><SPAN style=3D"COLOR: #000"> =
denominator_type d </SPAN><SPAN style=3D"COLOR: #660">=3D</SPAN><SPAN style=
=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #066">1</SPAN><SPAN style=3D=
"COLOR: #660">);</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; </SPAN=
><SPAN style=3D"COLOR: #008">template</SPAN><SPAN style=3D"COLOR: #000"> </=
SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><SPAN style=3D"COLOR: #008">typ=
ename</SPAN><SPAN style=3D"COLOR: #000"> U</SPAN><SPAN style=3D"COLOR: #660=
">&gt;</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; rational</SPAN><=
SPAN style=3D"COLOR: #660">(</SPAN><SPAN style=3D"COLOR: #008">const</SPAN>=
<SPAN style=3D"COLOR: #000"> rational</SPAN><SPAN style=3D"COLOR: #660">&lt=
;</SPAN><SPAN style=3D"COLOR: #000">U</SPAN><SPAN style=3D"COLOR: #660">&gt=
;</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">&am=
p;);</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; rational</SPAN><SP=
AN style=3D"COLOR: #660">(</SPAN><SPAN style=3D"COLOR: #008">const</SPAN><S=
PAN style=3D"COLOR: #000"> rational</SPAN><SPAN style=3D"COLOR: #660">&lt;<=
/SPAN><SPAN style=3D"COLOR: #000">T</SPAN><SPAN style=3D"COLOR: #660">&gt;<=
/SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">&amp;=
)</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">=3D=
</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #008">defa=
ult</SPAN><SPAN style=3D"COLOR: #660">;</SPAN><SPAN style=3D"COLOR: #000"><=
BR>&nbsp; &nbsp; </SPAN><SPAN style=3D"COLOR: #008">template</SPAN><SPAN st=
yle=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><SPAN st=
yle=3D"COLOR: #008">typename</SPAN><SPAN style=3D"COLOR: #000"> U</SPAN><SP=
AN style=3D"COLOR: #660">&gt;</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; =
&nbsp; rational</SPAN><SPAN style=3D"COLOR: #660">(</SPAN><SPAN style=3D"CO=
LOR: #000">rational</SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><SPAN styl=
e=3D"COLOR: #000">U</SPAN><SPAN style=3D"COLOR: #660">&gt;</SPAN><SPAN styl=
e=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">&amp;&amp;);</SPAN><S=
PAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; rational</SPAN><SPAN style=3D"C=
OLOR: #660">(</SPAN><SPAN style=3D"COLOR: #000">rational</SPAN><SPAN style=
=3D"COLOR: #660">&lt;</SPAN><SPAN style=3D"COLOR: #000">T</SPAN><SPAN style=
=3D"COLOR: #660">&gt;</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=
=3D"COLOR: #660">&amp;&amp;)</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPA=
N style=3D"COLOR: #660">=3D</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN=
 style=3D"COLOR: #008">default</SPAN><SPAN style=3D"COLOR: #660">;</SPAN><S=
PAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; </SPAN><SPAN style=3D"COLOR: #6=
60">~</SPAN><SPAN style=3D"COLOR: #000">rational</SPAN><SPAN style=3D"COLOR=
: #660">()</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: =
#660">=3D</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #=
008">default</SPAN><SPAN style=3D"COLOR: #660">;</SPAN><SPAN style=3D"COLOR=
: #000"><BR><BR>&nbsp; &nbsp; </SPAN><SPAN style=3D"COLOR: #800">// assignm=
ent</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; </SPAN><SPAN style=
=3D"COLOR: #008">template</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN s=
tyle=3D"COLOR: #660">&lt;</SPAN><SPAN style=3D"COLOR: #008">typename</SPAN>=
<SPAN style=3D"COLOR: #000"> U</SPAN><SPAN style=3D"COLOR: #660">&gt;</SPAN=
><SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; rational </SPAN><SPAN style=
=3D"COLOR: #660">&amp;</SPAN><SPAN style=3D"COLOR: #008">operator</SPAN><SP=
AN style=3D"COLOR: #660">=3D(</SPAN><SPAN style=3D"COLOR: #008">const</SPAN=
><SPAN style=3D"COLOR: #000"> rational</SPAN><SPAN style=3D"COLOR: #660">&l=
t;</SPAN><SPAN style=3D"COLOR: #000">U</SPAN><SPAN style=3D"COLOR: #660">&g=
t;</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">&a=
mp;);</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; rational </SPAN><=
SPAN style=3D"COLOR: #660">&amp;</SPAN><SPAN style=3D"COLOR: #008">operator=
</SPAN><SPAN style=3D"COLOR: #660">=3D(</SPAN><SPAN style=3D"COLOR: #008">c=
onst</SPAN><SPAN style=3D"COLOR: #000"> rational</SPAN><SPAN style=3D"COLOR=
: #660">&lt;</SPAN><SPAN style=3D"COLOR: #000">T</SPAN><SPAN style=3D"COLOR=
: #660">&gt;</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR=
: #660">&amp;)</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COL=
OR: #660">=3D</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLO=
R: #008">default</SPAN><SPAN style=3D"COLOR: #660">;</SPAN><SPAN style=3D"C=
OLOR: #000"><BR>&nbsp; &nbsp; </SPAN><SPAN style=3D"COLOR: #008">template</=
SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">&lt;</=
SPAN><SPAN style=3D"COLOR: #008">typename</SPAN><SPAN style=3D"COLOR: #000"=
> U</SPAN><SPAN style=3D"COLOR: #660">&gt;</SPAN><SPAN style=3D"COLOR: #000=
"><BR>&nbsp; &nbsp; rational </SPAN><SPAN style=3D"COLOR: #660">&amp;</SPAN=
><SPAN style=3D"COLOR: #008">operator</SPAN><SPAN style=3D"COLOR: #660">=3D=
(</SPAN><SPAN style=3D"COLOR: #000">rational</SPAN><SPAN style=3D"COLOR: #6=
60">&lt;</SPAN><SPAN style=3D"COLOR: #000">U</SPAN><SPAN style=3D"COLOR: #6=
60">&gt;</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #6=
60">&amp;&amp;);</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; ration=
al </SPAN><SPAN style=3D"COLOR: #660">&amp;</SPAN><SPAN style=3D"COLOR: #00=
8">operator</SPAN><SPAN style=3D"COLOR: #660">=3D(</SPAN><SPAN style=3D"COL=
OR: #000">rational</SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><SPAN style=
=3D"COLOR: #000">T</SPAN><SPAN style=3D"COLOR: #660">&gt;</SPAN><SPAN style=
=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">&amp;&amp;)</SPAN><SPA=
N style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">=3D</SPAN><SPAN=
 style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #008">default</SPAN><S=
PAN style=3D"COLOR: #660">;</SPAN><SPAN style=3D"COLOR: #000"><BR><BR>&nbsp=
; &nbsp; </SPAN><SPAN style=3D"COLOR: #800">// standard operators</SPAN><SP=
AN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; </SPAN><SPAN style=3D"COLOR: #00=
8">template</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR:=
 #660">&lt;</SPAN><SPAN style=3D"COLOR: #008">typename</SPAN><SPAN style=3D=
"COLOR: #000"> U</SPAN><SPAN style=3D"COLOR: #660">&gt;</SPAN><SPAN style=
=3D"COLOR: #000"><BR>&nbsp; &nbsp; rational </SPAN><SPAN style=3D"COLOR: #6=
60">&amp;</SPAN><SPAN style=3D"COLOR: #008">operator</SPAN><SPAN style=3D"C=
OLOR: #660">+=3D(</SPAN><SPAN style=3D"COLOR: #008">const</SPAN><SPAN style=
=3D"COLOR: #000"> rational</SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><SP=
AN style=3D"COLOR: #000">U</SPAN><SPAN style=3D"COLOR: #660">&gt;</SPAN><SP=
AN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">&amp;</SPAN><S=
PAN style=3D"COLOR: #000">rhs</SPAN><SPAN style=3D"COLOR: #660">);</SPAN><S=
PAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; </SPAN><SPAN style=3D"COLOR: #0=
08">template</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR=
: #660">&lt;</SPAN><SPAN style=3D"COLOR: #008">typename</SPAN><SPAN style=
=3D"COLOR: #000"> U</SPAN><SPAN style=3D"COLOR: #660">&gt;</SPAN><SPAN styl=
e=3D"COLOR: #000"><BR>&nbsp; &nbsp; rational </SPAN><SPAN style=3D"COLOR: #=
660">&amp;</SPAN><SPAN style=3D"COLOR: #008">operator</SPAN><SPAN style=3D"=
COLOR: #660">-=3D(</SPAN><SPAN style=3D"COLOR: #008">const</SPAN><SPAN styl=
e=3D"COLOR: #000"> rational</SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><S=
PAN style=3D"COLOR: #000">U</SPAN><SPAN style=3D"COLOR: #660">&gt;</SPAN><S=
PAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">&amp;</SPAN><=
SPAN style=3D"COLOR: #000">rhs</SPAN><SPAN style=3D"COLOR: #660">);</SPAN><=
SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; </SPAN><SPAN style=3D"COLOR: #=
008">template</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLO=
R: #660">&lt;</SPAN><SPAN style=3D"COLOR: #008">typename</SPAN><SPAN style=
=3D"COLOR: #000"> U</SPAN><SPAN style=3D"COLOR: #660">&gt;</SPAN><SPAN styl=
e=3D"COLOR: #000"><BR>&nbsp; &nbsp; rational </SPAN><SPAN style=3D"COLOR: #=
660">&amp;</SPAN><SPAN style=3D"COLOR: #008">operator</SPAN><SPAN style=3D"=
COLOR: #660">*=3D(</SPAN><SPAN style=3D"COLOR: #008">const</SPAN><SPAN styl=
e=3D"COLOR: #000"> rational</SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><S=
PAN style=3D"COLOR: #000">U</SPAN><SPAN style=3D"COLOR: #660">&gt;</SPAN><S=
PAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">&amp;</SPAN><=
SPAN style=3D"COLOR: #000">rhs</SPAN><SPAN style=3D"COLOR: #660">);</SPAN><=
SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; </SPAN><SPAN style=3D"COLOR: #=
008">template</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLO=
R: #660">&lt;</SPAN><SPAN style=3D"COLOR: #008">typename</SPAN><SPAN style=
=3D"COLOR: #000"> U</SPAN><SPAN style=3D"COLOR: #660">&gt;</SPAN><SPAN styl=
e=3D"COLOR: #000"><BR>&nbsp; &nbsp; rational </SPAN><SPAN style=3D"COLOR: #=
660">&amp;</SPAN><SPAN style=3D"COLOR: #008">operator</SPAN><SPAN style=3D"=
COLOR: #660">/=3D(</SPAN><SPAN style=3D"COLOR: #008">const</SPAN><SPAN styl=
e=3D"COLOR: #000"> rational</SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><S=
PAN style=3D"COLOR: #000">U</SPAN><SPAN style=3D"COLOR: #660">&gt;</SPAN><S=
PAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">&amp;</SPAN><=
SPAN style=3D"COLOR: #000">rhs</SPAN><SPAN style=3D"COLOR: #660">);</SPAN><=
SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; rational </SPAN><SPAN style=3D=
"COLOR: #008">operator</SPAN><SPAN style=3D"COLOR: #660">+()</SPAN><SPAN st=
yle=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #008">const</SPAN><SPAN s=
tyle=3D"COLOR: #660">;</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; =
enable_if</SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><SPAN style=3D"COLOR=
: #000">is_signed</SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><SPAN style=
=3D"COLOR: #000">T</SPAN><SPAN style=3D"COLOR: #660">&gt;::</SPAN><SPAN sty=
le=3D"COLOR: #000">type</SPAN><SPAN style=3D"COLOR: #660">,</SPAN><SPAN sty=
le=3D"COLOR: #000"> rational </SPAN><SPAN style=3D"COLOR: #008">operator</S=
PAN><SPAN style=3D"COLOR: #660">-()&gt;;</SPAN></DIV></CODE></DIV></DIV></B=
LOCKQUOTE>
<DIV><BR></DIV>
<DIV>Again, "is_signed&lt;T&gt;" might not make sense for all T's, though t=
he condition I have in mind is a little obtuse:</DIV>
<DIV><I>enable_if_t&lt;is_same&lt;decltype(-<WBR>num), numerator_type&gt;::=
value, rational&gt;</I></DIV></DIV></BLOCKQUOTE>
<DIV>&nbsp;</DIV>
<DIV>Should I have something like:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV style=3D"BORDER-BOTTOM: #bbb 1px solid; BORDER-LEFT: #bbb 1px solid; B=
ACKGROUND-COLOR: #fafafa; WORD-WRAP: break-word; BORDER-TOP: #bbb 1px solid=
; BORDER-RIGHT: #bbb 1px solid" class=3Dprettyprint><CODE class=3Dprettypri=
nt>
<DIV class=3Dsubprettyprint><SPAN style=3D"COLOR: #008" class=3Dstyled-by-p=
rettify>auto</SPAN><SPAN style=3D"COLOR: #000" class=3Dstyled-by-prettify> =
</SPAN><SPAN style=3D"COLOR: #008" class=3Dstyled-by-prettify>operator</SPA=
N><SPAN style=3D"COLOR: #660" class=3Dstyled-by-prettify>-()-&gt;</SPAN><SP=
AN style=3D"COLOR: #000" class=3Dstyled-by-prettify>rational</SPAN><SPAN st=
yle=3D"COLOR: #660" class=3Dstyled-by-prettify>&lt;</SPAN><SPAN style=3D"CO=
LOR: #008" class=3Dstyled-by-prettify>decltype</SPAN><SPAN style=3D"COLOR: =
#660" class=3Dstyled-by-prettify>(-</SPAN><SPAN style=3D"COLOR: #000" class=
=3Dstyled-by-prettify>num</SPAN><SPAN style=3D"COLOR: #660" class=3Dstyled-=
by-prettify>),</SPAN><SPAN style=3D"COLOR: #000" class=3Dstyled-by-prettify=
> denominator_type</SPAN><SPAN style=3D"COLOR: #660" class=3Dstyled-by-pret=
tify>&gt;</SPAN></DIV></CODE></DIV><BR>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV style=3D"BORDER-BOTTOM: rgb(187,187,187) 1px solid; BORDER-LEFT: rgb(1=
87,187,187) 1px solid; BACKGROUND-COLOR: rgb(250,250,250); WORD-WRAP: break=
-word; BORDER-TOP: rgb(187,187,187) 1px solid; BORDER-RIGHT: rgb(187,187,18=
7) 1px solid"><CODE>
<DIV><SPAN style=3D"COLOR: #000"><BR><BR>&nbsp; &nbsp; </SPAN><SPAN style=
=3D"COLOR: #800">// member accessors</SPAN><SPAN style=3D"COLOR: #000"><BR>=
&nbsp; &nbsp; numerator_type numerator</SPAN><SPAN style=3D"COLOR: #660">()=
</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #008">cons=
t</SPAN><SPAN style=3D"COLOR: #660">;</SPAN><SPAN style=3D"COLOR: #000"> </=
SPAN><SPAN style=3D"COLOR: #800">// Note: r-value</SPAN><SPAN style=3D"COLO=
R: #000"><BR>&nbsp; &nbsp; denominator_type denominator</SPAN><SPAN style=
=3D"COLOR: #660">()</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=
=3D"COLOR: #008">const</SPAN><SPAN style=3D"COLOR: #660">;</SPAN><SPAN styl=
e=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #800">// Nate: r-value</SPA=
N><SPAN style=3D"COLOR: #000"><BR><BR>&nbsp; &nbsp; </SPAN><SPAN style=3D"C=
OLOR: #800">// conversion</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbs=
p; </SPAN><SPAN style=3D"COLOR: #008">explicit</SPAN><SPAN style=3D"COLOR: =
#000"> </SPAN><SPAN style=3D"COLOR: #008">operator</SPAN><SPAN style=3D"COL=
OR: #000"> </SPAN><SPAN style=3D"COLOR: #008">bool</SPAN><SPAN style=3D"COL=
OR: #660">()</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR=
: #008">const</SPAN><SPAN style=3D"COLOR: #660">;</SPAN><SPAN style=3D"COLO=
R: #000"> </SPAN><SPAN style=3D"COLOR: #800">// num !=3D 0 || den =3D=3D 0<=
/SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; </SPAN><SPAN style=3D"C=
OLOR: #008">explicit</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=
=3D"COLOR: #008">operator</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN s=
tyle=3D"COLOR: #008">float</SPAN><SPAN style=3D"COLOR: #660">()</SPAN><SPAN=
 style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #008">const</SPAN><SPA=
N style=3D"COLOR: #660">;</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbs=
p; </SPAN><SPAN style=3D"COLOR: #008">explicit</SPAN><SPAN style=3D"COLOR: =
#000"> </SPAN><SPAN style=3D"COLOR: #008">operator</SPAN><SPAN style=3D"COL=
OR: #000"> </SPAN><SPAN style=3D"COLOR: #008">double</SPAN><SPAN style=3D"C=
OLOR: #660">()</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COL=
OR: #008">const</SPAN><SPAN style=3D"COLOR: #660">;</SPAN><SPAN style=3D"CO=
LOR: #000"><BR>&nbsp; &nbsp; </SPAN><SPAN style=3D"COLOR: #008">explicit</S=
PAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #008">operato=
r</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #008">lon=
g</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #008">dou=
ble</SPAN><SPAN style=3D"COLOR: #660">()</SPAN><SPAN style=3D"COLOR: #000">=
 </SPAN><SPAN style=3D"COLOR: #008">const</SPAN><SPAN style=3D"COLOR: #660"=
>;</SPAN><SPAN style=3D"COLOR: #000"><BR><BR>&nbsp; &nbsp; numerator_type f=
loor</SPAN><SPAN style=3D"COLOR: #660">()</SPAN><SPAN style=3D"COLOR: #000"=
> </SPAN><SPAN style=3D"COLOR: #008">const</SPAN><SPAN style=3D"COLOR: #660=
">;</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; numerator_type ceil=
ing</SPAN><SPAN style=3D"COLOR: #660">()</SPAN><SPAN style=3D"COLOR: #000">=
 </SPAN><SPAN style=3D"COLOR: #008">const</SPAN><SPAN style=3D"COLOR: #660"=
>;</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; </SPAN><SPAN style=3D"COLOR=
: #660">};</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; </SPAN><SPAN style=
=3D"COLOR: #008">template</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN s=
tyle=3D"COLOR: #660">&lt;</SPAN><SPAN style=3D"COLOR: #008">typename</SPAN>=
<SPAN style=3D"COLOR: #000"> T</SPAN><SPAN style=3D"COLOR: #660">,</SPAN><S=
PAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #008">typename</SPA=
N><SPAN style=3D"COLOR: #000"> U</SPAN><SPAN style=3D"COLOR: #660">&gt;</SP=
AN><SPAN style=3D"COLOR: #000"><BR>&nbsp; </SPAN><SPAN style=3D"COLOR: #008=
">auto</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #008=
">operator</SPAN><SPAN style=3D"COLOR: #660">+(</SPAN><SPAN style=3D"COLOR:=
 #008">const</SPAN><SPAN style=3D"COLOR: #000"> rational</SPAN><SPAN style=
=3D"COLOR: #660">&lt;</SPAN><SPAN style=3D"COLOR: #000">T</SPAN><SPAN style=
=3D"COLOR: #660">&gt;</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=
=3D"COLOR: #660">&amp;</SPAN><SPAN style=3D"COLOR: #000">lhs</SPAN><SPAN st=
yle=3D"COLOR: #660">,</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=
=3D"COLOR: #008">const</SPAN><SPAN style=3D"COLOR: #000"> rational</SPAN><S=
PAN style=3D"COLOR: #660">&lt;</SPAN><SPAN style=3D"COLOR: #000">T</SPAN><S=
PAN style=3D"COLOR: #660">&gt;</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><S=
PAN style=3D"COLOR: #660">&amp;</SPAN><SPAN style=3D"COLOR: #000">rhs</SPAN=
><SPAN style=3D"COLOR: #660">);</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp=
; </SPAN><SPAN style=3D"COLOR: #800">// sim. for operators -, * and /</SPAN=
><SPAN style=3D"COLOR: #000"><BR><BR>&nbsp; </SPAN><SPAN style=3D"COLOR: #0=
08">template</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR=
: #660">&lt;</SPAN><SPAN style=3D"COLOR: #008">typename</SPAN><SPAN style=
=3D"COLOR: #000"> T</SPAN><SPAN style=3D"COLOR: #660">&gt;</SPAN><SPAN styl=
e=3D"COLOR: #000"><BR>&nbsp; ostream </SPAN><SPAN style=3D"COLOR: #660">&am=
p;</SPAN><SPAN style=3D"COLOR: #008">operator</SPAN><SPAN style=3D"COLOR: #=
660">&lt;&lt;(</SPAN><SPAN style=3D"COLOR: #000">ostream </SPAN><SPAN style=
=3D"COLOR: #660">&amp;,</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN sty=
le=3D"COLOR: #008">const</SPAN><SPAN style=3D"COLOR: #000"> rational</SPAN>=
<SPAN style=3D"COLOR: #660">&lt;</SPAN><SPAN style=3D"COLOR: #000">T</SPAN>=
<SPAN style=3D"COLOR: #660">&gt;</SPAN><SPAN style=3D"COLOR: #000"> </SPAN>=
<SPAN style=3D"COLOR: #660">&amp;);</SPAN><SPAN style=3D"COLOR: #000"><BR>&=
nbsp; </SPAN><SPAN style=3D"COLOR: #008">template</SPAN><SPAN style=3D"COLO=
R: #000"> </SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><SPAN style=3D"COLO=
R: #008">typename</SPAN><SPAN style=3D"COLOR: #000"> T</SPAN><SPAN style=3D=
"COLOR: #660">&gt;</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; istream </S=
PAN><SPAN style=3D"COLOR: #660">&amp;</SPAN><SPAN style=3D"COLOR: #008">ope=
rator</SPAN><SPAN style=3D"COLOR: #660">&gt;&gt;(</SPAN><SPAN style=3D"COLO=
R: #000">istream </SPAN><SPAN style=3D"COLOR: #660">&amp;,</SPAN><SPAN styl=
e=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #008">const</SPAN><SPAN sty=
le=3D"COLOR: #000"> rational</SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><=
SPAN style=3D"COLOR: #000">T</SPAN><SPAN style=3D"COLOR: #660">&gt;</SPAN><=
SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">&amp;);</SPA=
N></DIV></CODE></DIV></DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>Inconsistent. Most C++ types don't define their own "operator&gt;&gt;"=
.. Correct me if I'm wrong, but wouldn't it be ambiguous if the user tried t=
o define their own and ADL pulled in this definition?</DIV></DIV></BLOCKQUO=
TE>
<DIV>&nbsp;</DIV>
<DIV>Accepted.</DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV style=3D"BORDER-BOTTOM: rgb(187,187,187) 1px solid; BORDER-LEFT: rgb(1=
87,187,187) 1px solid; BACKGROUND-COLOR: rgb(250,250,250); WORD-WRAP: break=
-word; BORDER-TOP: rgb(187,187,187) 1px solid; BORDER-RIGHT: rgb(187,187,18=
7) 1px solid"><CODE>
<DIV><SPAN style=3D"COLOR: #000"><BR><BR>&nbsp; </SPAN><SPAN style=3D"COLOR=
: #800">// Comparison operators</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp=
; </SPAN><SPAN style=3D"COLOR: #008">template</SPAN><SPAN style=3D"COLOR: #=
000"> </SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><SPAN style=3D"COLOR: #=
008">typename</SPAN><SPAN style=3D"COLOR: #000"> T</SPAN><SPAN style=3D"COL=
OR: #660">,</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR:=
 #008">typename</SPAN><SPAN style=3D"COLOR: #000"> U</SPAN><SPAN style=3D"C=
OLOR: #660">&gt;</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; </SPAN><SPAN =
style=3D"COLOR: #008">bool</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN =
style=3D"COLOR: #008">operator</SPAN><SPAN style=3D"COLOR: #660">=3D=3D(</S=
PAN><SPAN style=3D"COLOR: #008">const</SPAN><SPAN style=3D"COLOR: #000"> ra=
tional</SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><SPAN style=3D"COLOR: #=
000">T</SPAN><SPAN style=3D"COLOR: #660">&gt;</SPAN><SPAN style=3D"COLOR: #=
000"> </SPAN><SPAN style=3D"COLOR: #660">&amp;,</SPAN><SPAN style=3D"COLOR:=
 #000"> </SPAN><SPAN style=3D"COLOR: #008">const</SPAN><SPAN style=3D"COLOR=
: #000"> rational</SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><SPAN style=
=3D"COLOR: #000">U</SPAN><SPAN style=3D"COLOR: #660">&gt;</SPAN><SPAN style=
=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">&amp;);</SPAN><SPAN st=
yle=3D"COLOR: #000"><BR>&nbsp; </SPAN><SPAN style=3D"COLOR: #800">// sim. f=
or operators !=3D, &lt;, &gt;, &lt;=3D and &gt;=3D</SPAN><SPAN style=3D"COL=
OR: #000"><BR></SPAN><SPAN style=3D"COLOR: #660">}</SPAN><SPAN style=3D"COL=
OR: #000"> </SPAN><SPAN style=3D"COLOR: #800">// namespace std</SPAN><SPAN =
style=3D"COLOR: #000"><BR></SPAN><SPAN style=3D"COLOR: #000"><BR></SPAN></D=
IV></CODE></DIV><BR><BR>Three values would be represented by den =3D=3D 0:<=
BR>-infinity, if num =3D=3D -1<BR>NaN, if num =3D=3D 0<BR>+infinity, if num=
 =3D=3D +1<BR><BR>Otherwise, gcd(num, den) =3D=3D 1 if num !=3D 0, or den =
=3D=3D 1 if num =3D=3D 0.<BR><BR></DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>Think any of the &lt;cmath&gt; functions should have an overload for t=
his? At the least, hypot comes to mind. You mentioned floor and ceil, but a=
s member functions. (They should be overloads.) Perhaps std::div as well.</=
DIV></DIV></BLOCKQUOTE>
<DIV>&nbsp;</DIV>
<DIV>What would std::div do?</DIV>
<DIV>&nbsp;</DIV>
<DIV>Other functions that could be added are:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV><CODE class=3Dprettyprint>
<DIV style=3D"BORDER-BOTTOM: #bbb 1px solid; BORDER-LEFT: #bbb 1px solid; B=
ACKGROUND-COLOR: #fafafa; WORD-WRAP: break-word; BORDER-TOP: #bbb 1px solid=
; BORDER-RIGHT: #bbb 1px solid" class=3Dsubprettyprint><SPAN style=3D"COLOR=
: #000" class=3Dstyled-by-prettify>T round</SPAN><SPAN style=3D"COLOR: #660=
" class=3Dstyled-by-prettify>()</SPAN><SPAN style=3D"COLOR: #000" class=3Ds=
tyled-by-prettify> </SPAN><SPAN style=3D"COLOR: #008" class=3Dstyled-by-pre=
ttify>const</SPAN><SPAN style=3D"COLOR: #660" class=3Dstyled-by-prettify>;<=
/SPAN><SPAN style=3D"COLOR: #000" class=3Dstyled-by-prettify> </SPAN><SPAN =
style=3D"COLOR: #800" class=3Dstyled-by-prettify>// round to even &nbsp;</S=
PAN><SPAN style=3D"COLOR: #000" class=3Dstyled-by-prettify>&nbsp;<BR>&nbsp;=
 &nbsp;<BR></SPAN><SPAN style=3D"COLOR: #008" class=3Dstyled-by-prettify>bo=
ol</SPAN><SPAN style=3D"COLOR: #000" class=3Dstyled-by-prettify> is_finite<=
/SPAN><SPAN style=3D"COLOR: #660" class=3Dstyled-by-prettify>()</SPAN><SPAN=
 style=3D"COLOR: #000" class=3Dstyled-by-prettify> </SPAN><SPAN style=3D"CO=
LOR: #008" class=3Dstyled-by-prettify>const</SPAN><SPAN style=3D"COLOR: #00=
0" class=3Dstyled-by-prettify> </SPAN><SPAN style=3D"COLOR: #660" class=3Ds=
tyled-by-prettify>{</SPAN><SPAN style=3D"COLOR: #008" class=3Dstyled-by-pre=
ttify>return</SPAN><SPAN style=3D"COLOR: #000" class=3Dstyled-by-prettify> =
den </SPAN><SPAN style=3D"COLOR: #660" class=3Dstyled-by-prettify>!=3D</SPA=
N><SPAN style=3D"COLOR: #000" class=3Dstyled-by-prettify> </SPAN><SPAN styl=
e=3D"COLOR: #066" class=3Dstyled-by-prettify>0</SPAN><SPAN style=3D"COLOR: =
#660" class=3Dstyled-by-prettify>;</SPAN><SPAN style=3D"COLOR: #000" class=
=3Dstyled-by-prettify> </SPAN><SPAN style=3D"COLOR: #660" class=3Dstyled-by=
-prettify>}</SPAN><SPAN style=3D"COLOR: #000" class=3Dstyled-by-prettify> &=
nbsp;&nbsp;<BR></SPAN><SPAN style=3D"COLOR: #008" class=3Dstyled-by-prettif=
y>bool</SPAN><SPAN style=3D"COLOR: #000" class=3Dstyled-by-prettify> is_nan=
</SPAN><SPAN style=3D"COLOR: #660" class=3Dstyled-by-prettify>()</SPAN><SPA=
N style=3D"COLOR: #000" class=3Dstyled-by-prettify> </SPAN><SPAN style=3D"C=
OLOR: #008" class=3Dstyled-by-prettify>const</SPAN><SPAN style=3D"COLOR: #0=
00" class=3Dstyled-by-prettify> </SPAN><SPAN style=3D"COLOR: #660" class=3D=
styled-by-prettify>{</SPAN><SPAN style=3D"COLOR: #008" class=3Dstyled-by-pr=
ettify>return</SPAN><SPAN style=3D"COLOR: #000" class=3Dstyled-by-prettify>=
 den </SPAN><SPAN style=3D"COLOR: #660" class=3Dstyled-by-prettify>=3D=3D</=
SPAN><SPAN style=3D"COLOR: #000" class=3Dstyled-by-prettify> </SPAN><SPAN s=
tyle=3D"COLOR: #066" class=3Dstyled-by-prettify>0</SPAN><SPAN style=3D"COLO=
R: #000" class=3Dstyled-by-prettify> </SPAN><SPAN style=3D"COLOR: #660" cla=
ss=3Dstyled-by-prettify>&amp;&amp;</SPAN><SPAN style=3D"COLOR: #000" class=
=3Dstyled-by-prettify> num </SPAN><SPAN style=3D"COLOR: #660" class=3Dstyle=
d-by-prettify>=3D=3D</SPAN><SPAN style=3D"COLOR: #000" class=3Dstyled-by-pr=
ettify> </SPAN><SPAN style=3D"COLOR: #066" class=3Dstyled-by-prettify>0</SP=
AN><SPAN style=3D"COLOR: #660" class=3Dstyled-by-prettify>;</SPAN><SPAN sty=
le=3D"COLOR: #000" class=3Dstyled-by-prettify> </SPAN><SPAN style=3D"COLOR:=
 #660" class=3Dstyled-by-prettify>}</SPAN></DIV>
<DIV style=3D"BORDER-BOTTOM: #bbb 1px solid; BORDER-LEFT: #bbb 1px solid; B=
ACKGROUND-COLOR: #fafafa; WORD-WRAP: break-word; BORDER-TOP: #bbb 1px solid=
; BORDER-RIGHT: #bbb 1px solid" class=3Dprettyprint><BR>&nbsp;</DIV>
<DIV style=3D"BORDER-BOTTOM: #bbb 1px solid; BORDER-LEFT: #bbb 1px solid; B=
ACKGROUND-COLOR: #fafafa; WORD-WRAP: break-word; BORDER-TOP: #bbb 1px solid=
; BORDER-RIGHT: #bbb 1px solid" class=3Dprettyprint>&nbsp;</DIV></CODE>
<DIV>given that I have specified representations for NaN and <FONT color=3D=
#000000 size=3D3 face=3Darial,sans-serif>=C2=B1=E2=88=9E</FONT>.</DIV>
<DIV>&nbsp;</DIV>
<DIV>I have specifically not followed boost::rational in including pre/post=
-inc/decrement operators, as they seem somewhat incongruous.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Doug.</DIV></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_3464_1868083222.1422881573330--
------=_Part_3463_506603990.1422881573329--

.


Author: Douglas Boffey <douglas.boffey@gmail.com>
Date: Mon, 2 Feb 2015 18:19:52 +0000
Raw View
Sorry.  I misunderstood what you were referring to re: template metaprogramming.

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: Myriachan <myriachan@gmail.com>
Date: Mon, 2 Feb 2015 18:39:12 -0800 (PST)
Raw View
------=_Part_158_1678938458.1422931152252
Content-Type: multipart/alternative;
 boundary="----=_Part_159_2131025673.1422931152252"

------=_Part_159_2131025673.1422931152252
Content-Type: text/plain; charset=UTF-8

Perhaps this rationals proposal ought to be an extension of the big number
proposal, in that it would be one big number divided by another?

I've thought about finishing the big number proposal, like adding missing
functionality and fixing various issues with it.

On Monday, February 2, 2015 at 10:19:54 AM UTC-8, Douglas Boffey wrote:
>
> Sorry.  I misunderstood what you were referring to re: template
> metaprogramming.
>

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

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

<div dir=3D"ltr">Perhaps this rationals proposal ought to be an extension o=
f the big number proposal, in that it would be one big number divided by an=
other?<br><br>I've thought about finishing the big number proposal, like ad=
ding missing functionality and fixing various issues with it.<br><br>On Mon=
day, February 2, 2015 at 10:19:54 AM UTC-8, Douglas Boffey wrote:<blockquot=
e class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: =
1px #ccc solid;padding-left: 1ex;">Sorry. &nbsp;I misunderstood what you we=
re referring to re: template metaprogramming.
<br></blockquote></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_159_2131025673.1422931152252--
------=_Part_158_1678938458.1422931152252--

.


Author: Scott Prager <splinterofchaos@gmail.com>
Date: Wed, 4 Feb 2015 08:22:28 -0800 (PST)
Raw View
------=_Part_508_985222863.1423066948621
Content-Type: multipart/alternative;
 boundary="----=_Part_509_1541740071.1423066948621"

------=_Part_509_1541740071.1423066948621
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



On Monday, February 2, 2015 at 7:52:53 AM UTC-5, Douglas Boffey wrote:
>
>
> On Sunday, 1 February 2015 02:19:48 UTC, Scott Prager wrote:=20
>>
>> On Saturday, January 31, 2015 at 4:05:02 PM UTC-5, Douglas Boffey wrote:=
=20
>>>
>>> I would like to see a rational class:
>>>
>>
>> I was about to point out std::ratio, but then I realized it's compile=20
>> time only, which is odd because I don't think it pre-dated constexpr. Is=
=20
>> there a reason that template meta-programming was chosen over a=20
>> constexpr/runtime interface?
>>
> =20
> Eh?  I don=E2=80=99t see anywhere in my posting where I=E2=80=99ve used T=
MP.  Certainly, I=20
> have omitted any constexprs in my draft, just like I=E2=80=99ve not speci=
fied any=20
> exception specifications.
>
>>  =20
>>
>>>  namespace std {
>>>   template <typename T>
>>>   class rational {
>>>
>>
>> Shouldn't the numerator and denominator be separately typed?
>>
> =20
> Possibly (mayby defaulted to typename make_unsigned<T>::type?)  I would=
=20
> certainly object to a library where the numerator and denominator were=20
> forced to be the same type (why would you want negative denominators?)
>

Why not? Let's say I used this rational type to implement linear algebra=20
functions. I might use "rational(x, y)" to represent the slope of a=20
function. Or, maybe I want to write an inverse(x) function that returns=20
rational(1, x). If the denominator can't be negative, the inverse would=20
have to be written like this:

  rational<int> inverse(int x) {
      return x < 0 ? {-1, (unsigned)-x} : {1, (unsigned)x};
   }

At least assuming rational keeps its non-explicit constructors.


>>>     enable_if<is_signed<T>::type, rational operator-()>;
>>>
>>
>> Again, "is_signed<T>" might not make sense for all T's, though the=20
>> condition I have in mind is a little obtuse:
>> *enable_if_t<is_same<decltype(-num), numerator_type>::value, rational>*
>>
> =20
> Should I have something like:
> =20
> =20
>  auto operator-()->rational<decltype(-num), denominator_type>
>

Not sure *what* the best practice would be here, but allowing *-rational<un=
signed>(x,=20
y)* to have any type other than *rational<unsigned>* might be surprising to=
=20
users. That's why I thought of *enable_if*.
=20

> =20
>
=20
>
>>  =20
>>
>>> =20
>>>
>>>     // member accessors
>>>     numerator_type numerator() const; // Note: r-value
>>>     denominator_type denominator() const; // Nate: r-value
>>>
>>
I just realized this class doesn't offer a way to manually change/modify=20
the numerator or denominator... (not a criticism, just observing.)


>>>
>> Think any of the <cmath> functions should have an overload for this? At=
=20
>> the least, hypot comes to mind. You mentioned floor and ceil, but as mem=
ber=20
>> functions. (They should be overloads.) Perhaps std::div as well.
>>
> =20
> What would std::div do?
>

First, it would inverse multiply the two rationals, then return an=20
std::div_t with the remainder and quotient. Though, I think when I wrote=20
that, I was considering std::div(rational(x, y)) being equivalent to=20
std::div(x, y).
=20

> =20
> Other functions that could be added are:
> =20
> =20
> T round() const; // round to even  =20
>   =20
> bool is_finite() const {return den !=3D 0; }  =20
> bool is_nan() const {return den =3D=3D 0 && num =3D=3D 0; }
>
> =20
> =20
> given that I have specified representations for NaN and =C2=B1=E2=88=9E.
> =20
> I have specifically not followed boost::rational in including=20
> pre/post-inc/decrement operators, as they seem somewhat incongruous.
> =20
> Doug.
>

--=20

---=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

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

<div dir=3D"ltr"><br><br>On Monday, February 2, 2015 at 7:52:53 AM UTC-5, D=
ouglas Boffey wrote:<blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr"><br>On Sunday, 1 February 2015 02:19:48 UTC, Scott Prager wrote:=
=20
<blockquote style=3D"BORDER-LEFT:#ccc 1px solid;MARGIN:0px 0px 0px 0.8ex;PA=
DDING-LEFT:1ex" class=3D"gmail_quote">
<div dir=3D"ltr">On Saturday, January 31, 2015 at 4:05:02 PM UTC-5, Douglas=
 Boffey wrote:=20
<blockquote style=3D"BORDER-LEFT:#ccc 1px solid;MARGIN:0px 0px 0px 0.8ex;PA=
DDING-LEFT:1ex" class=3D"gmail_quote">
<div dir=3D"ltr">I would like to see a rational class:<br></div></blockquot=
e>
<div><br></div>
<div>I was about to point out std::ratio, but then I realized it's compile =
time only, which is odd because I don't think it pre-dated constexpr. Is th=
ere a reason that template meta-programming was chosen over a constexpr/run=
time interface?</div></div></blockquote>
<div>&nbsp;</div>
<div>Eh?&nbsp; I don=E2=80=99t see anywhere in my posting where I=E2=80=99v=
e used&nbsp;TMP.&nbsp; Certainly, I have omitted any constexprs in my draft=
, just like I=E2=80=99ve not specified any exception specifications.</div>
<blockquote style=3D"BORDER-LEFT:#ccc 1px solid;MARGIN:0px 0px 0px 0.8ex;PA=
DDING-LEFT:1ex" class=3D"gmail_quote">
<div dir=3D"ltr">
<div>&nbsp;</div>
<blockquote style=3D"BORDER-LEFT:#ccc 1px solid;MARGIN:0px 0px 0px 0.8ex;PA=
DDING-LEFT:1ex" class=3D"gmail_quote">
<div dir=3D"ltr">
<div style=3D"BORDER-BOTTOM:rgb(187,187,187) 1px solid;BORDER-LEFT:rgb(187,=
187,187) 1px solid;BACKGROUND-COLOR:rgb(250,250,250);WORD-WRAP:break-word;B=
ORDER-TOP:rgb(187,187,187) 1px solid;BORDER-RIGHT:rgb(187,187,187) 1px soli=
d"><code>
<div><span style=3D"COLOR:#008">namespace</span><span style=3D"COLOR:#000">=
 std </span><span style=3D"COLOR:#660">{</span><span style=3D"COLOR:#000"><=
br>&nbsp; </span><span style=3D"COLOR:#008">template</span><span style=3D"C=
OLOR:#000"> </span><span style=3D"COLOR:#660">&lt;</span><span style=3D"COL=
OR:#008">typename</span><span style=3D"COLOR:#000"> T</span><span style=3D"=
COLOR:#660">&gt;</span><span style=3D"COLOR:#000"><br>&nbsp; </span><span s=
tyle=3D"COLOR:#008">class</span><span style=3D"COLOR:#000"> rational </span=
><span style=3D"COLOR:#660">{</span></div></code></div></div></blockquote>
<div><span style=3D"FONT-SIZE:13px"><br></span></div>
<div><span style=3D"FONT-SIZE:13px">Shouldn't the numerator and denominator=
 be separately typed?</span></div></div></blockquote>
<div>&nbsp;</div>
<div>Possibly (mayby defaulted to <code><span style=3D"COLOR:#008">typename=
</span><span style=3D"COLOR:#000"> make_unsigned</span><span style=3D"COLOR=
:#660">&lt;</span><span style=3D"COLOR:#000">T</span><span style=3D"COLOR:#=
660">&gt;::</span><span style=3D"COLOR:#000">type?</span></code>)&nbsp; I w=
ould certainly object to a library where the numerator and denominator were=
 forced to be the same type (why would you want negative denominators?)</di=
v></div></blockquote><div><br></div><div>Why not? Let's say I used this rat=
ional type to implement linear algebra functions. I might use "rational(x, =
y)" to represent the slope of a function. Or, maybe I want to write an inve=
rse(x) function that returns rational(1, x). If the denominator can't be ne=
gative, the inverse would have to be written like this:</div><div><br></div=
><div>&nbsp; rational&lt;int&gt; inverse(int x) {</div><div>&nbsp; &nbsp; &=
nbsp; return <span style=3D"font-size: 13.3333339691162px;">x &lt; 0</span>=
<span style=3D"font-size: 13px;">&nbsp;? {-1, (unsigned)-x} : {1, (unsigned=
)x};</span></div><div>&nbsp; &nbsp;}</div><div><br></div><div>At least assu=
ming rational keeps its non-explicit constructors.</div><div><br></div><blo=
ckquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-=
left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><blockquote style=
=3D"BORDER-LEFT:#ccc 1px solid;MARGIN:0px 0px 0px 0.8ex;PADDING-LEFT:1ex" c=
lass=3D"gmail_quote"><div dir=3D"ltr"><blockquote style=3D"BORDER-LEFT:#ccc=
 1px solid;MARGIN:0px 0px 0px 0.8ex;PADDING-LEFT:1ex" class=3D"gmail_quote"=
><div dir=3D"ltr"><div style=3D"BORDER-BOTTOM:rgb(187,187,187) 1px solid;BO=
RDER-LEFT:rgb(187,187,187) 1px solid;BACKGROUND-COLOR:rgb(250,250,250);WORD=
-WRAP:break-word;BORDER-TOP:rgb(187,187,187) 1px solid;BORDER-RIGHT:rgb(187=
,187,187) 1px solid"><code><div><span style=3D"COLOR:#000"><br>&nbsp; &nbsp=
; enable_if</span><span style=3D"COLOR:#660">&lt;</span><span style=3D"COLO=
R:#000">is_signed</span><span style=3D"COLOR:#660">&lt;</span><span style=
=3D"COLOR:#000">T</span><span style=3D"COLOR:#660">&gt;::</span><span style=
=3D"COLOR:#000">type</span><span style=3D"COLOR:#660">,</span><span style=
=3D"COLOR:#000"> rational </span><span style=3D"COLOR:#008">operator</span>=
<span style=3D"COLOR:#660">-()&gt;;</span></div></code></div></div></blockq=
uote>
<div><br></div>
<div>Again, "is_signed&lt;T&gt;" might not make sense for all T's, though t=
he condition I have in mind is a little obtuse:</div>
<div><i>enable_if_t&lt;is_same&lt;decltype(-<wbr>num), numerator_type&gt;::=
value, rational&gt;</i></div></div></blockquote>
<div>&nbsp;</div>
<div>Should I have something like:</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div style=3D"BORDER-BOTTOM:#bbb 1px solid;BORDER-LEFT:#bbb 1px solid;BACKG=
ROUND-COLOR:#fafafa;WORD-WRAP:break-word;BORDER-TOP:#bbb 1px solid;BORDER-R=
IGHT:#bbb 1px solid"><code>
<div><span style=3D"COLOR:#008">auto</span><span style=3D"COLOR:#000"> </sp=
an><span style=3D"COLOR:#008">operator</span><span style=3D"COLOR:#660">-()=
-&gt;</span><span style=3D"COLOR:#000">rational</span><span style=3D"COLOR:=
#660">&lt;</span><span style=3D"COLOR:#008">decltype</span><span style=3D"C=
OLOR:#660"><wbr>(-</span><span style=3D"COLOR:#000">num</span><span style=
=3D"COLOR:#660">),</span><span style=3D"COLOR:#000"> denominator_type</span=
><span style=3D"COLOR:#660">&gt;</span></div></code></div></div></blockquot=
e><div><br></div><div>Not sure <i>what</i>&nbsp;the best practice would be =
here, but allowing <i>-rational&lt;unsigned&gt;(x, y)</i> to have any type =
other than <i>rational&lt;unsigned&gt;</i> might be surprising to users. Th=
at's why I thought of <i>enable_if</i>.</div><div>&nbsp;</div><blockquote c=
lass=3D"gmail_quote" style=3D"margin: 0;margin-left: 0.8ex;border-left: 1px=
 #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><div style=3D"BORDER-BOTTO=
M:#bbb 1px solid;BORDER-LEFT:#bbb 1px solid;BACKGROUND-COLOR:#fafafa;WORD-W=
RAP:break-word;BORDER-TOP:#bbb 1px solid;BORDER-RIGHT:#bbb 1px solid"><code=
><div><span style=3D"font-family: Arial, Helvetica, sans-serif; font-size: =
13px; background-color: white;">&nbsp;</span></div></code></div></div></blo=
ckquote><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left: 0=
..8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr">
<div>&nbsp;</div>
<blockquote style=3D"BORDER-LEFT:#ccc 1px solid;MARGIN:0px 0px 0px 0.8ex;PA=
DDING-LEFT:1ex" class=3D"gmail_quote">
<div dir=3D"ltr">
<div>&nbsp;</div>
<blockquote style=3D"BORDER-LEFT:#ccc 1px solid;MARGIN:0px 0px 0px 0.8ex;PA=
DDING-LEFT:1ex" class=3D"gmail_quote">
<div dir=3D"ltr">
<div style=3D"BORDER-BOTTOM:rgb(187,187,187) 1px solid;BORDER-LEFT:rgb(187,=
187,187) 1px solid;BACKGROUND-COLOR:rgb(250,250,250);WORD-WRAP:break-word;B=
ORDER-TOP:rgb(187,187,187) 1px solid;BORDER-RIGHT:rgb(187,187,187) 1px soli=
d"><code>
<div><span style=3D"COLOR:#000"><br><br>&nbsp; &nbsp; </span><span style=3D=
"COLOR:#800">// member accessors</span><span style=3D"COLOR:#000"><br>&nbsp=
; &nbsp; numerator_type numerator</span><span style=3D"COLOR:#660">()</span=
><span style=3D"COLOR:#000"> </span><span style=3D"COLOR:#008">const</span>=
<span style=3D"COLOR:#660">;</span><span style=3D"COLOR:#000"> </span><span=
 style=3D"COLOR:#800">// Note: r-value</span><span style=3D"COLOR:#000"><br=
>&nbsp; &nbsp; denominator_type denominator</span><span style=3D"COLOR:#660=
">()</span><span style=3D"COLOR:#000"> </span><span style=3D"COLOR:#008">co=
nst</span><span style=3D"COLOR:#660">;</span><span style=3D"COLOR:#000"> </=
span><span style=3D"COLOR:#800">// Nate: r-value</span></div></code></div><=
/div></blockquote></div></blockquote></div></blockquote><div><br></div><div=
>I just realized this class doesn't offer a way to manually change/modify t=
he numerator or denominator... (not a criticism, just observing.)</div><div=
><br></div><blockquote class=3D"gmail_quote" style=3D"margin: 0;margin-left=
: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=3D"ltr"><b=
lockquote style=3D"BORDER-LEFT:#ccc 1px solid;MARGIN:0px 0px 0px 0.8ex;PADD=
ING-LEFT:1ex" class=3D"gmail_quote"><div dir=3D"ltr"><blockquote style=3D"B=
ORDER-LEFT:#ccc 1px solid;MARGIN:0px 0px 0px 0.8ex;PADDING-LEFT:1ex" class=
=3D"gmail_quote"><div dir=3D"ltr"><br></div></blockquote>
<div><br></div>
<div>Think any of the &lt;cmath&gt; functions should have an overload for t=
his? At the least, hypot comes to mind. You mentioned floor and ceil, but a=
s member functions. (They should be overloads.) Perhaps std::div as well.</=
div></div></blockquote>
<div>&nbsp;</div>
<div>What would std::div do?</div></div></blockquote><div><br></div><div>Fi=
rst, it would inverse multiply the two rationals, then return an std::div_t=
 with the remainder and quotient. Though, I think when I wrote that, I was =
considering std::div(rational(x, y)) being equivalent to std::div(x, y).</d=
iv><div>&nbsp;</div><blockquote class=3D"gmail_quote" style=3D"margin: 0;ma=
rgin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;"><div dir=
=3D"ltr">
<div>&nbsp;</div>
<div>Other functions that could be added are:</div>
<div>&nbsp;</div>
<div>&nbsp;</div><code>
<div style=3D"BORDER-BOTTOM:#bbb 1px solid;BORDER-LEFT:#bbb 1px solid;BACKG=
ROUND-COLOR:#fafafa;WORD-WRAP:break-word;BORDER-TOP:#bbb 1px solid;BORDER-R=
IGHT:#bbb 1px solid"><span style=3D"COLOR:#000">T round</span><span style=
=3D"COLOR:#660">()</span><span style=3D"COLOR:#000"> </span><span style=3D"=
COLOR:#008">const</span><span style=3D"COLOR:#660">;</span><span style=3D"C=
OLOR:#000"> </span><span style=3D"COLOR:#800">// round to even &nbsp;</span=
><span style=3D"COLOR:#000">&nbsp;<br>&nbsp; &nbsp;<br></span><span style=
=3D"COLOR:#008">bool</span><span style=3D"COLOR:#000"> is_finite</span><spa=
n style=3D"COLOR:#660">()</span><span style=3D"COLOR:#000"> </span><span st=
yle=3D"COLOR:#008">const</span><span style=3D"COLOR:#000"> </span><span sty=
le=3D"COLOR:#660">{</span><span style=3D"COLOR:#008">return</span><span sty=
le=3D"COLOR:#000"> den </span><span style=3D"COLOR:#660">!=3D</span><span s=
tyle=3D"COLOR:#000"> </span><span style=3D"COLOR:#066">0</span><span style=
=3D"COLOR:#660">;</span><span style=3D"COLOR:#000"> </span><span style=3D"C=
OLOR:#660">}</span><span style=3D"COLOR:#000"> &nbsp;&nbsp;<br></span><span=
 style=3D"COLOR:#008">bool</span><span style=3D"COLOR:#000"> is_nan</span><=
span style=3D"COLOR:#660">()</span><span style=3D"COLOR:#000"> </span><span=
 style=3D"COLOR:#008">const</span><span style=3D"COLOR:#000"> </span><span =
style=3D"COLOR:#660">{</span><span style=3D"COLOR:#008">return</span><span =
style=3D"COLOR:#000"> den </span><span style=3D"COLOR:#660">=3D=3D</span><s=
pan style=3D"COLOR:#000"> </span><span style=3D"COLOR:#066">0</span><span s=
tyle=3D"COLOR:#000"> </span><span style=3D"COLOR:#660">&amp;&amp;</span><sp=
an style=3D"COLOR:#000"> num </span><span style=3D"COLOR:#660">=3D=3D</span=
><span style=3D"COLOR:#000"> </span><span style=3D"COLOR:#066">0</span><spa=
n style=3D"COLOR:#660">;</span><span style=3D"COLOR:#000"> </span><span sty=
le=3D"COLOR:#660">}</span></div>
<div style=3D"BORDER-BOTTOM:#bbb 1px solid;BORDER-LEFT:#bbb 1px solid;BACKG=
ROUND-COLOR:#fafafa;WORD-WRAP:break-word;BORDER-TOP:#bbb 1px solid;BORDER-R=
IGHT:#bbb 1px solid"><br>&nbsp;</div>
<div style=3D"BORDER-BOTTOM:#bbb 1px solid;BORDER-LEFT:#bbb 1px solid;BACKG=
ROUND-COLOR:#fafafa;WORD-WRAP:break-word;BORDER-TOP:#bbb 1px solid;BORDER-R=
IGHT:#bbb 1px solid">&nbsp;</div></code>
<div>given that I have specified representations for NaN and <font color=3D=
"#000000" size=3D"3" face=3D"arial,sans-serif">=C2=B1=E2=88=9E</font>.</div=
>
<div>&nbsp;</div>
<div>I have specifically not followed boost::rational in including pre/post=
-inc/decrement operators, as they seem somewhat incongruous.</div>
<div>&nbsp;</div>
<div>Doug.</div></div></blockquote></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_509_1541740071.1423066948621--
------=_Part_508_985222863.1423066948621--

.


Author: Douglas Boffey <douglas.boffey@gmail.com>
Date: Wed, 4 Feb 2015 16:51:04 +0000
Raw View
For inverse, I assume you mean 'reciprocal'.  I didn't give write
access to num/den to maintain canonicity.

On 2/4/15, Scott Prager <splinterofchaos@gmail.com> wrote:
>
>
> On Monday, February 2, 2015 at 7:52:53 AM UTC-5, Douglas Boffey wrote:
>>
>>
>> On Sunday, 1 February 2015 02:19:48 UTC, Scott Prager wrote:
>>>
>>> On Saturday, January 31, 2015 at 4:05:02 PM UTC-5, Douglas Boffey wrote=
:
>>>
>>>>
>>>> I would like to see a rational class:
>>>>
>>>
>>> I was about to point out std::ratio, but then I realized it's compile
>>> time only, which is odd because I don't think it pre-dated constexpr. I=
s
>>>
>>> there a reason that template meta-programming was chosen over a
>>> constexpr/runtime interface?
>>>
>>
>> Eh?  I don=E2=80=99t see anywhere in my posting where I=E2=80=99ve used =
TMP.  Certainly, I
>>
>> have omitted any constexprs in my draft, just like I=E2=80=99ve not spec=
ified any
>>
>> exception specifications.
>>
>>>
>>>
>>>>  namespace std {
>>>>   template <typename T>
>>>>   class rational {
>>>>
>>>
>>> Shouldn't the numerator and denominator be separately typed?
>>>
>>
>> Possibly (mayby defaulted to typename make_unsigned<T>::type?)  I would
>> certainly object to a library where the numerator and denominator were
>> forced to be the same type (why would you want negative denominators?)
>>
>
> Why not? Let's say I used this rational type to implement linear algebra
> functions. I might use "rational(x, y)" to represent the slope of a
> function. Or, maybe I want to write an inverse(x) function that returns
> rational(1, x). If the denominator can't be negative, the inverse would
> have to be written like this:
>
>   rational<int> inverse(int x) {
>       return x < 0 ? {-1, (unsigned)-x} : {1, (unsigned)x};
>    }
>
> At least assuming rational keeps its non-explicit constructors.
>
>
>>>>     enable_if<is_signed<T>::type, rational operator-()>;
>>>>
>>>
>>> Again, "is_signed<T>" might not make sense for all T's, though the
>>> condition I have in mind is a little obtuse:
>>> *enable_if_t<is_same<decltype(-num), numerator_type>::value, rational>*
>>>
>>
>> Should I have something like:
>>
>>
>>  auto operator-()->rational<decltype(-num), denominator_type>
>>
>
> Not sure *what* the best practice would be here, but allowing
> *-rational<unsigned>(x,
> y)* to have any type other than *rational<unsigned>* might be surprising =
to
>
> users. That's why I thought of *enable_if*.
>
>
>>
>>
>
>>
>>>
>>>
>>>>
>>>>
>>>>     // member accessors
>>>>     numerator_type numerator() const; // Note: r-value
>>>>     denominator_type denominator() const; // Nate: r-value
>>>>
>>>
> I just realized this class doesn't offer a way to manually change/modify
> the numerator or denominator... (not a criticism, just observing.)
>
>
>>>>
>>> Think any of the <cmath> functions should have an overload for this? At
>>> the least, hypot comes to mind. You mentioned floor and ceil, but as
>>> member
>>> functions. (They should be overloads.) Perhaps std::div as well.
>>>
>>
>> What would std::div do?
>>
>
> First, it would inverse multiply the two rationals, then return an
> std::div_t with the remainder and quotient. Though, I think when I wrote
> that, I was considering std::div(rational(x, y)) being equivalent to
> std::div(x, y).
>
>
>>
>> Other functions that could be added are:
>>
>>
>> T round() const; // round to even
>>
>> bool is_finite() const {return den !=3D 0; }
>> bool is_nan() const {return den =3D=3D 0 && num =3D=3D 0; }
>>
>>
>>
>> given that I have specified representations for NaN and =C2=B1=E2=88=9E.
>>
>> I have specifically not followed boost::rational in including
>> pre/post-inc/decrement operators, as they seem somewhat incongruous.
>>
>> Doug.
>>
>
> --
>
> ---
> 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.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>

--=20

---=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

.


Author: Douglas Boffey <douglas.boffey@gmail.com>
Date: Thu, 5 Feb 2015 03:33:53 -0800 (PST)
Raw View
------=_Part_3922_647184036.1423136033068
Content-Type: multipart/alternative;
 boundary="----=_Part_3923_217420997.1423136033068"

------=_Part_3923_217420997.1423136033068
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable


On Wednesday, 4 February 2015 16:22:28 UTC, Scott Prager wrote:=20
>
>
>
> On Monday, February 2, 2015 at 7:52:53 AM UTC-5, Douglas Boffey wrote:=20
>>
>>
>> On Sunday, 1 February 2015 02:19:48 UTC, Scott Prager wrote:=20
>>>
>>> On Saturday, January 31, 2015 at 4:05:02 PM UTC-5, Douglas Boffey wrote=
:=20
>>>>
>>>> I would like to see a rational class:
>>>>
>>>
>>> I was about to point out std::ratio, but then I realized it's compile=
=20
>>> time only, which is odd because I don't think it pre-dated constexpr. I=
s=20
>>> there a reason that template meta-programming was chosen over a=20
>>> constexpr/runtime interface?
>>>
>> =20
>> Eh?  I don=E2=80=99t see anywhere in my posting where I=E2=80=99ve used =
TMP.  Certainly,=20
>> I have omitted any constexprs in my draft, just like I=E2=80=99ve not sp=
ecified any=20
>> exception specifications.
>>
>>>  =20
>>>
>>>>  namespace std {
>>>>   template <typename T>
>>>>   class rational {
>>>>
>>>
>>> Shouldn't the numerator and denominator be separately typed?
>>>
>> =20
>> Possibly (mayby defaulted to typename make_unsigned<T>::type?)  I would=
=20
>> certainly object to a library where the numerator and denominator were=
=20
>> forced to be the same type (why would you want negative denominators?)
>>
>
> Why not? Let's say I used this rational type to implement linear algebra=
=20
> functions. I might use "rational(x, y)" to represent the slope of a=20
> function. Or, maybe I want to write an inverse(x) function that returns=
=20
> rational(1, x). If the denominator can't be negative, the inverse would=
=20
> have to be written like this:
>
>   rational<int> inverse(int x) {
>       return x < 0 ? {-1, (unsigned)-x} : {1, (unsigned)x};
>    }
>
> At least assuming rational keeps its non-explicit constructors.
>
>    =20
>>>>     enable_if<is_signed<T>::type, rational operator-()>;
>>>>
>>>
>>> Again, "is_signed<T>" might not make sense for all T's, though the=20
>>> condition I have in mind is a little obtuse:
>>> *enable_if_t<is_same<decltype(-num), numerator_type>::value, rational>*
>>>
>> =20
>> Should I have something like:
>> =20
>> =20
>>  auto operator-()->rational<decltype(-num), denominator_type>
>>
>
> Not sure *what* the best practice would be here, but allowing *-rational<=
unsigned>(x,=20
> y)* to have any type other than *rational<unsigned>* might be surprising=
=20
> to users. That's why I thought of *enable_if*.
> =20
>
>>  =20
>>
>  =20
>>
>>>  =20
>>>
>>>> =20
>>>>
>>>>     // member accessors
>>>>     numerator_type numerator() const; // Note: r-value
>>>>     denominator_type denominator() const; // Nate: r-value
>>>>
>>>
> I just realized this class doesn't offer a way to manually change/modify=
=20
> the numerator or denominator... (not a criticism, just observing.)
>
>   =20
>>>>
>>> Think any of the <cmath> functions should have an overload for this? At=
=20
>>> the least, hypot comes to mind. You mentioned floor and ceil, but as me=
mber=20
>>> functions. (They should be overloads.) Perhaps std::div as well.
>>>
>> =20
>> What would std::div do?
>>
>
> First, it would inverse multiply the two rationals, then return an=20
> std::div_t with the remainder and quotient. Though, I think when I wrote=
=20
> that, I was considering std::div(rational(x, y)) being equivalent to=20
> std::div(x, y).
>
=20
By =E2=80=98inverse multiply=E2=80=99, do I take it you mean =E2=80=98divid=
e=E2=80=99?
=20
I am not sure of the value of such a method.

>  =20
>
>>  =20
>> Other functions that could be added are:
>> =20
>> =20
>> T round() const; // round to even  =20
>>   =20
>> bool is_finite() const {return den !=3D 0; }  =20
>> bool is_nan() const {return den =3D=3D 0 && num =3D=3D 0; }
>>
>> =20
>> =20
>> given that I have specified representations for NaN and =C2=B1=E2=88=9E.
>> =20
>> I have specifically not followed boost::rational in including=20
>> pre/post-inc/decrement operators, as they seem somewhat incongruous.
>> =20
>> Doug.
>>
>

--=20

---=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

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

<div dir=3D"ltr"><BR>On Wednesday, 4 February 2015 16:22:28 UTC, Scott Prag=
er wrote:=20
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr><BR><BR>On Monday, February 2, 2015 at 7:52:53 AM UTC-5, Dou=
glas Boffey wrote:=20
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr><BR>On Sunday, 1 February 2015 02:19:48 UTC, Scott Prager wr=
ote:=20
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>On Saturday, January 31, 2015 at 4:05:02 PM UTC-5, Douglas B=
offey wrote:=20
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>I would like to see a rational class:<BR></DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>I was about to point out std::ratio, but then I realized it's compile =
time only, which is odd because I don't think it pre-dated constexpr. Is th=
ere a reason that template meta-programming was chosen over a constexpr/run=
time interface?</DIV></DIV></BLOCKQUOTE>
<DIV>&nbsp;</DIV>
<DIV>Eh?&nbsp; I don=E2=80=99t see anywhere in my posting where I=E2=80=99v=
e used&nbsp;TMP.&nbsp; Certainly, I have omitted any constexprs in my draft=
, just like I=E2=80=99ve not specified any exception specifications.</DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV style=3D"BORDER-BOTTOM: rgb(187,187,187) 1px solid; BORDER-LEFT: rgb(1=
87,187,187) 1px solid; BACKGROUND-COLOR: rgb(250,250,250); WORD-WRAP: break=
-word; BORDER-TOP: rgb(187,187,187) 1px solid; BORDER-RIGHT: rgb(187,187,18=
7) 1px solid"><CODE>
<DIV><SPAN style=3D"COLOR: #008">namespace</SPAN><SPAN style=3D"COLOR: #000=
"> std </SPAN><SPAN style=3D"COLOR: #660">{</SPAN><SPAN style=3D"COLOR: #00=
0"><BR>&nbsp; </SPAN><SPAN style=3D"COLOR: #008">template</SPAN><SPAN style=
=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">&lt;</SPAN><SPAN style=
=3D"COLOR: #008">typename</SPAN><SPAN style=3D"COLOR: #000"> T</SPAN><SPAN =
style=3D"COLOR: #660">&gt;</SPAN><SPAN style=3D"COLOR: #000"><BR>&nbsp; </S=
PAN><SPAN style=3D"COLOR: #008">class</SPAN><SPAN style=3D"COLOR: #000"> ra=
tional </SPAN><SPAN style=3D"COLOR: #660">{</SPAN></DIV></CODE></DIV></DIV>=
</BLOCKQUOTE>
<DIV><SPAN style=3D"FONT-SIZE: 13px"><BR></SPAN></DIV>
<DIV><SPAN style=3D"FONT-SIZE: 13px">Shouldn't the numerator and denominato=
r be separately typed?</SPAN></DIV></DIV></BLOCKQUOTE>
<DIV>&nbsp;</DIV>
<DIV>Possibly (mayby defaulted to <CODE><SPAN style=3D"COLOR: #008">typenam=
e</SPAN><SPAN style=3D"COLOR: #000"> make_unsigned</SPAN><SPAN style=3D"COL=
OR: #660">&lt;</SPAN><SPAN style=3D"COLOR: #000">T</SPAN><SPAN style=3D"COL=
OR: #660">&gt;::</SPAN><SPAN style=3D"COLOR: #000">type?</SPAN></CODE>)&nbs=
p; I would certainly object to a library where the numerator and denominato=
r were forced to be the same type (why would you want negative denominators=
?)</DIV></DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>Why not? Let's say I used this rational type to implement linear algeb=
ra functions. I might use "rational(x, y)" to represent the slope of a func=
tion. Or, maybe I want to write an inverse(x) function that returns rationa=
l(1, x). If the denominator can't be negative, the inverse would have to be=
 written like this:</DIV>
<DIV><BR></DIV>
<DIV>&nbsp; rational&lt;int&gt; inverse(int x) {</DIV>
<DIV>&nbsp; &nbsp; &nbsp; return <SPAN style=3D"FONT-SIZE: 13.33px">x &lt; =
0</SPAN><SPAN style=3D"FONT-SIZE: 13px">&nbsp;? {-1, (unsigned)-x} : {1, (u=
nsigned)x};</SPAN></DIV>
<DIV>&nbsp; &nbsp;}</DIV>
<DIV><BR></DIV>
<DIV>At least assuming rational keeps its non-explicit constructors.</DIV>
<DIV><BR></DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV style=3D"BORDER-BOTTOM: rgb(187,187,187) 1px solid; BORDER-LEFT: rgb(1=
87,187,187) 1px solid; BACKGROUND-COLOR: rgb(250,250,250); WORD-WRAP: break=
-word; BORDER-TOP: rgb(187,187,187) 1px solid; BORDER-RIGHT: rgb(187,187,18=
7) 1px solid"><CODE>
<DIV><SPAN style=3D"COLOR: #000"><BR>&nbsp; &nbsp; enable_if</SPAN><SPAN st=
yle=3D"COLOR: #660">&lt;</SPAN><SPAN style=3D"COLOR: #000">is_signed</SPAN>=
<SPAN style=3D"COLOR: #660">&lt;</SPAN><SPAN style=3D"COLOR: #000">T</SPAN>=
<SPAN style=3D"COLOR: #660">&gt;::</SPAN><SPAN style=3D"COLOR: #000">type</=
SPAN><SPAN style=3D"COLOR: #660">,</SPAN><SPAN style=3D"COLOR: #000"> ratio=
nal </SPAN><SPAN style=3D"COLOR: #008">operator</SPAN><SPAN style=3D"COLOR:=
 #660">-()&gt;;</SPAN></DIV></CODE></DIV></DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>Again, "is_signed&lt;T&gt;" might not make sense for all T's, though t=
he condition I have in mind is a little obtuse:</DIV>
<DIV><I>enable_if_t&lt;is_same&lt;decltype(-<WBR>num), numerator_type&gt;::=
value, rational&gt;</I></DIV></DIV></BLOCKQUOTE>
<DIV>&nbsp;</DIV>
<DIV>Should I have something like:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV style=3D"BORDER-BOTTOM: #bbb 1px solid; BORDER-LEFT: #bbb 1px solid; B=
ACKGROUND-COLOR: #fafafa; WORD-WRAP: break-word; BORDER-TOP: #bbb 1px solid=
; BORDER-RIGHT: #bbb 1px solid"><CODE>
<DIV><SPAN style=3D"COLOR: #008">auto</SPAN><SPAN style=3D"COLOR: #000"> </=
SPAN><SPAN style=3D"COLOR: #008">operator</SPAN><SPAN style=3D"COLOR: #660"=
>-()-&gt;</SPAN><SPAN style=3D"COLOR: #000">rational</SPAN><SPAN style=3D"C=
OLOR: #660">&lt;</SPAN><SPAN style=3D"COLOR: #008">decltype</SPAN><SPAN sty=
le=3D"COLOR: #660"><WBR>(-</SPAN><SPAN style=3D"COLOR: #000">num</SPAN><SPA=
N style=3D"COLOR: #660">),</SPAN><SPAN style=3D"COLOR: #000"> denominator_t=
ype</SPAN><SPAN style=3D"COLOR: #660">&gt;</SPAN></DIV></CODE></DIV></DIV><=
/BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>Not sure <I>what</I>&nbsp;the best practice would be here, but allowin=
g <I>-rational&lt;unsigned&gt;(x, y)</I> to have any type other than <I>rat=
ional&lt;unsigned&gt;</I> might be surprising to users. That's why I though=
t of <I>enable_if</I>.</DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV style=3D"BORDER-BOTTOM: #bbb 1px solid; BORDER-LEFT: #bbb 1px solid; B=
ACKGROUND-COLOR: #fafafa; WORD-WRAP: break-word; BORDER-TOP: #bbb 1px solid=
; BORDER-RIGHT: #bbb 1px solid"><CODE>
<DIV><SPAN style=3D"BACKGROUND-COLOR: white; FONT-FAMILY: Arial, Helvetica,=
 sans-serif; FONT-SIZE: 13px">&nbsp;</SPAN></DIV></CODE></DIV></DIV></BLOCK=
QUOTE>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV style=3D"BORDER-BOTTOM: rgb(187,187,187) 1px solid; BORDER-LEFT: rgb(1=
87,187,187) 1px solid; BACKGROUND-COLOR: rgb(250,250,250); WORD-WRAP: break=
-word; BORDER-TOP: rgb(187,187,187) 1px solid; BORDER-RIGHT: rgb(187,187,18=
7) 1px solid"><CODE>
<DIV><SPAN style=3D"COLOR: #000"><BR><BR>&nbsp; &nbsp; </SPAN><SPAN style=
=3D"COLOR: #800">// member accessors</SPAN><SPAN style=3D"COLOR: #000"><BR>=
&nbsp; &nbsp; numerator_type numerator</SPAN><SPAN style=3D"COLOR: #660">()=
</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #008">cons=
t</SPAN><SPAN style=3D"COLOR: #660">;</SPAN><SPAN style=3D"COLOR: #000"> </=
SPAN><SPAN style=3D"COLOR: #800">// Note: r-value</SPAN><SPAN style=3D"COLO=
R: #000"><BR>&nbsp; &nbsp; denominator_type denominator</SPAN><SPAN style=
=3D"COLOR: #660">()</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=
=3D"COLOR: #008">const</SPAN><SPAN style=3D"COLOR: #660">;</SPAN><SPAN styl=
e=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #800">// Nate: r-value</SPA=
N></DIV></CODE></DIV></DIV></BLOCKQUOTE></DIV></BLOCKQUOTE></DIV></BLOCKQUO=
TE>
<DIV><BR></DIV>
<DIV>I just realized this class doesn't offer a way to manually change/modi=
fy the numerator or denominator... (not a criticism, just observing.)</DIV>
<DIV><BR></DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr><BR></DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>Think any of the &lt;cmath&gt; functions should have an overload for t=
his? At the least, hypot comes to mind. You mentioned floor and ceil, but a=
s member functions. (They should be overloads.) Perhaps std::div as well.</=
DIV></DIV></BLOCKQUOTE>
<DIV>&nbsp;</DIV>
<DIV>What would std::div do?</DIV></DIV></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV>First, it would inverse multiply the two rationals, then return an std=
::div_t with the remainder and quotient. Though, I think when I wrote that,=
 I was considering std::div(rational(x, y)) being equivalent to std::div(x,=
 y).</DIV></DIV></BLOCKQUOTE>
<DIV>&nbsp;</DIV>
<DIV>By =E2=80=98inverse multiply=E2=80=99, do I take it you mean =E2=80=98=
divide=E2=80=99?</DIV>
<DIV>&nbsp;</DIV>
<DIV>I am not sure of the value of such a method.</DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE style=3D"BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex=
; PADDING-LEFT: 1ex" class=3Dgmail_quote>
<DIV dir=3Dltr>
<DIV>&nbsp;</DIV>
<DIV>Other functions that could be added are:</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV><CODE>
<DIV style=3D"BORDER-BOTTOM: #bbb 1px solid; BORDER-LEFT: #bbb 1px solid; B=
ACKGROUND-COLOR: #fafafa; WORD-WRAP: break-word; BORDER-TOP: #bbb 1px solid=
; BORDER-RIGHT: #bbb 1px solid"><SPAN style=3D"COLOR: #000">T round</SPAN><=
SPAN style=3D"COLOR: #660">()</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SP=
AN style=3D"COLOR: #008">const</SPAN><SPAN style=3D"COLOR: #660">;</SPAN><S=
PAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #800">// round to e=
ven &nbsp;</SPAN><SPAN style=3D"COLOR: #000">&nbsp;<BR>&nbsp; &nbsp;<BR></S=
PAN><SPAN style=3D"COLOR: #008">bool</SPAN><SPAN style=3D"COLOR: #000"> is_=
finite</SPAN><SPAN style=3D"COLOR: #660">()</SPAN><SPAN style=3D"COLOR: #00=
0"> </SPAN><SPAN style=3D"COLOR: #008">const</SPAN><SPAN style=3D"COLOR: #0=
00"> </SPAN><SPAN style=3D"COLOR: #660">{</SPAN><SPAN style=3D"COLOR: #008"=
>return</SPAN><SPAN style=3D"COLOR: #000"> den </SPAN><SPAN style=3D"COLOR:=
 #660">!=3D</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR:=
 #066">0</SPAN><SPAN style=3D"COLOR: #660">;</SPAN><SPAN style=3D"COLOR: #0=
00"> </SPAN><SPAN style=3D"COLOR: #660">}</SPAN><SPAN style=3D"COLOR: #000"=
> &nbsp;&nbsp;<BR></SPAN><SPAN style=3D"COLOR: #008">bool</SPAN><SPAN style=
=3D"COLOR: #000"> is_nan</SPAN><SPAN style=3D"COLOR: #660">()</SPAN><SPAN s=
tyle=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #008">const</SPAN><SPAN =
style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">{</SPAN><SPAN sty=
le=3D"COLOR: #008">return</SPAN><SPAN style=3D"COLOR: #000"> den </SPAN><SP=
AN style=3D"COLOR: #660">=3D=3D</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><=
SPAN style=3D"COLOR: #066">0</SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPA=
N style=3D"COLOR: #660">&amp;&amp;</SPAN><SPAN style=3D"COLOR: #000"> num <=
/SPAN><SPAN style=3D"COLOR: #660">=3D=3D</SPAN><SPAN style=3D"COLOR: #000">=
 </SPAN><SPAN style=3D"COLOR: #066">0</SPAN><SPAN style=3D"COLOR: #660">;</=
SPAN><SPAN style=3D"COLOR: #000"> </SPAN><SPAN style=3D"COLOR: #660">}</SPA=
N></DIV>
<DIV style=3D"BORDER-BOTTOM: #bbb 1px solid; BORDER-LEFT: #bbb 1px solid; B=
ACKGROUND-COLOR: #fafafa; WORD-WRAP: break-word; BORDER-TOP: #bbb 1px solid=
; BORDER-RIGHT: #bbb 1px solid"><BR>&nbsp;</DIV>
<DIV style=3D"BORDER-BOTTOM: #bbb 1px solid; BORDER-LEFT: #bbb 1px solid; B=
ACKGROUND-COLOR: #fafafa; WORD-WRAP: break-word; BORDER-TOP: #bbb 1px solid=
; BORDER-RIGHT: #bbb 1px solid">&nbsp;</DIV></CODE>
<DIV>given that I have specified representations for NaN and <FONT color=3D=
#000000 size=3D3 face=3Darial,sans-serif>=C2=B1=E2=88=9E</FONT>.</DIV>
<DIV>&nbsp;</DIV>
<DIV>I have specifically not followed boost::rational in including pre/post=
-inc/decrement operators, as they seem somewhat incongruous.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Doug.</DIV></DIV></BLOCKQUOTE></DIV></BLOCKQUOTE></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_3923_217420997.1423136033068--
------=_Part_3922_647184036.1423136033068--

.


Author: Farid Mehrabi <farid.mehrabi@gmail.com>
Date: Fri, 6 Feb 2015 23:26:06 +0330
Raw View
--001a1134cc4ee2bacc050e70d041
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

2015-02-01 6:14 GMT+03:30 Howard Hinnant <howard.hinnant@gmail.com>:

> On Jan 31, 2015, at 9:19 PM, Scott Prager <splinterofchaos@gmail.com>
> wrote:
>
> > I was about to point out std::ratio, but then I realized it's compile
> time only, which is odd because I don't think it pre-dated constexpr. Is
> there a reason that template meta-programming was chosen over a
> constexpr/runtime interface?
>
> http://stackoverflow.com/a/12326164/576911
> <http://stackoverflow.com/a/12326164/576911>
>
> I=E2=80=99m allergic to proposals without an implementation.
>
> Howard
>
> --
>
> False Positive. Just review boost::rational plz (boost is where std::rati=
o
came from too).

Regards,
FM.
--=20
how am I supposed to end the twisted road of  your hair in the dark night??
unless the candle of your face does turn a lamp up on my way!!!

--=20

---=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

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

<div dir=3D"rtl"><div style=3D"direction:ltr"><br></div><div class=3D"gmail=
_extra"><div style=3D"direction:ltr"><br></div><div class=3D"gmail_quote"><=
div dir=3D"ltr">2015-02-01 6:14 GMT+03:30 Howard Hinnant <span dir=3D"ltr">=
&lt;<a href=3D"mailto:howard.hinnant@gmail.com" target=3D"_blank">howard.hi=
nnant@gmail.com</a>&gt;</span>:</div><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div st=
yle=3D"direction:ltr">On Jan 31, 2015, at 9:19 PM, Scott Prager &lt;<a href=
=3D"mailto:splinterofchaos@gmail.com">splinterofchaos@gmail.com</a>&gt; wro=
te:</div><span class=3D""><div style=3D"direction:ltr"><br></div>
<div style=3D"direction:ltr">&gt; I was about to point out std::ratio, but =
then I realized it&#39;s compile time only, which is odd because I don&#39;=
t think it pre-dated constexpr. Is there a reason that template meta-progra=
mming was chosen over a constexpr/runtime interface?</div>
<div style=3D"direction:ltr"><br></div>
</span><div style=3D"direction:ltr"><a href=3D"http://stackoverflow.com/a/1=
2326164/576911" target=3D"_blank">http://stackoverflow.com/a/12326164/57691=
1</a><a href=3D"http://stackoverflow.com/a/12326164/576911" target=3D"_blan=
k"><br></a></div>
<div style=3D"direction:ltr"><br></div><div style=3D"direction:ltr">I=E2=80=
=99m allergic to proposals without an implementation.</div>
<span class=3D"HOEnZb"><div style=3D"direction:ltr"><font color=3D"#888888"=
><br></font></div><font color=3D"#888888"><div style=3D"direction:ltr">Howa=
rd</div>
</font></span><div class=3D"HOEnZb"><div class=3D"h5"><div style=3D"directi=
on:ltr"><br></div><div style=3D"direction:ltr">--</div>
<div style=3D"direction:ltr"><br></div></div></div></blockquote><div dir=3D=
"ltr">False Positive. Just review boost::rational plz (boost is where std::=
ratio came from too).</div><div dir=3D"ltr"><br></div><div dir=3D"ltr">Rega=
rds,</div><div dir=3D"ltr">FM.</div></div><div style=3D"direction:ltr">--=
=C2=A0</div><div class=3D"gmail_signature"><div dir=3D"ltr">how am I suppos=
ed to end the twisted road of=C2=A0 your hair in the dark night??<br>unless=
 the candle of your face does turn a lamp up on my way!!!<br></div></div>
</div></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--001a1134cc4ee2bacc050e70d041--

.


Author: Howard Hinnant <howard.hinnant@gmail.com>
Date: Fri, 6 Feb 2015 15:18:17 -0500
Raw View
On Feb 6, 2015, at 2:56 PM, Farid Mehrabi <farid.mehrabi@gmail.com> wrote:

> boost is where std::ratio came from too

See:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm#ratio

which says in part:

> ratio is a general purpose utility inspired by Walter Brown allowing one to easily and safely compute rational values at compile time.

When I wrote those words a little prior to 2008-06-11, boost::ratio did not exist.  boost::ratio was created from the example implementation I created.  I derived ratio from this 2001 paper by Walter Brown:

http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.18.3195&rep=rep1&type=pdf

I.e. in this case, boost::ratio came from std::ratio (at least a proposal for it andr the draft C++0X spec), which in turn came from Walter Brown.

Howard

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: "Vicente J. Botet Escriba" <vicente.botet@wanadoo.fr>
Date: Sat, 07 Feb 2015 08:52:47 +0100
Raw View
Le 06/02/15 21:18, Howard Hinnant a =C3=A9crit :
> On Feb 6, 2015, at 2:56 PM, Farid Mehrabi <farid.mehrabi@gmail.com> wrote=
:
>
>> boost is where std::ratio came from too
> See:
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm#ratio
>
> which says in part:
>
>> ratio is a general purpose utility inspired by Walter Brown allowing one=
 to easily and safely compute rational values at compile time.
> When I wrote those words a little prior to 2008-06-11, boost::ratio did n=
ot exist.  boost::ratio was created from the example implementation I creat=
ed.  I derived ratio from this 2001 paper by Walter Brown:
>
> http://citeseerx.ist.psu.edu/viewdoc/download?doi=3D10.1.1.18.3195&rep=3D=
rep1&type=3Dpdf
>
> I.e. in this case, boost::ratio came from std::ratio (at least a proposal=
 for it andr the draft C++0X spec), which in turn came from Walter Brown.
>
> Howard
>
Howard is right. Boost.Ratio was extracted by myself from the port to=20
Boost of the standard chrono library done by Beman (surely based on the=20
implementation of Howard).

Best,
Vicente

--=20

---=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

.


Author: "beman.dawes" <beman.dawes@gmail.com>
Date: Wed, 11 Feb 2015 18:39:54 -0800 (PST)
Raw View
------=_Part_1289_897349291.1423708795057
Content-Type: multipart/alternative;
 boundary="----=_Part_1290_2119364603.1423708795057"

------=_Part_1290_2119364603.1423708795057
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable



On Saturday, February 7, 2015 at 2:52:48 AM UTC-5, Vicente J. Botet Escriba=
=20
wrote:
>
> Le 06/02/15 21:18, Howard Hinnant a =C3=A9crit :=20
> > On Feb 6, 2015, at 2:56 PM, Farid Mehrabi <farid....@gmail.com=20
> <javascript:>> wrote:=20
> >=20
> >> boost is where std::ratio came from too=20
> > See:=20
> >=20
> > http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm#ratio=
=20
> >=20
> > which says in part:=20
> >=20
> >> ratio is a general purpose utility inspired by Walter Brown allowing=
=20
> one to easily and safely compute rational values at compile time.=20
> > When I wrote those words a little prior to 2008-06-11, boost::ratio did=
=20
> not exist.  boost::ratio was created from the example implementation I=20
> created.  I derived ratio from this 2001 paper by Walter Brown:=20
> >=20
> >=20
> http://citeseerx.ist.psu.edu/viewdoc/download?doi=3D10.1.1.18.3195&rep=3D=
rep1&type=3Dpdf=20
> >=20
> > I.e. in this case, boost::ratio came from std::ratio (at least a=20
> proposal for it andr the draft C++0X spec), which in turn came from Walte=
r=20
> Brown.=20
> >=20
> > Howard=20
> >=20
> Howard is right. Boost.Ratio was extracted by myself from the port to=20
> Boost of the standard chrono library done by Beman (surely based on the=
=20
> implementation of Howard).=20
>

Yes, exactly.

--Beman=20
=20

--=20

---=20
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 e=
mail to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposa=
ls/.

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

<div dir=3D"ltr"><br><br>On Saturday, February 7, 2015 at 2:52:48 AM UTC-5,=
 Vicente J. Botet Escriba wrote:<blockquote class=3D"gmail_quote" style=3D"=
margin: 0;margin-left: 0.8ex;border-left: 1px #ccc solid;padding-left: 1ex;=
">Le 06/02/15 21:18, Howard Hinnant a =C3=A9crit :
<br>&gt; On Feb 6, 2015, at 2:56 PM, Farid Mehrabi &lt;<a href=3D"javascrip=
t:" target=3D"_blank" gdf-obfuscated-mailto=3D"X-p_oZZduKQJ" rel=3D"nofollo=
w" onmousedown=3D"this.href=3D'javascript:';return true;" onclick=3D"this.h=
ref=3D'javascript:';return true;">farid....@gmail.com</a>&gt; wrote:
<br>&gt;
<br>&gt;&gt; boost is where std::ratio came from too
<br>&gt; See:
<br>&gt;
<br>&gt; <a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008=
/n2661.htm#ratio" target=3D"_blank" rel=3D"nofollow" onmousedown=3D"this.hr=
ef=3D'http://www.google.com/url?q\75http%3A%2F%2Fwww.open-std.org%2Fjtc1%2F=
sc22%2Fwg21%2Fdocs%2Fpapers%2F2008%2Fn2661.htm%23ratio\46sa\75D\46sntz\0751=
\46usg\75AFQjCNE0knZiJtXXh58gaP9Pw_qB2k870w';return true;" onclick=3D"this.=
href=3D'http://www.google.com/url?q\75http%3A%2F%2Fwww.open-std.org%2Fjtc1%=
2Fsc22%2Fwg21%2Fdocs%2Fpapers%2F2008%2Fn2661.htm%23ratio\46sa\75D\46sntz\07=
51\46usg\75AFQjCNE0knZiJtXXh58gaP9Pw_qB2k870w';return true;">http://www.ope=
n-std.org/jtc1/<wbr>sc22/wg21/docs/papers/2008/<wbr>n2661.htm#ratio</a>
<br>&gt;
<br>&gt; which says in part:
<br>&gt;
<br>&gt;&gt; ratio is a general purpose utility inspired by Walter Brown al=
lowing one to easily and safely compute rational values at compile time.
<br>&gt; When I wrote those words a little prior to 2008-06-11, boost::rati=
o did not exist. &nbsp;boost::ratio was created from the example implementa=
tion I created. &nbsp;I derived ratio from this 2001 paper by Walter Brown:
<br>&gt;
<br>&gt; <a href=3D"http://citeseerx.ist.psu.edu/viewdoc/download?doi=3D10.=
1.1.18.3195&amp;rep=3Drep1&amp;type=3Dpdf" target=3D"_blank" rel=3D"nofollo=
w" onmousedown=3D"this.href=3D'http://www.google.com/url?q\75http%3A%2F%2Fc=
iteseerx.ist.psu.edu%2Fviewdoc%2Fdownload%3Fdoi%3D10.1.1.18.3195%26rep%3Dre=
p1%26type%3Dpdf\46sa\75D\46sntz\0751\46usg\75AFQjCNH55E0fNxMhz-kTXZpUcQqxEv=
ZGhQ';return true;" onclick=3D"this.href=3D'http://www.google.com/url?q\75h=
ttp%3A%2F%2Fciteseerx.ist.psu.edu%2Fviewdoc%2Fdownload%3Fdoi%3D10.1.1.18.31=
95%26rep%3Drep1%26type%3Dpdf\46sa\75D\46sntz\0751\46usg\75AFQjCNH55E0fNxMhz=
-kTXZpUcQqxEvZGhQ';return true;">http://citeseerx.ist.psu.edu/<wbr>viewdoc/=
download?doi=3D10.1.1.<wbr>18.3195&amp;rep=3Drep1&amp;type=3Dpdf</a>
<br>&gt;
<br>&gt; I.e. in this case, boost::ratio came from std::ratio (at least a p=
roposal for it andr the draft C++0X spec), which in turn came from Walter B=
rown.
<br>&gt;
<br>&gt; Howard
<br>&gt;
<br>Howard is right. Boost.Ratio was extracted by myself from the port to=
=20
<br>Boost of the standard chrono library done by Beman (surely based on the=
=20
<br>implementation of Howard).
<br></blockquote><div><br>Yes, exactly.<br><br>--Beman <br></div><div>&nbsp=
;</div></div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

------=_Part_1290_2119364603.1423708795057--
------=_Part_1289_897349291.1423708795057--

.


Author: Farid Mehrabi <farid.mehrabi@gmail.com>
Date: Fri, 13 Feb 2015 16:51:38 +0330
Raw View
--089e0102f2121cef2f050ef81f99
Content-Type: text/plain; charset=UTF-8

thanks a lot for the correction. Interesting to know

2015-02-06 23:48 GMT+03:30 Howard Hinnant <howard.hinnant@gmail.com>:

> On Feb 6, 2015, at 2:56 PM, Farid Mehrabi <farid.mehrabi@gmail.com> wrote:
>
> > boost is where std::ratio came from too
>
> See:
>
> http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.htm#ratio
>
> which says in part:
>
> > ratio is a general purpose utility inspired by Walter Brown allowing one
> to easily and safely compute rational values at compile time.
>
> When I wrote those words a little prior to 2008-06-11, boost::ratio did
> not exist.  boost::ratio was created from the example implementation I
> created.  I derived ratio from this 2001 paper by Walter Brown:
>
>
> http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.18.3195&rep=rep1&type=pdf
>
> I.e. in this case, boost::ratio came from std::ratio (at least a proposal
> for it andr the draft C++0X spec), which in turn came from Walter Brown.
>
> Howard
>
> --
>
> ---
> 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.
> Visit this group at
> http://groups.google.com/a/isocpp.org/group/std-proposals/.
>



--
how am I supposed to end the twisted road of  your hair in the dark night??
unless the candle of your face does turn a lamp up on my way!!!

--

---
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.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

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

<div dir=3D"rtl"><div dir=3D"ltr">thanks a lot for the correction. Interest=
ing to know</div></div><div class=3D"gmail_extra"><br><div class=3D"gmail_q=
uote"><div dir=3D"ltr">2015-02-06 23:48 GMT+03:30 Howard Hinnant <span dir=
=3D"ltr">&lt;<a href=3D"mailto:howard.hinnant@gmail.com" target=3D"_blank">=
howard.hinnant@gmail.com</a>&gt;</span>:</div><blockquote class=3D"gmail_qu=
ote" style=3D"margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex=
"><span class=3D"">On Feb 6, 2015, at 2:56 PM, Farid Mehrabi &lt;<a href=3D=
"mailto:farid.mehrabi@gmail.com">farid.mehrabi@gmail.com</a>&gt; wrote:<br>
<br>
&gt; boost is where std::ratio came from too<br>
<br>
</span>See:<br>
<br>
<a href=3D"http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2661.ht=
m#ratio" target=3D"_blank">http://www.open-std.org/jtc1/sc22/wg21/docs/pape=
rs/2008/n2661.htm#ratio</a><br>
<br>
which says in part:<br>
<br>
&gt; ratio is a general purpose utility inspired by Walter Brown allowing o=
ne to easily and safely compute rational values at compile time.<br>
<br>
When I wrote those words a little prior to 2008-06-11, boost::ratio did not=
 exist.=C2=A0 boost::ratio was created from the example implementation I cr=
eated.=C2=A0 I derived ratio from this 2001 paper by Walter Brown:<br>
<br>
<a href=3D"http://citeseerx.ist.psu.edu/viewdoc/download?doi=3D10.1.1.18.31=
95&amp;rep=3Drep1&amp;type=3Dpdf" target=3D"_blank">http://citeseerx.ist.ps=
u.edu/viewdoc/download?doi=3D10.1.1.18.3195&amp;rep=3Drep1&amp;type=3Dpdf</=
a><br>
<br>
I.e. in this case, boost::ratio came from std::ratio (at least a proposal f=
or it andr the draft C++0X spec), which in turn came from Walter Brown.<br>
<div class=3D"HOEnZb"><div class=3D"h5"><br>
Howard<br>
<br>
--<br>
<br>
---<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%2Bunsubscribe@isocpp.org">std-propo=
sals+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>
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/" target=3D"_blank">http://groups.google.com/a/isocpp.org/gro=
up/std-proposals/</a>.<br>
</div></div></blockquote></div><br><br clear=3D"all"><div><br></div>-- <br>=
<div class=3D"gmail_signature"><div dir=3D"ltr">how am I supposed to end th=
e twisted road of=C2=A0 your hair in the dark night??<br>unless the candle =
of your face does turn a lamp up on my way!!!<br></div></div>
</div>

<p></p>

-- <br />
<br />
--- <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 />
Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/group/=
std-proposals/">http://groups.google.com/a/isocpp.org/group/std-proposals/<=
/a>.<br />

--089e0102f2121cef2f050ef81f99--

.