View mode: basic / threaded / horizontal-split · Log in · Help
April 16, 2012
Re: floats default to NaN... why?
Actually, all of this discussion has made me think that having a 
compiler flag to change FP values to zero as default would be a 
good idea.

Basically my opinion is largely influenced by a couple things. 
That is:

- I believe a lot of good programmers are used to using zero for 
default. Winning them over is a good thing for everyone here. I'm 
not trying to blow this issue out of proportion, I understand 
this isn't all that big a deal, but papercuts do count.

- My major project in D is a game engine. I want D to not only be 
used for the engine, but also to serve as the "scripting" 
language as well. Thus, I want D knowledge prerequisite to be as 
low as possible. I still think that 0 should be used as default 
in D, however, I'd be more than happy to have a compiler flag for 
this as well.



I've been wanting to try and contribute to D for awhile now. I've 
looked through the source; haven't coded in C++ in a long time, 
and never professionally, but I should be able to tackle 
something like adding a compiler flag to default FP variables to 
zero. If I write the code, would anyone object to having a flag 
for this?
April 16, 2012
Re: floats default to NaN... why?
F i L:

> I should be able to tackle something like adding a compiler 
> flag to default FP variables to zero. If I write the code, 
> would anyone object to having a flag for this?

I strongly doubt Walter & Andrei will accept this in the main DMD 
trunk.

Bye,
bearophile
April 16, 2012
Re: floats default to NaN... why?
On Monday, 16 April 2012 at 03:25:15 UTC, bearophile wrote:
> F i L:
>
>> I should be able to tackle something like adding a compiler 
>> flag to default FP variables to zero. If I write the code, 
>> would anyone object to having a flag for this?
>
> I strongly doubt Walter & Andrei will accept this in the main 
> DMD trunk.

Do you have an idea as the reason? To specific/insignificant an 
issue to justify a compiler flag? They don't like new 
contributors?

I'll wait for a definite yes or no from one of them before I 
approach this.
April 16, 2012
Re: floats default to NaN... why?
On 4/16/12 12:00 PM, F i L wrote:
> On Monday, 16 April 2012 at 03:25:15 UTC, bearophile wrote:
>> F i L:
>>
>>> I should be able to tackle something like adding a compiler flag to
>>> default FP variables to zero. If I write the code, would anyone
>>> object to having a flag for this?
>>
>> I strongly doubt Walter & Andrei will accept this in the main DMD trunk.
>
> Do you have an idea as the reason? To specific/insignificant an issue to
> justify a compiler flag? They don't like new contributors?
>
> I'll wait for a definite yes or no from one of them before I approach this.

It's a flag that changes the behavior of the generated output. That's a 
no no.
April 16, 2012
Re: floats default to NaN... why?
On Monday, 16 April 2012 at 04:05:35 UTC, Ary Manzana wrote:
> On 4/16/12 12:00 PM, F i L wrote:
>> On Monday, 16 April 2012 at 03:25:15 UTC, bearophile wrote:
>>> F i L:
>>>
>>>> I should be able to tackle something like adding a compiler 
>>>> flag to
>>>> default FP variables to zero. If I write the code, would 
>>>> anyone
>>>> object to having a flag for this?
>>>
>>> I strongly doubt Walter & Andrei will accept this in the main 
>>> DMD trunk.
>>
>> Do you have an idea as the reason? To specific/insignificant 
>> an issue to
>> justify a compiler flag? They don't like new contributors?
>>
>> I'll wait for a definite yes or no from one of them before I 
>> approach this.
>
> It's a flag that changes the behavior of the generated output. 
> That's a no no.

Don't *all* flags technically change behavior? -m64 for instance. 
How is this any different?

Besides, NaN as default is debugging feature. It's not the same 
thing as -debug/-release, but I think it makes sense to be able 
to disable it.
April 16, 2012
Re: floats default to NaN... why?
On 16/04/12 04:38, F i L wrote:
>>> Of course FP numbers are meant for coders... they're in a programming language. They are used by coders, and not every coder that uses FP math *has* to be well trained in the finer points of mathematics simply to use a number that can represent fractions in a conceptually practical way.
>>>
>> The above is not finer points, but basic ones.
>> Otherwise, float and double are rather integers than by fractions.
>
> I don't understand what you wrote. Typo?

