In java byte b=1+(byte)(5.0); is valid But byte b=1+(byte)(Math.sqrt(25)); is invalid What's happening here? Both seem exactly the same as sqrt function also has double sa return type. Does something change when function calls are involved?
Asked
Active
Viewed 50 times
0
-
`b=(byte)(1+Math.sqrt(25));` would solve this. – JGFMK Feb 13 '22 at 11:12
-
Yeah. But I was trying to understand why is it happening – P S Feb 13 '22 at 11:33
-
2I think it's because the literal 5.0 + 1 can not blow the byte limit, whereas the compiler does not inspect sqrt for literals to determine the outcome... i.e. an arithimetic operation has to be performed.. that's outside the realms of the compiler, which the former (literal formula) could cope with. – JGFMK Feb 13 '22 at 18:39