-3.6.floorToDouble()
I'd expect this to return -4, because floor() rounds towards negative infinty, but it actually returns -3. It basically acts like truncate(). Is this a bug in the dart sdk or implemented on purpose?
-3.6.floorToDouble()
I'd expect this to return -4, because floor() rounds towards negative infinty, but it actually returns -3. It basically acts like truncate(). Is this a bug in the dart sdk or implemented on purpose?
It's a parsing artifact.
The expression -3.6.floorToDouble() means -(3.6.floorToDouble()) because the postfix . binds stronger than the prefix -.
You need to parenthesize negative number literals when you immediately call methods on them. That's a remarkably rare thing to do in real programs — the methods on numbers are generally ones where you can predict the result and just write that as a literal instead.