Boost logo

Boost :

Subject: Re: [boost] a safe integer library
From: Matt Hurd (matthurd_at_[hidden])
Date: 2015-12-17 04:43:16


On 17 December 2015 at 19:12, Robert Ramey <ramey_at_[hidden]> wrote:

> On 12/16/15 11:16 PM, David Stone wrote:
>
>> I have written a similar library (http://doublewise.net/c++/bounded/),
>> and
>> I have a few questions about your implementation.
>>
>
> I'm very aware of this. I attended your excellent presentation of you
> bounded integer library at C++Now 2014. I've also referenced your library
> in the documentation for safe_numeric. I was working on the safe numeric
> library at the time so that's why I was interested.

Great initiatives!

I've been thinking about both approaches, especially with a view to
translating a safe language for kids. I can see two good use cases: using
both a particular integer type [Robert?], and using a minimal type from a
set of possible [David?] (e.g. set of: fast; aligned; all/size minimal).
Reminds me a little of Pascal's integer ranges with modern machinery.

Indefinite loops and subtracting unsigned values are particular breakages
with performance concerns that I can't see being addressed without run-time
overhead, but perhaps those casts, at the coupling points, can be debug
only on request?

My preference for lib/policy would certainly be for zero run-time overhead
unless cast but I can imagine many would be happy with continual run-time
checks.

Having no exceptions would be a requirement for most of my use cases. One
alternate way I've thought of dealing with that is by having a sentinel or
NaN for integers, which might be a thought worth considering that I don't
think I've seen elsewhere, but it might not help much if it becomes an
awkward run-time precondition instead of a type. David's saturation idea
might be a +/- INF sentinel too and perhaps helpful for physical units.

It would be nice to see a decimal precision type integer (which I used a
lot, e.g. cents or 0.0001 precision) or fixed point extensions or
accommodations as these also repurpose integers, such as Robert's
safe<money> suggestion. Those types would also be greatly enhanced by
having the same wonderful range benefits. Combined with units, you might
just save a few red-faces, satellites, or lives with non-stupid financial
and physical ranges :-)

$0.02,

--Matt.


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