Re: Quadratic time to sort in a simple case?

2013-04-24 Thread Xinok
On Friday, 19 April 2013 at 22:37:45 UTC, Ivan Kazmenko wrote: So, why isn't TimSort the default? I would actually argue for this, not for safety (introsort is an adequate solution) but for different reasons. Timsort is stable and it's faster on data with low entropy, being nearly instantane

Re: Postblit isn't called on rvalue return

2013-04-24 Thread Ali Çehreli
On Wednesday, 24 April 2013 at 21:36:48 UTC, Sebastian Graf wrote: Seems to me that dmd doesn't do NRVO (?), see the issue. I can see that NRVO would be faster than the extra bit-copy. Especially the last one of the following set of blog posts is relevant. The posts explain the rationale for

Re: Postblit isn't called on rvalue return

2013-04-24 Thread Sebastian Graf
On Wednesday, 24 April 2013 at 20:53:11 UTC, Ali Çehreli wrote: First, as the local 's' in makeS() is local, it cannot be returned by ref. So, the 'auto ref' return type of makeS() becomes by-value. However, rvalues are never copied in D. The compiler automatically moves the bits of the rva

Re: Internal error: ../ztc/cgcs.c

2013-04-24 Thread Namespace
I think this is already fixed in the current dmd 2.063alpha. Bye, bearophile You walking encyclopedia. ;) Good to know.

Re: Postblit isn't called on rvalue return

