www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Floating Point Literals: float (f) and real (L) suffix issue

reply kdevel <kdevel vogtner.de> writes:
suffix.d
```
void main ()
{
    real r = 1.L;
    float f = 1.f;
}
```

$ dmd suffix.d
suffix.d(3): Error: no property 'L' for type 'int'
suffix.d(4): Error: no property 'f' for type 'int'

According to the grammar in dmd2/html/d/spec/lex.html both are 
valid FloatLiterals. Any comments?
Jan 12
parent reply kdevel <kdevel vogtner.de> writes:
On Friday, 12 January 2018 at 12:45:59 UTC, kdevel wrote:
 suffix.d
 ```
 void main ()
 {
    real r = 1.L;
    float f = 1.f;
 }
 ```

 $ dmd suffix.d
 suffix.d(3): Error: no property 'L' for type 'int'
 suffix.d(4): Error: no property 'f' for type 'int'

 According to the grammar in dmd2/html/d/spec/lex.html both are 
 valid FloatLiterals. Any comments?
Just found this on the same page | If a floating literal has a . and a type suffix, at least one digit must be in-between: | | 1f; // OK | 1.f; // forbidden | 1.; // OK, double Is there a rational for this restriction?
Jan 12
parent Simen =?UTF-8?B?S2rDpnLDpXM=?= <simen.kjaras gmail.com> writes:
On Friday, 12 January 2018 at 12:57:37 UTC, kdevel wrote:
 On Friday, 12 January 2018 at 12:45:59 UTC, kdevel wrote:
 suffix.d
 ```
 void main ()
 {
    real r = 1.L;
    float f = 1.f;
 }
 ```

 $ dmd suffix.d
 suffix.d(3): Error: no property 'L' for type 'int'
 suffix.d(4): Error: no property 'f' for type 'int'

 According to the grammar in dmd2/html/d/spec/lex.html both are 
 valid FloatLiterals. Any comments?
Just found this on the same page | If a floating literal has a . and a type suffix, at least one digit must be in-between: | | 1f; // OK | 1.f; // forbidden | 1.; // OK, double Is there a rational for this restriction?
int foo(int n) { return n * 2; } assert(2.foo == 4); Now simply replace foo with f or L. I believe this ambiguity is the whole reason. -- Simen
Jan 12