Jump to page: 1 2
Thread overview
Mini proposal: rename float.min to float.min_normal
Oct 23, 2009
Don
Oct 23, 2009
#ponce
Oct 23, 2009
Ali Cehreli
Oct 23, 2009
bearophile
Oct 24, 2009
Jeremie Pelletier
Oct 24, 2009
bearophile
Oct 24, 2009
Don
Oct 28, 2009
Don
Oct 28, 2009
Jason House
October 23, 2009
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.
October 23, 2009
I agree, when i had to type float.min i was confused it it was the smallest subnormal or smallest normal float
October 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
October 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

October 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
October 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!

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
October 24, 2009
bearophile wrote:
> Don:
> 
>> such as X86_64 and D_InlineAsm_X86<
> 
> I don't like the identifier that denotes D2 code ("D_Version2").

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.

>> 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 :-)

I agree, its a good change! I would also change float.min to be an alias of -float.max.

Jeremie
October 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
October 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.
October 28, 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.
« First   ‹ Prev
1 2