Matrix creation quiz

2011-04-28 Thread bearophile
A little quiz. This is related to a recent post of mine in the main D newsgroup, but please don't take a look at that post yet. This is the original function: double[][] matgen(int n) { double[][] a; double tmp = 1.0 / n / n; a.length = n; for (int i = 0; i < n; ++i) a[i].length

Re: Matrix creation quiz

2011-04-28 Thread Pedro Rodrigues
On 28-04-2011 13:02, bearophile wrote: A little quiz. This is related to a recent post of mine in the main D newsgroup, but please don't take a look at that post yet. This is the original function: double[][] matgen(int n) { double[][] a; double tmp = 1.0 / n / n; a.length = n;

Re: Matrix creation quiz

2011-04-28 Thread Steven Schveighoffer
On Thu, 28 Apr 2011 08:02:40 -0400, bearophile wrote: A little quiz. This is related to a recent post of mine in the main D newsgroup, but please don't take a look at that post yet. This is the original function: double[][] matgen(int n) { double[][] a; double tmp = 1.0 / n / n;

Re: Matrix creation quiz

2011-04-28 Thread Kagamin
bearophile Wrote: > auto a = new double[][](n, n); And this really allocs tag array? ps lol, didn't see the unsigned bug.

Re: Matrix creation quiz

2011-04-28 Thread Moritz Warning
On Thu, 28 Apr 2011 08:02:40 -0400, bearophile wrote: > A little quiz. This is related to a recent post of mine in the main D > newsgroup, but please don't take a look at that post yet. This is the > original function: uhm, very sneaky. I wonder, can there be done smth. on behalf of the language t

Re: Matrix creation quiz

2011-04-28 Thread bearophile
Pedro Rodrigues: > The fact that 'i' and 'j' are deduced to type 'uint' in the second > version. That's the kind of bug that would keep me up at night. Almost right answer. i and j are size_t, that is not uint in 64 bit compilations. Unsigned numbers cause the (i-j) sub-expression to give wrong

Re: Matrix creation quiz

2011-04-28 Thread Pedro Rodrigues
On 28-04-2011 16:39, Moritz Warning wrote: On Thu, 28 Apr 2011 08:02:40 -0400, bearophile wrote: A little quiz. This is related to a recent post of mine in the main D newsgroup, but please don't take a look at that post yet. This is the original function: uhm, very sneaky. I wonder, can there

Re: Matrix creation quiz

2011-04-28 Thread bearophile
Pedro Rodrigues: > There sure is: disallow implicit conversion of types. In this program what are the implicit type conversions that cause the bug? Bye, bearophile

Re: Matrix creation quiz

2011-04-30 Thread Ary Manzana
On 4/28/11 8:02 PM, bearophile wrote: A little quiz. This is related to a recent post of mine in the main D newsgroup, but please don't take a look at that post yet. This is the original function: What are unsigned values good for?

Re: Matrix creation quiz

2011-04-30 Thread Don
bearophile wrote: Pedro Rodrigues: The fact that 'i' and 'j' are deduced to type 'uint' in the second version. That's the kind of bug that would keep me up at night. Almost right answer. i and j are size_t, that is not uint in 64 bit compilations. Unsigned numbers cause the (i-j) sub-express

Re: Matrix creation quiz

2011-05-02 Thread bearophile
I was away. Don: > That would not fix this problem. You're doing arithmetic on unsigned > values, where overflow doesn't happen. My enhancement request about integral overflows asks for two compiler switches: one that turns signed integral overflows (at compile time or run time) into errors,