for ranges

ixid via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 23 01:44:20 PST 2015


On Thursday, 22 January 2015 at 16:41:49 UTC, Russel Winder wrote:
> Playing with factorial implementations, as you do. I had a D
> implementation using ulong. Not sensible obviously since 
> overflow is a
> bit of a problem. But the code worked, as did the tests. Now 
> converting
> to BigInt and…
>
> The standard explicit iteration form uses a loop:
>
> 	for(i; 2..n+1)
>
> for n = 0 or 1 this loop doesn't loop since the range is [,). 
> However
> for BigInt:
>
> 	for(i; two..n + one)
>
> the loop starts at 0 and just keeps on going. This is clearly 
> not good.
>
> Am I having a mental breakdown or is this a real bug?

In general it feels as if BigInt needs more work as it doesn't
work with simple generic code in too many cases. Templates get
confused by invocation with a literal and a BigInt for example
when it should have a single type. Literals feel too strongly
typed or too weakly implicitly convertible.


More information about the Digitalmars-d-learn mailing list