^
is only defined for the integer-like types (byte
, short
, int
, long
, char
) and boolean
s.
In other words: exactly what the error message says. float
s are not legal operands for the ^
operator.
And that makes sense: most people wouldn't be able to tell what the binary representation of e.g. 23.42
is. Would you? (This is actually a trick question: you cannot even represent 23.42
in binary. The closest you can get is 23.4200000000000017053025658242
whose binary representation is 01000000 00110111 01101011 10000101 00011110 10111000 01010001 11101100
.)
If the ^
operator did work with float
s, it wouldn't be very obvious. E.g.
2.0 ^ 3.0
Would be
0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000111253692925360069154511635867
(I think, if I didn't make a mistake somewhere.)