digitalmars.D - Mini proposal: rename float.min to float.min_normal
- Don (29/29) Oct 23 2009 This is another small imperfection we should get rid of.
- #ponce (1/1) Oct 23 2009 I agree, when i had to type float.min i was confused it it was the small...
- Lars T. Kyllingstad (10/35) Oct 23 2009 After I read your floating-point article on the DMD web site that name
- Ali Cehreli (3/5) Oct 23 2009 That bothered me too when I was writing about it before; I felt embarras...
- bearophile (5/7) Oct 23 2009 I usually like all your proposals about floating point numbers :-)
- Jeremie Pelletier (7/15) Oct 24 2009 I never use it either, this identifier is rather pointless. Both
- bearophile (4/7) Oct 24 2009 Sorry, as usual I want not precise enough, I meant I don't like the name...
- Don (3/5) Oct 24 2009 Unfortunately, we can't do that yet, it would silently change the
- Andrei Alexandrescu (7/10) Oct 23 2009 I've always hated that with a passion. Yes Don, great initiative. Let's
- Don (2/13) Oct 28 2009 Patch is in bugzilla 3446. It took about 2 minutes to do.
- Jason House (2/17) Oct 28 2009 You're missing documentation updates.
This is another small imperfection we should get rid of. The floating point types have a property called ".min", but unlike the integer ".min", it's not the minimum! This naming stupidity is inherited from C++. The minimum float is -float.max. Instead, float.min is the minimum representable positive normalized number. (BTW there are also representable "subnormal" numbers between 0 and float.min. So the name 'min' is _completely_ inappropriate, it's not even the minimum absolute value). This misnaming is bad because (a) it causes confusion; and (b) it interfere with generic code, requiring special cases. We should rename this while we have the chance. I don't think we should depart too far from the C/C++ name, but anything other than ".min" will work. I propose: real.min ----> real.min_normal Comments: (1) Embedded underscores are probably not ideal, but they are already in use in the floating point properties mant_dig, and the rarely used max_10_exp, max_exp, min_10_exp, min_exp. They're also used in foreach_reverse, and in the built-in version identifiers, such as X86_64 and D_InlineAsm_X86. So there seems no reason to avoid them here. But if you have a much better idea for a name, speak now! (2) There's no need for float.max_normal. float.max truly is the maximum representable number (excluding infinity). Although float.min sounds like some kind of inverse of float.max, it is not. (The relationship is: X.max * X.min = 4.0 for binary types, 10.0 for decimal types). Changing float.min -> float.min_normal will remove that illusion. If there is no objection to this, I will create a patch. It's very simple.
Oct 23 2009
I agree, when i had to type float.min i was confused it it was the smallest subnormal or smallest normal float
Oct 23 2009
Don wrote:This is another small imperfection we should get rid of. The floating point types have a property called ".min", but unlike the integer ".min", it's not the minimum! This naming stupidity is inherited from C++. The minimum float is -float.max. Instead, float.min is the minimum representable positive normalized number. (BTW there are also representable "subnormal" numbers between 0 and float.min. So the name 'min' is _completely_ inappropriate, it's not even the minimum absolute value). This misnaming is bad because (a) it causes confusion; and (b) it interfere with generic code, requiring special cases. We should rename this while we have the chance. I don't think we should depart too far from the C/C++ name, but anything other than ".min" will work. I propose: real.min ----> real.min_normal Comments: (1) Embedded underscores are probably not ideal, but they are already in use in the floating point properties mant_dig, and the rarely used max_10_exp, max_exp, min_10_exp, min_exp. They're also used in foreach_reverse, and in the built-in version identifiers, such as X86_64 and D_InlineAsm_X86. So there seems no reason to avoid them here. But if you have a much better idea for a name, speak now!After I read your floating-point article on the DMD web site that name has been bothering me too. I vote for changing it. I wouldn't worry about the underscore, as there is already precedence for using them in keywords and built-in properties. If people don't like that, we should also change the others. Would it make sense to redefine real.min to mean -real.max? It would at least be consistent with the meaning of int.min, and perhaps it would find use in generic code. -Lars
Oct 23 2009
Don Wrote:The floating point types have a property called ".min", but unlike the integer ".min", it's not the minimum!That bothered me too when I was writing about it before; I felt embarrassed when explaining that it was not actually the minimum. :) Ali
Oct 23 2009
Don:such as X86_64 and D_InlineAsm_X86<I don't like the identifier that denotes D2 code ("D_Version2").If there is no objection to this, I will create a patch. It's very simple.I usually like all your proposals about floating point numbers :-) Bye, bearophile
Oct 23 2009
bearophile wrote:Don:I never use it either, this identifier is rather pointless. Both compilers will still parse both conditions and errors on the branch for the other version.such as X86_64 and D_InlineAsm_X86<I don't like the identifier that denotes D2 code ("D_Version2").I agree, its a good change! I would also change float.min to be an alias of -float.max. JeremieIf there is no objection to this, I will create a patch. It's very simple.I usually like all your proposals about floating point numbers :-)
Oct 24 2009
Jeremie Pelletier:I never use it either, this identifier is rather pointless. Both compilers will still parse both conditions and errors on the branch for the other version.Sorry, as usual I want not precise enough, I meant I don't like the name of that identifier, but I use that functionality, I use version(D_Version2) when I want to write code that works with both Phobos1 and Phobos2 (so for example I import to!(int, string) from Phobos2 and toInt from Phobos1). Bye, bearophile
Oct 24 2009
Jeremie Pelletier wrote:I agree, its a good change! I would also change float.min to be an alias of -float.max.Unfortunately, we can't do that yet, it would silently change the meaning of existing code. Hopefully it can be done eventually.
Oct 24 2009
Don wrote:This is another small imperfection we should get rid of. The floating point types have a property called ".min", but unlike the integer ".min", it's not the minimum!I've always hated that with a passion. Yes Don, great initiative. Let's change that crap once and for all. I'd consider using minNormal, but you make a good point that _ is already present. ++vote for patching. There are a couple of places in Phobos that need changing, I can operate them. Andrei
Oct 23 2009
Don wrote:This is another small imperfection we should get rid of. The floating point types have a property called ".min", but unlike the integer ".min", it's not the minimum!This misnaming is bad because (a) it causes confusion; and (b) it interfere with generic code, requiring special cases. We should rename this while we have the chance. I don't think we should depart too far from the C/C++ name, but anything other than ".min" will work. I propose: real.min ----> real.min_normal If there is no objection to this, I will create a patch. It's very simple.Patch is in bugzilla 3446. It took about 2 minutes to do.
Oct 28 2009
Don Wrote:Don wrote:You're missing documentation updates.This is another small imperfection we should get rid of. The floating point types have a property called ".min", but unlike the integer ".min", it's not the minimum!This misnaming is bad because (a) it causes confusion; and (b) it interfere with generic code, requiring special cases. We should rename this while we have the chance. I don't think we should depart too far from the C/C++ name, but anything other than ".min" will work. I propose: real.min ----> real.min_normal If there is no objection to this, I will create a patch. It's very simple.Patch is in bugzilla 3446. It took about 2 minutes to do.
Oct 28 2009