Re: Do you like bounded integrals?

2016-08-30 Thread tsbockman via Digitalmars-d
On Tuesday, 30 August 2016 at 14:58:16 UTC, Chris Wright wrote: We can only track types, not values, and that strongly hampers our ability to reduce ranges. Playing with some examples, I think the real issue is that precise bounds tracking requires analyzing the formula as a whole, rather

Re: Do you like bounded integrals?

2016-08-30 Thread tsbockman via Digitalmars-d
On Tuesday, 30 August 2016 at 14:58:16 UTC, Chris Wright wrote: On Tue, 30 Aug 2016 13:24:04 +, tsbockman wrote: Ranges don't always grow. Some operations will also cause them to shrink, if they're really being tracked correctly: We can only track types, not values, and that strongly

Re: Do you like bounded integrals?

2016-08-30 Thread Chris Wright via Digitalmars-d
On Tue, 30 Aug 2016 13:24:04 +, tsbockman wrote: > On Tuesday, 30 August 2016 at 03:37:06 UTC, Chris Wright wrote: >> On Mon, 29 Aug 2016 18:20:05 +, tsbockman wrote: >>> They should. Generally speaking, if that doesn't produce reasonable >>> bounds (leaving aside rounding errors) at the

Re: Do you like bounded integrals?

2016-08-30 Thread Andrei Alexandrescu via Digitalmars-d
On 08/29/2016 11:37 PM, Chris Wright wrote: On Mon, 29 Aug 2016 18:20:05 +, tsbockman wrote: On Tuesday, 23 August 2016 at 20:40:06 UTC, Andrei Alexandrescu wrote: When composing, do the limits compose meaningfully? They should. Generally speaking, if that doesn't produce reasonable

Re: Do you like bounded integrals?

2016-08-30 Thread tsbockman via Digitalmars-d
On Tuesday, 30 August 2016 at 03:37:06 UTC, Chris Wright wrote: On Mon, 29 Aug 2016 18:20:05 +, tsbockman wrote: They should. Generally speaking, if that doesn't produce reasonable bounds (leaving aside rounding errors) at the end of the computation, it means that the logic of the

Re: Do you like bounded integrals?

2016-08-29 Thread Chris Wright via Digitalmars-d
On Mon, 29 Aug 2016 18:20:05 +, tsbockman wrote: > On Tuesday, 23 August 2016 at 20:40:06 UTC, Andrei Alexandrescu wrote: >> When composing, do the limits compose meaningfully? > > They should. Generally speaking, if that doesn't produce reasonable > bounds (leaving aside rounding errors) at

Re: Do you like bounded integrals?

2016-08-29 Thread tsbockman via Digitalmars-d
On Tuesday, 23 August 2016 at 20:40:06 UTC, Andrei Alexandrescu wrote: When composing, do the limits compose meaningfully? They should. Generally speaking, if that doesn't produce reasonable bounds (leaving aside rounding errors) at the end of the computation, it means that the logic of the

Re: Do you like bounded integrals?

