Thread overview
Errors in specification?
Jun 12, 2008
Simen Haugen
Jun 13, 2008
Simen Haugen
Jun 13, 2008
BCS
Jun 16, 2008
Gide Nwawudu
June 12, 2008
This is the property example from http://digitalmars.com/d/1.0/property.html

int a;
int b = 1;
typedef int t = 2;
t c;
t d = cast(t)3;

int.init // is 0
a.init  // is 0
b.init  // is 1 // Well, I get 0
t.init  // is 2 // Well, I get 2
c.init  // is 2 // Well, I get 2
d.init  // is 3 // Well, I get 2

struct Foo
{
    int a;
    int b = 7;
}

Foo.a.init // is 0 // Well, I get 0
Foo.b.init // is 7 // Well, I get 0


And another:

enum E { V };
E.V.stringof; // I get int instead of E.V


And another:

float f = 1.0;
f.init; // This should be 1.0 according to the spec.. It's nan here.
const f2 = 1.0;
f2.init; // still nan... Only typedefs changes the init?

Ditto for other types.


And is it possible to check if a float is nan?
float f2;
f2 is float.nan; // false
f2.init is float.init; // false
float.nan is float.nan; // false...


I'm using dmd 1.028


June 12, 2008
"Simen Haugen" <simen.haugen@pandavre.com> wrote in message news:g2s4uk$2nt7$1@digitalmars.com...
> This is the property example from http://digitalmars.com/d/1.0/property.html
>
> ...
>
> Ditto for other types.

The behavior of .init was changed in 1.017.  Per-variable .inits now just get the .init of the type.  I don't know why the spec hasn't been updated to match.

>
> And is it possible to check if a float is nan?
> float f2;
> f2 is float.nan; // false
> f2.init is float.init; // false
> float.nan is float.nan; // false...

Either use std.math.isnan/tango.math.IEEE.isNaN, or a somewhat.. funnier looking method:

float f2;
f2 !<>= f2; // true


June 13, 2008
"Jarrett Billingsley" wrote in message
> Either use std.math.isnan/tango.math.IEEE.isNaN, or a somewhat.. funnier looking method:
>
> float f2;
> f2 !<>= f2; // true

Thanks a lot

If I had checked the expression chapter I would have seen that. I must say that at first I thought wtf! I had no idea what you were doing there: "f2 not lt gt eq f2"?!? Sure is a long strange looking operator.


June 13, 2008
"Simen Haugen" <simen@norstat.no> wrote in message news:g2tdtv$e76$1@digitalmars.com...
> "Jarrett Billingsley" wrote in message
>> Either use std.math.isnan/tango.math.IEEE.isNaN, or a somewhat.. funnier looking method:
>>
>> float f2;
>> f2 !<>= f2; // true
>
> Thanks a lot
>
> If I had checked the expression chapter I would have seen that. I must say that at first I thought wtf! I had no idea what you were doing there: "f2 not lt gt eq f2"?!? Sure is a long strange looking operator.

Heheh.  Well I don't think it actually mentions that that's a possible test for nan, but it just happens to work out because of the semantics of that operator.


June 13, 2008
Reply to Jarrett,

> "Simen Haugen" <simen@norstat.no> wrote in message
> news:g2tdtv$e76$1@digitalmars.com...
> 
>> "Jarrett Billingsley" wrote in message
>> 
>>> Either use std.math.isnan/tango.math.IEEE.isNaN, or a somewhat..
>>> funnier looking method:
>>> 
>>> float f2;
>>> f2 !<>= f2; // true
>> Thanks a lot
>> 
>> If I had checked the expression chapter I would have seen that. I
>> must say that at first I thought wtf! I had no idea what you were
>> doing there: "f2 not lt gt eq f2"?!? Sure is a long strange looking
>> operator.
>> 
> Heheh.  Well I don't think it actually mentions that that's a possible
> test for nan, but it just happens to work out because of the semantics
> of that operator.
> 

It's also the only thing it's useful for.

However I would like to see "f1 is f2" do an "incorrect" floating point comparison: (NaN is NaN) == true

I was planning on asking for it but Simen beat me to it.


June 16, 2008
On Thu, 12 Jun 2008 23:37:23 +0200, "Simen Haugen" <simen.haugen@pandavre.com> wrote:

>This is the property example from http://digitalmars.com/d/1.0/property.html
>
>int a;
>int b = 1;
>typedef int t = 2;
>t c;
>t d = cast(t)3;
>
>int.init // is 0
>a.init  // is 0
>b.init  // is 1 // Well, I get 0
>t.init  // is 2 // Well, I get 2
>c.init  // is 2 // Well, I get 2
>d.init  // is 3 // Well, I get 2
>
>struct Foo
>{
>    int a;
>    int b = 7;
>}
>
>Foo.a.init // is 0 // Well, I get 0
>Foo.b.init // is 7 // Well, I get 0
> ...

The .init error in spec is already in bugzilla. http://d.puremagic.com/issues/show_bug.cgi?id=2045

Gide