2013-04-24 Thread Ali Çehreli
On Wednesday, 24 April 2013 at 11:42:01 UTC, Sebastian Graf wrote: For this program: import std.stdio; struct S { ubyte* b; ubyte buf[128]; this(this) { writeln("postblit"); } } auto ref makeS() { S s;

Re: Internal error: ../ztc/cgcs.c

2013-04-24 Thread bearophile
Namespace: import std.stdio; int[2] getSize() { return [42, 23]; } int width() { return getSize()[0]; } void main() { writeln("Hello world!"); } Compilation output: Internal error: ../ztc/cgcs.c 343 I think this is already fixed in the current dmd 2.063alpha.

Re: Internal error: ../ztc/cgcs.c

2013-04-24 Thread Timon Gehr
On 04/24/2013 10:25 PM, Namespace wrote: import std.stdio; int[2] getSize() { return [42, 23]; } int width() { return getSize()[0]; } void main() { writeln("Hello world!"); } Compilation output: Internal error: ../ztc/cgcs.c 343 http://dpaste.1azy.net/a1897e84 I don

Internal error: ../ztc/cgcs.c

2013-04-24 Thread Namespace
import std.stdio; int[2] getSize() { return [42, 23]; } int width() { return getSize()[0]; } void main() { writeln("Hello world!"); } Compilation output: Internal error: ../ztc/cgcs.c 343 http://dpaste.1azy.net/a1897e84 I don't know if this should compile (b

Re: Random double

2013-04-24 Thread Joseph Rushton Wakeling
On 04/23/2013 10:59 PM, bearophile wrote: > Also note by their nature doubles are not equally spread across the line of > Reals, so getting a truly uniform distribution is hard or impossible. More than that -- the number of unique values generated by the underlying RNG should (for Mersenne Twister

Re: Random double

2013-04-24 Thread Ivan Kazmenko
On Wednesday, 24 April 2013 at 13:30:41 UTC, Ivan Kazmenko wrote: probably excluding special values (all-0 or all-1), I meant exponent bits being all 0 or all 1, sorry. That's where the special values reside, at least according to IEEE-754-1985 here: http://en.wikipedia.org/wiki/IEEE_754-1985

Re: Random double

2013-04-24 Thread Ivan Kazmenko
On Tuesday, 23 April 2013 at 14:43:15 UTC, qznc wrote: I want to generate a random "double" value, excluding wierdos like NaN and Infinity. However, std.random.uniform seems to be useless. I tried things like std.random.uniform( double.min, double.max); std.random.uniform(-double.max, doub

Re: Random double

2013-04-24 Thread qznc
On Wednesday, 24 April 2013 at 06:56:44 UTC, Ivan Kazmenko wrote: On Wednesday, 24 April 2013 at 06:37:50 UTC, qznc wrote: It also raises the question what uniform means in the context of floating point. Uniform over the numbers or uniform over the bit patterns? I'd like to mention that there

Re: WinAPI callbacks and GC

2013-04-24 Thread evilrat
On Wednesday, 24 April 2013 at 09:51:29 UTC, Regan Heath wrote: Until then, I would perform manual memory allocation. I am not sure how in D, but you need something like "placement new" to construct a class in a previously allocated block of memory (allocated with malloc or similar). look at

Postblit isn't called on rvalue return

2013-04-24 Thread Sebastian Graf
For this program: import std.stdio; struct S { ubyte* b; ubyte buf[128]; this(this) { writeln("postblit"); } } auto ref makeS() { S s; s.b = s.buf; writeln("made S at ", cast(void*)&s, ", s.b ==

Re: Random double

2013-04-24 Thread Ivan Kazmenko
On Wednesday, 24 April 2013 at 10:46:57 UTC, Andrea Fontana wrote: What's the probability to guess a precise number in [0..1]? I think is 0 as long as you have infinite numbers. Right. What's the probability to guess a interval in [0..1]? I think it's the interval size. Right again. I mean

Re: Random double

2013-04-24 Thread Andrea Fontana
On Wednesday, 24 April 2013 at 10:33:49 UTC, Ivan Kazmenko wrote: On Wednesday, 24 April 2013 at 10:26:19 UTC, Andrea Fontana wrote: I'd like to mention that there's no such mathematical object as "uniform distribution on [0..+infinity)". ... you neither can choose a random real number in any

Re: Random double

2013-04-24 Thread Ivan Kazmenko
On Wednesday, 24 April 2013 at 10:26:19 UTC, Andrea Fontana wrote: I'd like to mention that there's no such mathematical object as "uniform distribution on [0..+infinity)". ... you neither can choose a random real number in any interval ... ... but that is at least valid mathematically, albe

Re: Random double

2013-04-24 Thread Andrea Fontana
On Wednesday, 24 April 2013 at 06:56:44 UTC, Ivan Kazmenko wrote: On Wednesday, 24 April 2013 at 06:37:50 UTC, qznc wrote: It also raises the question what uniform means in the context of floating point. Uniform over the numbers or uniform over the bit patterns? I'd like to mention that there

Re: WinAPI callbacks and GC

2013-04-24 Thread Regan Heath
On Tue, 23 Apr 2013 22:21:27 +0100, Jack Applegame wrote: I'm writing Ctrl-C handler for console application for Windows: extern(Windows) { int CtrlHandler(uint flag) nothrow { auto tmp = new SomeClass; // is it safe? ... return true; } } ... SetConsoleCtrlHandler(&Ctr

Re: Quadratic time to sort in a simple case?

2013-04-24 Thread Dmitry Olshansky
24-Apr-2013 01:09, Ivan Kazmenko пишет: And on Tuesday, 23 April 2013 at 01:10:26 UTC, Xinok wrote: I filed a bug report for this issue a year ago: http://d.puremagic.com/issues/show_bug.cgi?id=7767 I've been meaning to fix this issue myself. Time allowing, I'll do it soon. What I wonder now,

Re: Quadratic time to sort in a simple case?

2013-04-24 Thread Dmitry Olshansky
23-Apr-2013 05:17, Xinok пишет: On Saturday, 20 April 2013 at 16:35:25 UTC, Dmitry Olshansky wrote: And this all is good but TimSort allocates O(N) memory. The constant in front of N is smallish less then 1.0 but it could cause some grief. Worst case is O(n/2), but it starts small and doubles

Re: Random double

2013-04-24 Thread Ivan Kazmenko
On Wednesday, 24 April 2013 at 06:37:50 UTC, qznc wrote: It also raises the question what uniform means in the context of floating point. Uniform over the numbers or uniform over the bit patterns? I'd like to mention that there's no such mathematical object as "uniform distribution on [0..+in