Topic: a safe integer library


Author: Robert Ramey <ramey@rrsd.com>
Date: Wed, 9 Dec 2015 23:44:50 -0800
Raw View
Arithmetic operations in C++ are NOT guaranteed to yield a correct
mathematical result. This feature is inherited from the early days of C.
The behavior of int, unsigned int and others were designed to map
closely to the underlying hardware. Computer hardware implements these
types as a fixed number of bits. When the result of arithmetic
operations exceeds this number of bits, the result will not be
arithmetically correct.

I have crafted a library to address this issue once and for all. You can
find out more about this by checking out the page for Safe Numerics at
the boost library incubator. www.blincubator.com

I've also made a proposal for the C++ Standards committee to include a
simplified version of this library as part of he C++ standard.

You can see the proposal at
http://www.rrsd.com/software_development/safe_numerics/proposal.pdf

Robert Ramey

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: "dgutson ." <danielgutson@gmail.com>
Date: Thu, 10 Dec 2015 09:14:30 -0300
Raw View
El 10/12/2015 4:50, "Robert Ramey" <ramey@rrsd.com> escribi=C3=B3:
>
> Arithmetic operations in C++ are NOT guaranteed to yield a correct mathem=
atical result. This feature is inherited from the early days of C. The beha=
vior of int, unsigned int and others were designed to map closely to the un=
derlying hardware. Computer hardware implements these types as a fixed numb=
er of bits. When the result of arithmetic operations exceeds this number of=
 bits, the result will not be arithmetically correct.
>
> I have crafted a library to address this issue once and for all. You can =
find out more about this by checking out the page for Safe Numerics at the =
boost library incubator. www.blincubator.com
>
> I've also made a proposal for the C++ Standards committee to include a si=
mplified version of this library as part of he C++ standard.
>
> You can see the proposal at http://www.rrsd.com/software_development/safe=
_numerics/proposal.pdf

IIUC, this library proposal (as other similar libraries) is
per-operation oriented, rather than per-expression.

For example: consider a*b/c, which can be solved as:
  (a*b)/c, (a/c)*b, a*(c/b), a/(c/b), b/(c/b)

Depending on the values of a, b and c, one of the expressions is the
most suitablt.
Moreover, transformations can take place by considering the remainder
by dividing by  C, we can write for example
   a =3D x * c + r
so
   (x*c + r )/c * b =3D x * b + r * b / c
and a recursive function can be provided.

Sorry about the lengthy example, I just want to point out that a very
simple expression gets complicated to get a good result, something
usually impossible when considering isolated operations.

That being said, I think that no matter how elegant this proposal can
be regarding operations, but the real problem is still not
definitively solved without considering the whole expression, which
provides a better solution. And the implementation that comes to my
mind is an expression template approach which is able to consider the
whole expression and make transformations/decisions (such as the
remainder trick).

I would really like to see a complete solution for real life examples,
which are not just one operation.

That, and the ability to specify saturation/wraparound behavior.

   Daniel.

>
> Robert Ramey
>
> --
>
> --- You received this message because you are subscribed to the Google Gr=
oups "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-propo=
sals/.

--=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: "dgutson ." <danielgutson@gmail.com>
Date: Thu, 10 Dec 2015 09:16:06 -0300
Raw View
Errata :)

On Thu, Dec 10, 2015 at 9:14 AM, dgutson . <danielgutson@gmail.com> wrote:
> El 10/12/2015 4:50, "Robert Ramey" <ramey@rrsd.com> escribi=C3=B3:
>>
>> Arithmetic operations in C++ are NOT guaranteed to yield a correct mathe=
matical result. This feature is inherited from the early days of C. The beh=
avior of int, unsigned int and others were designed to map closely to the u=
nderlying hardware. Computer hardware implements these types as a fixed num=
ber of bits. When the result of arithmetic operations exceeds this number o=
f bits, the result will not be arithmetically correct.
>>
>> I have crafted a library to address this issue once and for all. You can=
 find out more about this by checking out the page for Safe Numerics at the=
 boost library incubator. www.blincubator.com
>>
>> I've also made a proposal for the C++ Standards committee to include a s=
implified version of this library as part of he C++ standard.
>>
>> You can see the proposal at http://www.rrsd.com/software_development/saf=
e_numerics/proposal.pdf
>
> IIUC, this library proposal (as other similar libraries) is
> per-operation oriented, rather than per-expression.
>
> For example: consider a*b/c, which can be solved as:
>   (a*b)/c, (a/c)*b, a*(c/b), a/(c/b), b/(c/b)

(a*b)/c,  (a/c)*b,  a*(b/c), a/(c/b), b/(c/a)

