Getting action on your favorite D issues
H. S. Teoh
hsteoh at quickfur.ath.cx
Sat Jun 6 00:25:15 UTC 2020
On Fri, Jun 05, 2020 at 04:53:28PM -0700, H. S. Teoh via Digitalmars-d wrote:
> On Fri, Jun 05, 2020 at 11:57:39PM +0200, ag0aep6g via Digitalmars-d wrote:
> [...]
> > 2) "bool can be both true and false"
> > https://issues.dlang.org/show_bug.cgi?id=20148
> >
> > This one is just silly.
> [...]
>
> Nah, it's not silly, it's just that DMD's backend produces code that
> exhibits quantum uncertainty:
[...]
For even more quantum fun:
----------
bool schrodingersCat() @safe {
import std.random;
union Box { bool b; int state; }
Box u;
u.state = uniform(2, int.max);
return u.b;
}
void main() @safe {
import std.stdio;
bool b = schrodingersCat();
if (b) writeln("alive");
if (!b) writeln("dead");
}
----------
With LDC, this code will output either "alive" or "dead" with a roughly
50% probability of each. So it's a classical observer.
With DMD, however, this code will perceive the quantum superimposition
directly and output both "alive" and "dead" every time.
:-D
//
OK, I'll stop now. :-P
T
--
Bare foot: (n.) A device for locating thumb tacks on the floor.
More information about the Digitalmars-d
mailing list