"R" suffix for reals

bearophile bearophileHUGS at lycos.com
Sun May 6 15:49:11 PDT 2012


"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));
}

Bye,
bearophile


More information about the Digitalmars-d mailing list