Just need to add some code that saves the base stack pointer, detects when the stack is about to run out, then saves the current number, resets the stack to the original pointer but now with the current number as x and continues on to fix the stack overflow issue. You don’t even have to restore the stack when it’s all unwinding!
The integer overflow issue would be more complicated to solve except it isn’t really an issue because chopping off the upper bits doesn’t affect the eveness of a value.
Oh and I thought of a quick way to verify the result of the algorithm. It should give the same result as this expression that you can use in your test suite:
!(x & 1)
Edit: um, new formatting problem… And that amp shows up in the edit box so it might even keep expanding.
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: !programmerhumor@lemmy.ml
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
Posts must be relevant to programming, programmers, or computer science.
No NSFW content.
Jokes must be in good taste. No hate speech, bigotry, etc.
Just need to add some code that saves the base stack pointer, detects when the stack is about to run out, then saves the current number, resets the stack to the original pointer but now with the current number as x and continues on to fix the stack overflow issue. You don’t even have to restore the stack when it’s all unwinding!
The integer overflow issue would be more complicated to solve except it isn’t really an issue because chopping off the upper bits doesn’t affect the eveness of a value.
Oh and I thought of a quick way to verify the result of the algorithm. It should give the same result as this expression that you can use in your test suite:
Edit: um, new formatting problem… And that amp shows up in the edit box so it might even keep expanding.
The ampersand thing is a known bug in Lemmy. It has to do with input sanitation, as I understand.
Yeah looks like it’s sanitizing both on submit and when displaying.