Typo:
float and double are rather represented by integers than by fractions.

Jerome
June 05, 2012
Re: floats default to NaN... why?
On 14/04/12 16:52, F i L wrote:
> On Saturday, 14 April 2012 at 10:38:45 UTC, Silveri wrote:
>> On Saturday, 14 April 2012 at 07:52:51 UTC, F i L wrote:
>>> On Saturday, 14 April 2012 at 06:43:11 UTC, Manfred Nowak wrote:
>>>> F i L wrote:
>>>>
>>>> 4) use hardware signalling to overcome some of the limitations
>>>> impressed by 3).
>>>
>>> 4) I have no idea what you just said... :)
>>
>> On Saturday, 14 April 2012 at 07:58:44 UTC, F i L wrote:
>>> That's interesting, but what effect does appending an invalid char to
>>> a valid one have? Does the resulting string end up being "NaS" (Not a
>>> String)? Cause if not, I'm not sure that's a fair comparison.
>>
>> The initialization values chosen are also determined by the underlying
>> hardware implementation of the type. Signalling NANs
>> (http://en.wikipedia.org/wiki/NaN#Signaling_NaN) can be used with
>> floats because they are implemented by the CPU, but in the case of
>> integers or strings their aren't really equivalent values.
>
> I'm sure the hardware can just as easily signal zeros.

It can't.
June 06, 2012
Re: floats default to NaN... why?
People may not have voiced their dislike but I'm sure quite a few 
don't like it, it felt jarringly wrong to me. Zero is a better 
default for the consistency and usefulness, expecting a default 
to cause things to keel over as a justification isn't a good one, 
or not as strong as the consistency of zero.
June 08, 2012
Re: floats default to NaN... why?
I agree that the default value for floats/doubles should be zero. 
It feels much more natural.

I think the problem here is that people are thinking about some 
stuff too much. D is a rather new language that wants to be 
practical. Floats defaulting to NaN is NOT practical FOR MOST 
PEOPLE when at the same time I write:

int sum;

for(...)
  sum += blah blah blah

And it works.

Having floats deaulting to a value that's un-natural for most 
people is, in my opinion, craziness. Even if that's "more" 
correct in a mathematical sense.

Please excuse my English.
June 08, 2012
Re: floats default to NaN... why?
On Jun 7, 2012 9:53 PM, "Minas" <minas_mina1990@hotmail.co.uk> wrote:
>
> I agree that the default value for floats/doubles should be zero. It
feels much more natural.
>
> I think the problem here is that people are thinking about some stuff too
much. D is a rather new language that wants to be practical. Floats
defaulting to NaN is NOT practical FOR MOST PEOPLE when at the same time I
write:
>
> int sum;
>
> for(...)
>  sum += blah blah blah
>
> And it works.
>
> Having floats deaulting to a value that's un-natural for most people is,
in my opinion, craziness. Even if that's "more" correct in a mathematical
sense.
>
> Please excuse my English.

The idea isn't being "practical" exactly.  The idea was to use invalid
values as defaults. Unfortunately things like ints don't have invalid
values, so they chose zero.  The idea is to make people initialize their
variables.  It would have been better to pick 19472937 as the int default
because not many people will use that value.

The code you showed would be considered **bad** because you did not
initialize your variables, however ints defaulting to zero is well defined
so it isn't really a big deal.

With floats there is this wonderful value that ensures that nothing
reasonable comes out of a bad calculation, NaN.  Therefore this is used as
a default because if you forget to initialize your vars it will jump out at
you.

This is the thought that was used and many people don't agree.  It is
**very** unlikely to be changed now but __maybe__ D3 however far off that
is.  I hope not though, I hope ints default to 8472927 instead, but
everyone has different opinions.
1 2 3 4 5 6 7
Top | Discussion index | About this forum | D home