>
> Depending on the values of a, b and c, one of the expressions is the
> most suitablt.
> Moreover, transformations can take place by considering the remainder
> by dividing by  C, we can write for example
>    a =3D x * c + r
> so
>    (x*c + r )/c * b =3D x * b + r * b / c
> and a recursive function can be provided.
>
> Sorry about the lengthy example, I just want to point out that a very
> simple expression gets complicated to get a good result, something
> usually impossible when considering isolated operations.
>
> That being said, I think that no matter how elegant this proposal can
> be regarding operations, but the real problem is still not
> definitively solved without considering the whole expression, which
> provides a better solution. And the implementation that comes to my
> mind is an expression template approach which is able to consider the
> whole expression and make transformations/decisions (such as the
> remainder trick).
>
> I would really like to see a complete solution for real life examples,
> which are not just one operation.
>
> That, and the ability to specify saturation/wraparound behavior.
>
>    Daniel.
>
>>
>> Robert Ramey
>>
>> --
>>
>> --- You received this message because you are subscribed to the Google G=
roups "ISO C++ Standard - Future Proposals" group.
>> To unsubscribe from this group and stop receiving emails from it, send a=
n 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-prop=
osals/.



--=20
Who=E2=80=99s got the sweetest disposition?
One guess, that=E2=80=99s who?
Who=E2=80=99d never, ever start an argument?
Who never shows a bit of temperament?
Who's never wrong but always right?
Who'd never dream of starting a fight?
Who get stuck with all the bad luck?

--=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: Robert Ramey <ramey@rrsd.com>
Date: Thu, 10 Dec 2015 09:34:40 -0800
Raw View
On 12/10/15 4:14 AM, dgutson . wrote:
> Depending on the values of a, b and c, one of the expressions is the
> most suitablt.
> Moreover, transformations can take place by considering the remainder
> by dividing by  C, we can write for example
>     a = x * c + r
> so
>     (x*c + r )/c * b = x * b + r * b / c
> and a recursive function can be provided.

C++ places this decision into the hands of the user/programmer - for
good reason.  This library doesn't change this.  That would be different
library designed to address a different problem.

> Sorry about the lengthy example, I just want to point out that a very
> simple expression gets complicated to get a good result, something
> usually impossible when considering isolated operations.

> I would really like to see a complete solution for real life examples,
> which are not just one operation.

since the library is intended as drop in replacement for built in
integer types, feel free to take program you want to try and and change
it to use the library - should be as simple as a global replace

> That, and the ability to specify saturation/wraparound behavior.

The (more elaborate superset) library at www.blincubator.com includes
policy classes to permit customization of the behavior in these cases.
Including such facilities in an officially sanctioned C++ standard
library would be a significant departure from traditional practice,
would add more complexity than many people want, and increase the scope
and scale required for vendors to implement the library.

If you actually need and/or want such a facility, you can use the
library at www.blincubator.com which includes all these facilities (and
more) and has been submitted for review to boost.

Robert Ramey


--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-proposals@isocpp.org.
Visit this group at http://groups.google.com/a/isocpp.org/group/std-proposals/.

.


Author: "dgutson ." <danielgutson@gmail.com>
Date: Thu, 10 Dec 2015 18:30:18 -0300
Raw View
--001a1142789ed17289052691e992
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

El 10/12/2015 14:34, "Robert Ramey" <ramey@rrsd.com> escribi=C3=B3:
>
> On 12/10/15 4:14 AM, dgutson . wrote:
>>
>> Depending on the values of a, b and c, one of the expressions is the
>> most suitablt.
>> Moreover, transformations can take place by considering the remainder
>> by dividing by  C, we can write for example
>>     a =3D x * c + r
>> so
>>     (x*c + r )/c * b =3D x * b + r * b / c
>> and a recursive function can be provided.
>
>
> C++ places this decision into the hands of the user/programmer - for good
reason.  This library doesn't change this.  That would be different library
designed to address a different problem.

That is the key point I want to highlight.
I don't see the usefulness of a SafeInt library which takes pieces of
operations making no sense if the whole is not considering: a*b may not
overflow if /c is considered, that's why I think that a SafeExpressions
library should be the real solution.

