FloatPoint unexpected rounding with dot syntax

I see a little confusing thing:

-5.9.rounded(.down) // -5
(-5.9).rounded(.down) // -6

It seems that -5.9.rounded(.down) is treated as -(5.9.rounded(.down)).

Is it expected?


1 Like

Yes, but in opinion it is not expected and natural. Is there any robust arguments for such rules? Should I report a bug at Issues · apple/swift · GitHub? @xwu

This is how ~every roughly similar language’s grammar works, FWIW. It might have been interesting to do it otherwise in Swift 1, but it would have been swimming against the weight of precedent from other languages then, and would be source-breaking today.

Requiring parentheses to disambiguate prefix/postfix expressions would be interesting to explore.


Saying ''Requiring parentheses to disambiguate prefix/postfix expressions" you mean a warning, requiring to write either -(5.9.rounded(.down)) or (-5.9).rounded(.down) ?

An error rather than a warning, but yes.