Re: Example in the overview

2010-05-14 Thread Walter Bright
Steven Schveighoffer wrote: A comment to explain the representation of the array may be good. Well, I did add your explanation to the bugzilla report! Thanks.

Re: Example in the overview

2010-05-14 Thread Steven Schveighoffer
On Fri, 14 May 2010 19:37:58 -0400, Walter Bright wrote: R.Tenton wrote: At the very bottom of http://digitalmars.com/d/2.0/overview.html there is an example implementation of the Eratosthenes' sieve. That code is broken! It counts 1899 prime numbers, while there are only 1028 primes in t

Re: Example in the overview

2010-05-14 Thread Simen kjaeraas
Walter Bright wrote: bearophile wrote: Walter Bright: Are you sure? What's the mistake in the code? This is the code in the Overview, it prints 1899: http://codepad.org/lzRtggEL This is the code I have suggested in bugzilla, it prints 1027: http://ideone.com/D9ZqQ Wolfram Alpha says they

Re: Example in the overview

2010-05-14 Thread bearophile
Ary Borenszweig: > A small observation: count +=1 is performed for i = 0, hmmm... It lacks unit tests. A basic unit testing can catch that bug. Recently I have ready a quote: "If it has no unit tests then it's broken". Experience shows me that this is more often true than false. Bye, bearophile

Re: Example in the overview

2010-05-14 Thread Ary Borenszweig
Walter Bright wrote: bearophile wrote: Walter Bright: Are you sure? What's the mistake in the code? This is the code in the Overview, it prints 1899: http://codepad.org/lzRtggEL This is the code I have suggested in bugzilla, it prints 1027: http://ideone.com/D9ZqQ Wolfram Alpha says they ar

Re: Example in the overview

2010-05-14 Thread Walter Bright
bearophile wrote: Walter Bright: Are you sure? What's the mistake in the code? This is the code in the Overview, it prints 1899: http://codepad.org/lzRtggEL This is the code I have suggested in bugzilla, it prints 1027: http://ideone.com/D9ZqQ Wolfram Alpha says they are 1027 (I have left ou

Re: Example in the overview

2010-05-14 Thread bearophile
Walter Bright: > Are you sure? What's the mistake in the code? This is the code in the Overview, it prints 1899: http://codepad.org/lzRtggEL This is the code I have suggested in bugzilla, it prints 1027: http://ideone.com/D9ZqQ Wolfram Alpha says they are 1027 (I have left out the last number be

Re: Example in the overview

2010-05-14 Thread Walter Bright
R.Tenton wrote: At the very bottom of http://digitalmars.com/d/2.0/overview.html there is an example implementation of the Eratosthenes' sieve. That code is broken! It counts 1899 prime numbers, while there are only 1028 primes in the interval [1,8191]! Are you sure? What's the mistake in the c

Re: Confusing behavior involving array operations.

