Re: floats default to NaN... why?

2012-06-09 Thread Minas
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. I think that

Re: floats default to NaN... why?

2012-06-09 Thread Kevin
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

Re: floats default to NaN... why?

2012-06-09 Thread Jerome BENOIT
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

Re: floats default to NaN... why?

2012-06-09 Thread Kevin
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

Re: floats default to NaN... why?

2012-06-09 Thread Jerome BENOIT
On 09/06/12 20: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

Re: floats default to NaN... why?

2012-06-09 Thread Andrew Wiley
On Sat, Jun 9, 2012 at 4:53 PM, Andrew Wiley wiley.andre...@gmail.com wrote: On Sat, Jun 9, 2012 at 11:57 AM, Kevin kevincox...@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

Re: floats default to NaN... why?

2012-06-09 Thread Jerome BENOIT
Hello: On 10/06/12 01:57, Andrew Wiley wrote: On Sat, Jun 9, 2012 at 4:53 PM, Andrew Wileywiley.andre...@gmail.com wrote: On Sat, Jun 9, 2012 at 11:57 AM, Kevinkevincox...@gmail.com wrote: On Sat 09 Jun 2012 14:59:21 EDT, Jerome BENOIT wrote: On 09/06/12 20:48, Kevin wrote: On

Re: floats default to NaN... why?

2012-06-09 Thread Jonathan M Davis
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

Re: floats default to NaN... why?

2012-06-09 Thread Jerome BENOIT
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

Re: floats default to NaN... why?

2012-06-09 Thread Jerome BENOIT
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

Re: floats default to NaN... why?

2012-06-08 Thread Minas
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. I understand the logic, but I still disagree. No offense :) I don't

Re: floats default to NaN... why?

2012-06-08 Thread Andrew Wiley
On Thu, Jun 7, 2012 at 6:50 PM, Minas minas_mina1...@hotmail.co.uk wrote: I agree that the default value for floats/doubles should be zero. It feels much more natural. The point is to make sure code is correct. Initializing your variables should be what feels natural. Leaving then

Re: floats default to NaN... why?

2012-06-07 Thread Minas
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

Re: floats default to NaN... why?

2012-06-07 Thread Kevin Cox
On Jun 7, 2012 9:53 PM, Minas minas_mina1...@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.

Re: floats default to NaN... why?

2012-06-07 Thread Jerome BENOIT
hello List: On 08/06/12 04:04, Kevin Cox wrote: On Jun 7, 2012 9:53 PM, Minas minas_mina1...@hotmail.co.uk mailto:minas_mina1...@hotmail.co.uk wrote: I agree that the default value for floats/doubles should be zero. It feels much more natural. This highly depends on your perspective:

Re: floats default to NaN... why?

2012-06-06 Thread ixid
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

Re: floats default to NaN... why?

2012-06-05 Thread Don Clugston
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

Re: floats default to NaN... why?

2012-04-16 Thread Jerome BENOIT
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

Re: floats default to NaN... why?

2012-04-15 Thread F i L
Forums are messing up, so I'll try and respond in sections. /test

Re: floats default to NaN... why?

2012-04-15 Thread F i L
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.

Re: floats default to NaN... why?

2012-04-15 Thread bearophile
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

Re: floats default to NaN... why?

2012-04-15 Thread F i L
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

Re: floats default to NaN... why?

2012-04-15 Thread Ary Manzana
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

Re: floats default to NaN... why?

2012-04-15 Thread F i L
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

Re: floats default to NaN... why?

2012-04-14 Thread Ali Çehreli
On 04/13/2012 09:00 PM, F i L wrote: default is NaN Just to complete the picture, character types have invalid initial values as well: 0xFF, 0x, and 0x for char, wchar, and dchar, respectively. Ali

Re: floats default to NaN... why?

2012-04-14 Thread Jonathan M Davis
On Friday, April 13, 2012 23:29:40 Ali Çehreli wrote: On 04/13/2012 09:00 PM, F i L wrote: default is NaN Just to complete the picture, character types have invalid initial values as well: 0xFF, 0x, and 0x for char, wchar, and dchar, respectively. Yeah. Thanks for mentioning

