"R" suffix for reals
Jonathan M Davis
jmdavisProg at gmx.com
Sun May 6 17:17:59 PDT 2012
On Monday, May 07, 2012 00:49:11 bearophile wrote:
> "R" suffix for reals
>
> This is small enhancement suggestion :-) (Issue 8049).
>
> The "f" suffix turns a number literal without "." into a float,
> while "L" requires a "." in the number literal, otherwise you
> have defined a literal of type long:
>
>
> void main() {
> auto x1 = 1f;
> static assert(is(typeof(x1) == float));
> auto x2 = 1L;
> static assert(is(typeof(x2) == long));
> auto x3 = 1.0L;
> static assert(is(typeof(x3) == real));
> }
>
> D has "auto" for local inferencing, so this suffix is able to
> cause some problems.
>
> So what do you think about introducing a more specific and less
> bug-prone suffix like "R" (eventually using "L" to denote
> longs only):
>
> void main() {
> auto x = 1R;
> static assert(is(typeof(x) == real));
> }
And what is so onerous about having to do 1.0L instead of 1R? 1L is clearly a
long, whereas 1.0L is clearly a floating point value (it would have to be
either double or real, and apparently it's real). We _could_ add R, but I
don't really see what it buys us.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list