My temporary PHP fix from 2014 has nearly 20M installs. Today I'm deprecating it
Thread
Unofficial Hacker News client; not affiliated with Y Combinator.
My temporary PHP fix from 2014 has nearly 20M installs. Today I'm deprecating it
Unofficial Hacker News client; not affiliated with Y Combinator.
jakeasmith · · focus · HN ↗
HackerThemAll · · focus · HN ↗
<a href="https://www.npmjs.com/package/is-odd" rel="nofollow">https://www.npmjs.com/package/is-odd
<a href="https://www.npmjs.com/package/is-even" rel="nofollow">https://www.npmjs.com/package/is-even
<a href="https://www.npmjs.com/package/left-pad" rel="nofollow">https://www.npmjs.com/package/left-pad
<a href="https://www.npmjs.com/package/is-whitespace-character" rel="nofollow">https://www.npmjs.com/package/is-whitespace-character
<a href="https://www.npmjs.com/package/isarray" rel="nofollow">https://www.npmjs.com/package/isarray
JaggerJo · · focus · HN ↗
junon · · focus · HN ↗
So of course they don't make sense now. But they were created for a reason. Before even Markov chains were a fad - let alone LLMs - we were trying to be as efficient as possible and maximize code reuse I stead of writing the same helper functions over and over again. That's what you're seeing.
IncreasePosts · · focus · HN ↗
Ut oh, your code is broken for negative numbers now since % isn't a true modulo operator...
Fine then, isOdd = (x) => x % 2 != 0
Ut oh, your code is broken because isOdd("hi") returns true now...
Fine then, isOdd = (x) => if(!isNumber(x)) throw... else return x%2 != 0
Ut oh, your code is now broken because isOdd(2^55+1) returns true now...
Dylan16807 · · focus · HN ↗
I think you messed up this example. Whether I literally use "2^55" with XOR or replace it with "2*55", that version of isOdd returns false.
False for isOdd(58) is obviously correct. (Also thanks C for permanently screwing up the precedence of bitwise operations because you didn't want to break some existing programs in 1972.)
False for isOdd(36028797018963970) is also correct, and if you expected to send in a different number the bug is in the "+1" not the isOdd.
IncreasePosts · · focus · HN ↗
2 to the 55th power is obviously even, so that +1 is obviously odd, but ((2*55) +1) % 2 == 0 in JavaScript.
Dylan16807 · · focus · HN ↗
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 · · focus · HN ↗
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 · · focus · HN ↗
You have a plus and an exponentiation in there. That's code.
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.