Re: floats default to NaN... why?

2012-04-14 Thread Manfred Nowak
F i L wrote: It sounds like circular reasoning. Several considerations pressed the design into the current form: 1) always changing output on unchanged input is hard to debug 2) GC needs to be saved from garbage, that looks like pointers 3) missed explicit initializations should not create

Re: floats default to NaN... why?

2012-04-14 Thread F i L
Jonathan M Davis wrote: No. You always have a bug if you don't initialize a variable to the value that it's supposed to be. It doesn't matter whether it's 0, NaN, 527.1209823, or whatever. All having a default value that you're more likely to use means is that you're less likely to have to

Re: floats default to NaN... why?

2012-04-14 Thread F i L
On Saturday, 14 April 2012 at 06:43:11 UTC, Manfred Nowak wrote: F i L wrote: It sounds like circular reasoning. Several considerations pressed the design into the current form: 1) always changing output on unchanged input is hard to debug 2) GC needs to be saved from garbage, that looks

Re: floats default to NaN... why?

2012-04-14 Thread F i L
On Saturday, 14 April 2012 at 06:29:40 UTC, Ali Çehreli wrote: On 04/13/2012 09:00 PM, F i L wrote: default is NaN Just to complete the picture, character types have invalid initial values as well: 0xFF, 0x, and 0x for char, wchar, and dchar, respectively. Ali That's

Re: floats default to NaN... why?

2012-04-14 Thread Jonathan M Davis
On Saturday, April 14, 2012 09:58:42 F i L wrote: On Saturday, 14 April 2012 at 06:29:40 UTC, Ali Çehreli wrote: On 04/13/2012 09:00 PM, F i L wrote: default is NaN Just to complete the picture, character types have invalid initial values as well: 0xFF, 0x, and 0x for

Re: floats default to NaN... why?

2012-04-14 Thread F i L
On Saturday, 14 April 2012 at 07:59:25 UTC, Jonathan M Davis wrote: On Saturday, April 14, 2012 09:45:57 F i L wrote: If D doesn't accommodate entering Laymen, how does it expect to gain popularity in any major way? Efficiency puts D on the map, convenience is what brings the tourists. I

Re: floats default to NaN... why?

2012-04-14 Thread Silveri
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

Re: floats default to NaN... why?