2016-08-29 Thread Andrei Alexandrescu via Digitalmars-d
On 08/29/2016 11:33 AM, Marco Leise wrote: The following could make it more accessible, much like the two Exception constructors we have: alias CheckedInt(T, T min, T max, Hook = Abort) = CheckedIntImpl!(T, Hook, min, max); alias CheckedInt(T, Hook = Abort) = CheckedIntImpl!(T,

Re: Do you like bounded integrals?

2016-08-29 Thread Marco Leise via Digitalmars-d
Am Tue, 23 Aug 2016 16:40:06 -0400 schrieb Andrei Alexandrescu : > Currently checkedint (https://github.com/dlang/phobos/pull/4613) stands > at 2432 lines and implements a variety of checking behaviors. At this > point I just figured I can very easily add custom

Re: Do you like bounded integrals?

2016-08-25 Thread Andrei Alexandrescu via Digitalmars-d
Update: I've taken a shot at adding bounds, see https://github.com/dlang/phobos/pull/4613/commits/bbdcea723e3dd98a979ae3f06a6786645647a778. Here are a few notes: * The Hook API works nicely with built-in or custom hooks, so no change there was necessary. * The constructor got quite a bit

Re: Do you like bounded integrals?

2016-08-24 Thread Bill Hicks via Digitalmars-d
On Tuesday, 23 August 2016 at 20:40:06 UTC, Andrei Alexandrescu wrote: Currently checkedint (https://github.com/dlang/phobos/pull/4613) stands at 2432 lines and implements a variety of checking behaviors. At this point I just figured I can very easily add custom bounds, e.g. an int limited to

Re: Do you like bounded integrals?

2016-08-24 Thread Robert burner Schadek via Digitalmars-d
what about two types. alias BI = Bound!int; alias CBI = CheckedInt!BI; if Bound behaves as an integer people can choose.

Re: Do you like bounded integrals?

2016-08-24 Thread Andrei Alexandrescu via Digitalmars-d
On 08/24/2016 05:05 AM, Lodovico Giaretta wrote: On Wednesday, 24 August 2016 at 00:40:15 UTC, Andrei Alexandrescu wrote: That wouldn't work for e.g. NaN. A NaN wants to "steal" a value but only if that's not available. It's complicated. Ok, I get your point. WithNaN should not waste the

Re: Do you like bounded integrals?

2016-08-24 Thread Lodovico Giaretta via Digitalmars-d
On Wednesday, 24 August 2016 at 00:40:15 UTC, Andrei Alexandrescu wrote: That wouldn't work for e.g. NaN. A NaN wants to "steal" a value but only if that's not available. It's complicated. Ok, I get your point. WithNaN should not waste the "official range" when there is a huge wasted

Re: Do you like bounded integrals?

2016-08-24 Thread Nordlöw via Digitalmars-d
On Wednesday, 24 August 2016 at 08:39:28 UTC, Nordlöw wrote: Such an implementation is `IndexedBy` at https://github.com/nordlow/phobos-next/blob/master/src/typecons_ex.d#L167 Correction: Index type here is actually a Ada-style modulo type which does wrap-around instead of truncation.

Re: Do you like bounded integrals?

2016-08-24 Thread Nordlöw via Digitalmars-d
On Tuesday, 23 August 2016 at 20:40:06 UTC, Andrei Alexandrescu wrote: Currently checkedint (https://github.com/dlang/phobos/pull/4613) stands at 2432 lines and implements a variety of checking behaviors. At this point I just figured I can very easily add custom bounds, e.g. an int limited to

Re: Do you like bounded integrals?

2016-08-23 Thread Andrei Alexandrescu via Digitalmars-d
On 08/23/2016 05:08 PM, Lodovico Giaretta wrote: On Tuesday, 23 August 2016 at 20:40:06 UTC, Andrei Alexandrescu wrote: * When assigning a Checked to another, should the limits be matched statically or checked dynamically? The ideal would be implicit cast allowed when widening, explicit

Re: Do you like bounded integrals?

2016-08-23 Thread Meta via Digitalmars-d
On Tuesday, 23 August 2016 at 20:40:06 UTC, Andrei Alexandrescu wrote: * When composing, do the limits compose meaningfully? Just to make sure I understand what you mean by "composing limits", do you mean this? alias NonNegativeInt = CheckedInt!(int, Abort, 0, int.max); alias Ubyte =

Re: Do you like bounded integrals?

2016-08-23 Thread Lodovico Giaretta via Digitalmars-d
On Tuesday, 23 August 2016 at 20:40:06 UTC, Andrei Alexandrescu wrote: * When assigning a Checked to another, should the limits be matched statically or checked dynamically? The ideal would be implicit cast allowed when widening, explicit required when narrowing. As I think we will have to

Re: Do you like bounded integrals?

2016-08-23 Thread Cauterite via Digitalmars-d
On Tuesday, 23 August 2016 at 20:40:06 UTC, Andrei Alexandrescu wrote: I think all of these questions have answers, but I wanted to gauge the interest in bounded checked integrals. Would the need for them justify additional complications in the definition? Well, this occurs very frequently in

Do you like bounded integrals?

2016-08-23 Thread Andrei Alexandrescu via Digitalmars-d
Currently checkedint (https://github.com/dlang/phobos/pull/4613) stands at 2432 lines and implements a variety of checking behaviors. At this point I just figured I can very easily add custom bounds, e.g. an int limited to 0 through 100 etc. It would take just a few lines because a lot of