"R" suffix for reals

Steven Schveighoffer schveiguy at yahoo.com
Mon May 7 12:07:53 PDT 2012


On Mon, 07 May 2012 14:11:34 -0400, Arne <arne at linux.nu> wrote:

> On Monday, 7 May 2012 at 12:34:26 UTC, Steven Schveighoffer wrote:
>> On Sun, 06 May 2012 21:02:28 -0400, bearophile  
>> <bearophileHUGS at lycos.com> wrote:
>>
>>> Or maybe you initially have written:
>>> auto r = 1.1L;
>>> And later you want to change the number to 1.0 and you fix it like  
>>> this:
>>> auto r = 1L;
>>> Now you have a little bug.
>>
>> Or maybe you have initially written:
>>
>> auto d = 1.1;
>> and later you want to change the number to 1.0 and you fix it like this:
>>
>> auto d = 1;
>>
>> Now you have a little bug.
>>
>> To me the problem of floating pt. vs. integral is orthogonal to the  
>> size of the integral/floating point.
>>
>> -Steve
>
> Since you use the suffix to disambiguate / explicitly specify the  
> type... it is extremely unintuitive if the type suddenly changes while  
> *keeping* the same suffix...
>

I concede that is a concern, but really, ".[0-9]" is the suffix that  
determines it's a floating point, not "L".  I almost think 1f should be an  
error, it should have to be 1.0f.  Ohhh, I thought of another example:

auto x = 0x1f;

Remove the 0x prefix, and you have:

auto x = 1f; // now a floating point 1 vs. integer 31

However, I think these examples are misleading and do not prove the  
point.  It shows IMO more that you are better off declaring the type on  
the left if your code depends on it always staying the same.

i.e. this does not have that problem:

real r = 1L;

-Steve


More information about the Digitalmars-d mailing list