2012-04-14 Thread dennis luehring
Am 14.04.2012 07:48, schrieb F i L: On Saturday, 14 April 2012 at 05:19:38 UTC, dennis luehring wrote: Am 14.04.2012 06:00, schrieb F i L: struct Foo { int x, y;// ready for use. float z, w; // messes things up. float r = 0; // almost always... }

Re: floats default to NaN... why?

2012-04-14 Thread Jerome BENOIT
On 14/04/12 09:45, F i L wrote: Jonathan M Davis wrote: No. You always have a bug if you don't initialize a variable to the value that it's supposed to be. It doesn't matter whether it's 0, NaN, 527.1209823, or whatever. All having a default value that you're more likely to use means is that

Re: floats default to NaN... why?

2012-04-14 Thread bearophile
F i L: So basically, it's for debugging? To avoid bugs it's useful for all variables to be initialized before use (maybe with an explicit annotation for the uncommon cases where you want to use uninitialized memory, like: http://research.swtch.com/sparse ). Having a variable not

Re: floats default to NaN... why?

2012-04-14 Thread Andrej Mitrovic
On 4/14/12, bearophile bearophileh...@lycos.com wrote: Having a variable not initialized is a common source of bugs. I'm going to argue that this was true for C/C++ but is much less true for D. One benefit of having integrals initialized to 0 is that you now have a defined default that you can

Re: floats default to NaN... why?

2012-04-14 Thread F i L
Jerome BENOIT wrote: Why would a compiler set `real' to 0.0 rather then 1.0, Pi, ? Because 0.0 is the lowest (smallest, starting point, etc..) numerical value. Pi is the corner case and obviously has to be explicitly set. If you want to take this further, chars could even be

Re: floats default to NaN... why?

2012-04-14 Thread F i L
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

Re: floats default to NaN... why?

2012-04-14 Thread F i L
dennis luehring wrote: what does make float default to 0.0 better - does it just feel better? Not just. It's consistent with Int types, therefor easier for newbs to pick up since all numeric value types behave the same. I even think char should default to a usable value as well. Most

Re: floats default to NaN... why?

2012-04-14 Thread F i L
On Saturday, 14 April 2012 at 12:48:01 UTC, Andrej Mitrovic wrote: On 4/14/12, bearophile bearophileh...@lycos.com wrote: Having a variable not initialized is a common source of bugs. I'm going to argue that this was true for C/C++ but is much less true for D. One benefit of having integrals

Re: floats default to NaN... why?

2012-04-14 Thread Andrej Mitrovic
On 4/14/12, F i L witte2...@gmail.com wrote: This is exactly what I'm trying to get at. Anyway it's not all bad news since we can use a workaround: struct Float { float payload = 0.0; alias payload this; } void main() { Float x; // acts as a float, is initialized to 0.0 } Not

Re: floats default to NaN... why?

2012-04-14 Thread Jerome BENOIT
On 14/04/12 16:47, F i L wrote: Jerome BENOIT wrote: Why would a compiler set `real' to 0.0 rather then 1.0, Pi, ? Because 0.0 is the lowest (smallest, starting point, etc..) quid -infinity ? numerical value. Pi is the corner case and obviously has to be explicitly set. If you

Re: floats default to NaN... why?

2012-04-14 Thread F i L
On Saturday, 14 April 2012 at 15:44:46 UTC, Jerome BENOIT wrote: On 14/04/12 16:47, F i L wrote: Jerome BENOIT wrote: Why would a compiler set `real' to 0.0 rather then 1.0, Pi, ? Because 0.0 is the lowest (smallest, starting point, etc..) quid -infinity ? The concept of zero is

Re: floats default to NaN... why?

2012-04-14 Thread F i L
On Saturday, 14 April 2012 at 15:35:13 UTC, Andrej Mitrovic wrote: On 4/14/12, F i L witte2...@gmail.com wrote: This is exactly what I'm trying to get at. Anyway it's not all bad news since we can use a workaround: struct Float { float payload = 0.0; alias payload this; } void

Re: floats default to NaN... why?

2012-04-14 Thread Andrej Mitrovic
On 4/14/12, F i L witte2...@gmail.com wrote: a Hack though, since it doesn't work with 'auto'. What do you mean?

Re: floats default to NaN... why?

2012-04-14 Thread F i L
On Saturday, 14 April 2012 at 17:30:19 UTC, Andrej Mitrovic wrote: On 4/14/12, F i L witte2...@gmail.com wrote: a Hack though, since it doesn't work with 'auto'. What do you mean? Only that: auto f = 1.0f; // is float not Float

Re: floats default to NaN... why?

2012-04-14 Thread Andrej Mitrovic
On 4/14/12, F i L witte2...@gmail.com wrote: auto f = 1.0f; // is float not Float UFCS in 2.059 to the rescue: struct Float { float payload = 0.0; alias payload this; } @property Float f(float val) { return Float(val); } void main() { auto f = 1.0.f; }

Re: floats default to NaN... why?

2012-04-14 Thread Jerome BENOIT
On 14/04/12 18:38, F i L wrote: On Saturday, 14 April 2012 at 15:44:46 UTC, Jerome BENOIT wrote: On 14/04/12 16:47, F i L wrote: Jerome BENOIT wrote: Why would a compiler set `real' to 0.0 rather then 1.0, Pi, ? Because 0.0 is the lowest (smallest, starting point, etc..) quid

Re: floats default to NaN... why?

2012-04-14 Thread F i L
On Saturday, 14 April 2012 at 18:02:57 UTC, Andrej Mitrovic wrote: On 4/14/12, F i L witte2...@gmail.com wrote: auto f = 1.0f; // is float not Float UFCS in 2.059 to the rescue: struct Float { float payload = 0.0; alias payload this; } @property Float f(float val) { return

Re: floats default to NaN... why?

2012-04-14 Thread F i L
On Saturday, 14 April 2012 at 18:07:41 UTC, Jerome BENOIT wrote: On 14/04/12 18:38, F i L wrote: On Saturday, 14 April 2012 at 15:44:46 UTC, Jerome BENOIT wrote: On 14/04/12 16:47, F i L wrote: Jerome BENOIT wrote: Why would a compiler set `real' to 0.0 rather then 1.0, Pi, ? Because

Re: floats default to NaN... why?

2012-04-14 Thread Andrej Mitrovic
On 4/14/12, Jerome BENOIT g62993...@rezozer.net wrote: I would even say that D may go further by setting a kind of NaN for integers. That's never going to happen.

Re: floats default to NaN... why?

2012-04-14 Thread Manfred Nowak
F i L wrote: You can't force new D programmers to follow a 'guidline' By exposing a syntax error for every missed explicit initialization the current guideline would be changed into an insurmountable barrier, forcing every new D programmers to follow the 'guidline'. -manfred

Re: floats default to NaN... why?

2012-04-14 Thread Joseph Rushton Wakeling
On 14/04/12 16:52, F i L wrote: 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

Re: floats default to NaN... why?

2012-04-14 Thread Jerome BENOIT
On 14/04/12 20:51, F i L wrote: On Saturday, 14 April 2012 at 18:07:41 UTC, Jerome BENOIT wrote: On 14/04/12 18:38, F i L wrote: On Saturday, 14 April 2012 at 15:44:46 UTC, Jerome BENOIT wrote: On 14/04/12 16:47, F i L wrote: Jerome BENOIT wrote: Why would a compiler set `real' to 0.0

floats default to NaN... why?

2012-04-13 Thread F i L
From the FaQ: NaNs have the interesting property in that whenever a NaN is used as an operand in a computation, the result is a NaN. Therefore, NaNs will propagate and appear in the output whenever a computation made use of one. This implies that a NaN appearing in the output is an

Re: floats default to NaN... why?

2012-04-13 Thread Jonathan M Davis
On Saturday, April 14, 2012 06:00:35 F i L wrote: From the FaQ: NaNs have the interesting property in that whenever a NaN is used as an operand in a computation, the result is a NaN. Therefore, NaNs will propagate and appear in the output whenever a computation made use of one. This

Re: floats default to NaN... why?

2012-04-13 Thread dennis luehring
Am 14.04.2012 06:00, schrieb F i L: struct Foo { int x, y;// ready for use. float z, w; // messes things up. float r = 0; // almost always... } how often in your code is 0 or 0.0 the real starting point? i can't think of any situation except counters or

Re: floats default to NaN... why?

2012-04-13 Thread F i L
So it's what I thought, the only reason is based on a faulty premise, IMO. Jonathan M Davis wrote: Types default to the closest thing that they have to an invalid value so that code blows up as soon as possible if you fail to initialize a variable to a proper value and so that it fails

Re: floats default to NaN... why?

2012-04-13 Thread F i L
On Saturday, 14 April 2012 at 05:19:38 UTC, dennis luehring wrote: Am 14.04.2012 06:00, schrieb F i L: struct Foo { int x, y;// ready for use. float z, w; // messes things up. float r = 0; // almost always... } how often in your code is 0 or 0.0 the real

Re: floats default to NaN... why?

2012-04-13 Thread Jonathan M Davis
On Saturday, April 14, 2012 07:41:33 F i L wrote: You're supposed to initialize them or assign them to appropriate values before using them. sure, but if they always default to _usable_ constants no expectations are lost and no bugs are created. No. You always have a bug if you don't