floats default to NaN... why?

Kevin kevincox.ca at gmail.com
Sat Jun 9 11:48:55 PDT 2012


On 09/06/12 14:42, Minas wrote:
>> With
>> ints, the best we can do is 0. With floats, NaN makes it better.
>
> With the logic that NaN is the default for floats, 0 is a very bad
> choice for ints. It the worst we could do. Altough I understand that
> setting it to something else like -infinity is still not a good choice.
Is it just me but do ints not have infinity values?  I think ints should
default to about half of their capacity (probably negative for signed). 
This way you are unlikely to get an off-by-one for an uninitialized values.

> I think that if D wants people to initialize their variables, it
> should generate a compiler error when not doing so, like C# and Java.
> For me, having floats defaulting to NaN and ints to zero is somewhere
> in the middle... Which isn't good.
I 100% agree.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 230 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20120609/29001dc6/attachment.pgp>


More information about the Digitalmars-d-learn mailing list