June 10, 2012
Hello:

On 10/06/12 01:57, Andrew Wiley wrote:
> On Sat, Jun 9, 2012 at 4:53 PM, Andrew Wiley<wiley.andrew.j@gmail.com>  wrote:
>>
>> On Sat, Jun 9, 2012 at 11:57 AM, Kevin<kevincox.ca@gmail.com>  wrote:
>>>
>>> On Sat 09 Jun 2012 14:59:21 EDT, Jerome BENOIT wrote:
>>>>
>>>>
>>>> On 09/06/12 20:48, Kevin wrote:
>>>>> 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?
>>>>
>>>> in Mathematics yes, but not in D.
>>>>
>>>>   I think ints should
>>>>> default to about half of their capacity (probably negative for
>>>>> signed).
>>>>
>>>> This would be machine depends, as such it should be avoided.
>>>>
>>>>> This way you are unlikely to get an off-by-one for an uninitialized
>>>>> values.
>>>>
>>>> something as a Not an Integer NaI should be better.
>>>
>>> I just don't think it is a good idea to add more metadata to ints.
>>>
>>
>> I agree. With floats, NaN is implemented in hardware. The compiler doesn't
>> have to check for NaN when emitting assembly, it just emits operations
>> normally and the hardware handles NaN like you'd expect.
>> If we tried to add a NaN-like value for integers, we would have to check
>> for it before performing integer math. Even with value range propagation, I
>> think that would injure integer math performance significantly.

I see. So the alternative, to get a kind of NaN effect, would be to set integers
to their hardware extremum (INT_MAX,SIZE_MAX,...). But this option is hardware
dependent, so zero as default for integers sounds the best option.

Jerome

>
> Crap, my apologies for responding with HTML.
June 10, 2012
On Sunday, June 10, 2012 02:32:18 Jerome BENOIT wrote:
> I see. So the alternative, to get a kind of NaN effect, would be to set integers to their hardware extremum (INT_MAX,SIZE_MAX,...). But this option is hardware dependent, so zero as default for integers sounds the best option.

??? All integral types in D have fixed sizes. It's _not_ system or hardware dependent. There's no reason why would couldn't have defaulted int to int.max, long to long.max, etc. It would have been the same on all systems.

size_t does vary across systems, because it's an alias (uint on 32-bit, ulong on 64-bit), but that's pretty much the only integral type which varies.

There's no hardware stuff going on there like you get with NaN, so you wouldn't get stuff like dividing by zero results in int.max with ints. That would be the same as always if int defaulted to int.max - it's just the init value which would change. NaN can do more, because it has hardware support and floating point values are just plain different from integral values. But we could certainly have made integral values default to their max without costing performance.

Regardless, for better or worse, 0 was chosen as the init value for all of the integral types, and it would break tons of code to change it now. So, it's never going to change.

- Jonathan M Davis
June 10, 2012

On 10/06/12 02:49, Jonathan M Davis wrote:
> On Sunday, June 10, 2012 02:32:18 Jerome BENOIT wrote:
>> I see. So the alternative, to get a kind of NaN effect, would be to set
>> integers to their hardware extremum (INT_MAX,SIZE_MAX,...). But this option
>> is hardware dependent, so zero as default for integers sounds the best
>> option.
>
> ??? All integral types in D have fixed sizes.

You are right, what I wrote is a non sense:
I am getting tired.

Sorry forthe mistake, and the noise,
Jerome
June 10, 2012

On 10/06/12 02:49, Jonathan M Davis wrote:
> On Sunday, June 10, 2012 02:32:18 Jerome BENOIT wrote:
>> I see. So the alternative, to get a kind of NaN effect, would be to set
>> integers to their hardware extremum (INT_MAX,SIZE_MAX,...). But this option
>> is hardware dependent, so zero as default for integers sounds the best
>> option.
>
> ??? All integral types in D have fixed sizes.

Sorry, I forgot this part.


Jerome
1 2 3 4 5 6 7
Next ›   Last »