You are viewing a single comment's thread. Return to all comments →
That messed me up. I casted and was not able to get the as long value. Once I remove it worked.
We do not need to cast explicitly. We are just required to check the applicable ranges.
if(x>=-128 && x<=127)
if(x>=-(Math.pow(2,15)) && x<=(Math.pow(2,15)-1))
if(x>=-(Math.pow(2,31)) && x<=(Math.pow(2,31)-1))
if(x>=-(Math.pow(2,63)) && x<=(Math.pow(2,63)-1))
i tried using appying the range directly but i couldnt able to clear two test cases
u added pow function but i tried with entering the range values like for byte -128 to 127 but i am not able to clear the 2 testcases among 4
same here, could u help.
you will not be able to clear the test cases if u use that method because th range of because the range of int and long are very large to be inputted xplicitly like if u enter 2147483648 which is the rangeof int is verylarge value for compiler
I meant something like Byte.Max() which does not require any literal number to be input but will always be dependant on the compiler...
You must have used if(x>=-Math.pow(2,31) && x=-Math.pow(2,31) && x<= Math.pow(2,31)-1 )
and also for long ""x<=Math.pow(2,63)-1""
but then..i thnk this wont work?
Yes it worked for me as well. Thanks.
pow() returns a double and casting it explicitly causing problems.
Without casting it works fine and clears all Test cases.
but pow() returns the value in double data type?isn't it?
Casting is necessary because Math.pow function returns value in double