What's so special about adding/subtracting 1 to/from a floating point value that it deserves a dedicated operator?
double a = -0.001234129;
a++; // ?
I've never felt the need to use such a construction; it looks really weird to me. But if I ever had to, I'd feel much more comfortable with just:
a += 1;
Maybe it's because of my strong C++ background, but to me it makes a variable look like an array indexer.
Is there any reason for this?
The ++
and --
operators operate on all other number types, why make an exception for floating point numbers? To me, that would be the more surprising choice.
Note that C++ also implements these for floating point:
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
double a = 0.5;
cout << a << '\n';
++a;
cout << a << '\n';
return 0;
}
Output:
0.5 1.5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With