Mini-proposal: Integral Floating Point Literals: 42f

1,406 views
Skip to first unread message

Andrew Tomazos

unread,
Mar 11, 2020, 3:08:43 AM3/11/20
to std-pr...@isocpp.org
It's standard behaviour that the token 42f is ill-formed and not a floating-point literal:

    float a = 42f; // ERROR

whereas this works:

    float a = 42.0f; // OK

and as not many people know this works:

    float a = 42.f; // OK

This is because:

    decimal-floating-point-literal:
        fractional-constant exponent-part_opt floating-point-suffix_opt
        digit-sequence exponent-part floating-point-suffix_opt

    fractional-constant:
        digit-sequence_opt . digit-sequence
        digit-sequence .

I wonder why we need the redundant `.0` or `.`?  What would we think of a proposal that allows an integer to be followed by `f`?

As in:

    decimal-floating-point-literal:
        fractional-constant exponent-part_opt floating-point-suffix_opt
        digit-sequence exponent-part floating-point-suffix_opt
        digit-sequence float-floating-point-suffix

    float-floating-point-suffix: one of
        f F

Where a `decimal-floating-point-literal` of the form `digit-sequence float-floating-point-suffix`, DF, where D is the `digit-sequence` and F is the `float-floating-point-suffix`, is equivalent to D.0F


Reply all
Reply to author
Forward
0 new messages