Complete floating point literals

Simen Kjaeraas simen.kjaras at gmail.com
Sun Jul 10 11:13:32 PDT 2011


On Sun, 10 Jul 2011 19:51:10 +0200, Daniel Murphy  
<yebblies at nospamgmail.com> wrote:

> "bearophile" <bearophileHUGS at lycos.com> wrote in message
> news:ivcg7j$ooj$1 at digitalmars.com...
>> Jacob Carlborg reminds that 1.f conflicts with the UFCS, I think the
>> suggestion by Daniel Murphy of the special case is not worth it.
>>
>
> If the only reason for removing 1.f and 1.L is to aid ufcs we should also
> get rid of leading underscores after the decimal point.  eg 1._3 also
> conflicts with ufcs.  And don't forget hex floating point literals.

Now if f and L were functions taking an int as their first parameter,
they could be defined thusly:

@ufcs @property
float f(int n) {
     return n;
}

@ufcs @property
double L(long n) {
     return n;
}

Furthermore, magic could be added:

@ufcs @property
auto opDispatch(string name)(int n) if (isValidHexString(name)) {
     static if (too many digits for real) {
         return BigFloat(to!string(n) ~ "." ~ name);
     } else {
         // convert to real and return
     }
}


See? Marvellous! :p
-- 
   Simen


More information about the Digitalmars-d mailing list