Limne
Limne

Reputation: 133

Which operators are defined for each of the base types?

Having used C# I was surprised to discover that C++ floats did not have the modulus operator defined. Nor are the bitwise operators apparently. I decided to learn more and went looking for a chart of which base types had operators defined for them and which did not but I couldn't find anything of that nature.

I know what all the operators are and how to overload them: http://en.wikipedia.org/wiki/C%2B%2B_operators

I do not, however, know which operators are defined for each of the base types.

Upvotes: 1

Views: 83

Answers (1)

Mats Petersson
Mats Petersson

Reputation: 129314

All operators are defined for integer types (char, short, int, long, long long and enum). For floating point types (float, double and long double), you don't have % and none of the "bitwise" operators: <<, >>, ~, &, | and ^, since they don't make much sense for floating point. For example, what do you expect from 3.3 ^ 6.8? [1] Or 1.9 % 13.4? [1] There is no "remainder" in a floating point divide, so it's hard to envisage what it actually should give.

As mentioned in the comment, fmod does a similar thing to %.

[1] These are rhetorical questions, I don't expect anyone to come up with a good answer.

Upvotes: 1

Related Questions