>
>
>> Sorry about the lengthy example, I just want to point out that a very
>> simple expression gets complicated to get a good result, something
>> usually impossible when considering isolated operations.
>
>
>> I would really like to see a complete solution for real life examples,
>> which are not just one operation.
>
>
> since the library is intended as drop in replacement for built in integer
types, feel free to take program you want to try and and change it to use
the library - should be as simple as a global replace
>
>
>> That, and the ability to specify saturation/wraparound behavior.
>
>
> The (more elaborate superset) library at www.blincubator.com includes
policy classes to permit customization of the behavior in these cases.
Including such facilities in an officially sanctioned C++ standard library
would be a significant departure from traditional practice, would add more
complexity than many people want, and increase the scope and scale required
for vendors to implement the library.
>
> If you actually need and/or want such a facility, you can use the library
at www.blincubator.com which includes all these facilities (and more) and
has been submitted for review to boost.
>
>
> Robert Ramey
>
>
> --
>
> --- You received this message because you are subscribed to the Google
Groups "ISO C++ Standard - Future Proposals" group.
> To unsubscribe from this group and stop receiving emails from it, send an
email to std-proposals+unsubscribe@isocpp.org.
> To post to this group, send email to std-proposals@isocpp.org.
> 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/.

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

<p dir=3D"ltr"><br>
El 10/12/2015 14:34, &quot;Robert Ramey&quot; &lt;<a href=3D"mailto:ramey@r=
rsd.com">ramey@rrsd.com</a>&gt; escribi=C3=B3:<br>
&gt;<br>
&gt; On 12/10/15 4:14 AM, dgutson . wrote:<br>
&gt;&gt;<br>
&gt;&gt; Depending on the values of a, b and c, one of the expressions is t=
he<br>
&gt;&gt; most suitablt.<br>
&gt;&gt; Moreover, transformations can take place by considering the remain=
der<br>
&gt;&gt; by dividing by=C2=A0 C, we can write for example<br>
&gt;&gt; =C2=A0 =C2=A0 a =3D x * c + r<br>
&gt;&gt; so<br>
&gt;&gt; =C2=A0 =C2=A0 (x*c + r )/c * b =3D x * b + r * b / c<br>
&gt;&gt; and a recursive function can be provided.<br>
&gt;<br>
&gt;<br>
&gt; C++ places this decision into the hands of the user/programmer - for g=
ood reason.=C2=A0 This library doesn&#39;t change this.=C2=A0 That would be=
 different library designed to address a different problem.</p>
<p dir=3D"ltr">That is the key point I want to highlight.<br>
I don&#39;t see the usefulness of a SafeInt library which takes pieces of o=
perations making no sense if the whole is not considering: a*b may not over=
flow if /c is considered, that&#39;s why I think that a SafeExpressions lib=
rary should be the real solution.</p>
<p dir=3D"ltr">&gt;<br>
&gt;<br>
&gt;&gt; Sorry about the lengthy example, I just want to point out that a v=
ery<br>
&gt;&gt; simple expression gets complicated to get a good result, something=
<br>
&gt;&gt; usually impossible when considering isolated operations.<br>
&gt;<br>
&gt;<br>
&gt;&gt; I would really like to see a complete solution for real life examp=
les,<br>
&gt;&gt; which are not just one operation.<br>
&gt;<br>
&gt;<br>
&gt; since the library is intended as drop in replacement for built in inte=
ger types, feel free to take program you want to try and and change it to u=
se the library - should be as simple as a global replace<br>
&gt;<br>
&gt;<br>
&gt;&gt; That, and the ability to specify saturation/wraparound behavior.<b=
r>
&gt;<br>
&gt;<br>
&gt; The (more elaborate superset) library at <a href=3D"http://www.blincub=
ator.com">www.blincubator.com</a> includes policy classes to permit customi=
zation of the behavior in these cases. Including such facilities in an offi=
cially sanctioned C++ standard library would be a significant departure fro=
m traditional practice, would add more complexity than many people want, an=
d increase the scope and scale required for vendors to implement the librar=
y.<br>
&gt;<br>
&gt; If you actually need and/or want such a facility, you can use the libr=
ary at <a href=3D"http://www.blincubator.com">www.blincubator.com</a> which=
 includes all these facilities (and more) and has been submitted for review=
 to boost.<br>
&gt;<br>
&gt;<br>
&gt; Robert Ramey<br>
&gt;<br>
&gt;<br>
&gt; -- <br>
&gt;<br>
&gt; --- You received this message because you are subscribed to the Google=
 Groups &quot;ISO C++ Standard - Future Proposals&quot; group.<br>
&gt; To unsubscribe from this group and stop receiving emails from it, send=
 an email to <a href=3D"mailto:std-proposals%2Bunsubscribe@isocpp.org">std-=
proposals+unsubscribe@isocpp.org</a>.<br>
&gt; To post to this group, send email to <a href=3D"mailto:std-proposals@i=
socpp.org">std-proposals@isocpp.org</a>.<br>
&gt; Visit this group at <a href=3D"http://groups.google.com/a/isocpp.org/g=
roup/std-proposals/">http://groups.google.com/a/isocpp.org/group/std-propos=
als/</a>.<br>
</p>

<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 />

--001a1142789ed17289052691e992--

.