2010-05-14 Thread Robert Clipsham
On 15/05/10 00:14, Pillsy wrote: I have the following program on Mac OS X 10.6.3 running dmd version 2.043: $ cat if.d import std.stdio; void main (string [] args) { foreach(arg; args) writeln(arg); auto vec = new double[10]; foreach(i, ref x; vec) { x = cast(double) i; } if

Re: compiled gdb

2010-05-14 Thread Robert Clipsham
On 15/05/10 00:14, eles wrote: hello, since gnu debugger (gdb) is free and now there is a version which works properly with D, could someone host (and made available for download) *compiled* versions for windows and linux? of course, patched versions (so that it would work with D). maybe on dsou

compiled gdb

2010-05-14 Thread eles
hello, since gnu debugger (gdb) is free and now there is a version which works properly with D, could someone host (and made available for download) *compiled* versions for windows and linux? of course, patched versions (so that it would work with D). maybe on dsource? thanks (I am not good when

Confusing behavior involving array operations.

2010-05-14 Thread Pillsy
I have the following program on Mac OS X 10.6.3 running dmd version 2.043: $ cat if.d import std.stdio; void main (string [] args) { foreach(arg; args) writeln(arg); auto vec = new double[10]; foreach(i, ref x; vec) { x = cast(double) i; } if (args.length > 1 && args[1] == "bar") {

Re: Loop optimization

2010-05-14 Thread Jérôme M. Berger
bearophile wrote: > kai: > >> I was scared off by the warning that D 2.0 support is experimental. > > LDC is D1 still, mostly :-( > And at the moment it uses LLVM 2.6. > LLVM 2.7 contains a new optimization that can improve that code some more. > > >> Good to know, thanks (thats actually a grea

Re: Loop optimization

2010-05-14 Thread bearophile
kai: > I was scared off by the warning that D 2.0 support is experimental. LDC is D1 still, mostly :-( And at the moment it uses LLVM 2.6. LLVM 2.7 contains a new optimization that can improve that code some more. > Good to know, thanks (thats actually a great feature for scientists!). In theo

Re: Loop optimization

2010-05-14 Thread strtr
== Quote from bearophile (bearophileh...@lycos.com)'s article > But the bigger problem in your code is that you are performing operations on NaNs (that's the default initalization of FP values in D), and operations on NaNs are usually quite slower. I didn't know that. Is it the same for inf? I us

Re: Loop optimization

2010-05-14 Thread kai
Thanks for the help all! > 2. Can you use vector operations? If the example you gave is > representative of your specific problem, then you can't because you are > adding overlapping parts of the array. But if you are doing operations > on separate arrays, then array operations will be *much* fa

Re: Assertion failure: 'fieldi>=0 && fieldi < se->elements->dim' on line 2062 in file 'interpret.c'

2010-05-14 Thread strtr
or : module main; //const S s = S(.5f); // Uncomment to make it compile struct S { float a; static S opCall( float a_ ) { S s = { a_ }; return s; } const S _s = S( 1f ); } void main(){}

Re: Assertion failure: 'fieldi>=0 && fieldi < se->elements->dim' on line 2062 in file 'interpret.c'

2010-05-14 Thread strtr
== Quote from bearophile (bearophileh...@lycos.com)'s article > This produces the same errors: > struct Foo { > int bar; > static Foo baz() { > return Foo(); > } > const Foo one = Foo.baz(); > } > void main() {} > Bye, > bearophile And this is why in my program compiled any

Re: Loop optimization

2010-05-14 Thread Steven Schveighoffer
On Thu, 13 May 2010 22:38:40 -0400, kai wrote: Hello, I was evaluating using D for some numerical stuff. However I was surprised to find that looping & array indexing was not very speedy compared to alternatives (gcc et al). I was using the DMD2 compiler on mac and windows, with -O -rele

Re: Loop optimization

2010-05-14 Thread Lars T. Kyllingstad
On Fri, 14 May 2010 07:32:54 -0400, Steven Schveighoffer wrote: > On Fri, 14 May 2010 02:31:29 -0400, Lars T. Kyllingstad > wrote: > >> On Fri, 14 May 2010 02:38:40 +, kai wrote: > > >>> I was using the DMD2 compiler on >>> mac and windows, with -O -release. >> >> 1. Have you tried the -no

Re: Loop optimization

2010-05-14 Thread Steven Schveighoffer
On Fri, 14 May 2010 02:31:29 -0400, Lars T. Kyllingstad wrote: On Fri, 14 May 2010 02:38:40 +, kai wrote: I was using the DMD2 compiler on mac and windows, with -O -release. 1. Have you tried the -noboundscheck compiler switch? Unlike C, D checks that you do not try to read/write b

Re: Loop optimization

2010-05-14 Thread bearophile
kai: > I was evaluating using D for some numerical stuff. For that evaluation you probably have to use the LDC compiler, that is able to optimize better. > void main (string[] args) > { > double [] foo = new double [cast(int)1e6]; > for (int i=0;i<1e3;i+