3 ms·
Sorry, it's supposed to be power. So 2**55 in JavaScript 2 to the 55th power is obviously even, so that +1 is obviously odd, but ((2*55) +1) % 2 == 0 in JavaSc
by IncreasePosts 9d ago
Sorry, it's supposed to be power. So 2**55 in JavaScript
2 to the 55th power is obviously even, so that +1 is obviously odd, but ((2*55) +1) % 2 == 0 in JavaScript.
- Dylan16807 9d agoBut there's no bug in isOdd. You're sending the number 36028797018963970 into it, which is clearly even. Putting extra code between the parentheses of the function call doesn't make it the function's responsibility. As nice as it would be for debugging if you could stuff your entire program inside of isNaN((function(){ /* your code here */ })()) and force your browser vendor to fix all problems.
- IncreasePosts 8d agoYou should check the math on a real calculator. Despite what most JavaScript implementations will tell you, 2 to the 55th power is 36028797018963968, and adding one to that value is 36028797018963969. That's clearly odd. There is no extra code between the parens. I just put them there so there wouldn't be any question as to operator precedence. I do see now that hn ate my double star, but I think you know what I mean since you told me the value that is spits out when you do the exponentiation
- Dylan16807 8d ago> There is no extra code between the parens. You have a plus and an exponentiation in there. That's code. var n = 2**55 + 1 console.log(n) isOdd(n) n is 36028797018963970. isOdd(n) is giving you the right answer. Putting the +1 inside the parentheses and talking about calculators is a sleight of hand that lets you pretend isOdd gets an odd number, but it doesn't. No odd numbers are around by the time isOdd actually does anything. The problems are in + and/or our expectations of +. It does not output 36028797018963969, and we must acknowledge that.