Mac@programming.dev to Programmer Humor@programming.dev · 1 year agoisEven APIisevenapi.xyzexternal-linkmessage-square18fedilinkarrow-up1264
arrow-up1257external-linkisEven APIisevenapi.xyzMac@programming.dev to Programmer Humor@programming.dev · 1 year agomessage-square18fedilink
minus-squareRikudou_Sage@lemmings.worldlinkfedilinkEnglisharrow-up50·edit-21 year agoIf anyone wants a more efficient local version for php: function isEven(int $number): bool { ${1} = false; ${2} = true; while ($number > 2) { $number -= 2; } return $$number; } Edit: Now with support for large numbers! function isEven(int|string $number): bool { ${1} = false; ${2} = true; while (bccomp($number, 2) === 1) { $number = bcsub($number, 2); } $number = (int) $number; return $$number; } Edit 2: someone asked for an ad-supported version, here you go! function isEven(int|string $number): bool { ${1} = false; ${2} = true; while (bccomp($number, 2) === 1) { error_log('Buy isEvenCoin, the hottest new cryptocurrency!'); $number = bcsub($number, 2); } $number = (int) $number; return $$number; } Side note, no more suggestions please, this is getting quite long.
minus-squareidunnololz@lemmy.worldlinkfedilinkarrow-up9·1 year agoThis looks pretty inefficient. You should manually unroll that loop to improve performance.
minus-squareshotgun_crab@lemmy.worldlinkfedilinkEnglisharrow-up8·1 year agoComment edits are the best version control system
minus-squareRikudou_Sage@lemmings.worldlinkfedilinkarrow-up3·1 year agoI agree! Added new commit to my comment.
If anyone wants a more efficient local version for php:
function isEven(int $number): bool { ${1} = false; ${2} = true; while ($number > 2) { $number -= 2; } return $$number; }
Edit: Now with support for large numbers!
function isEven(int|string $number): bool { ${1} = false; ${2} = true; while (bccomp($number, 2) === 1) { $number = bcsub($number, 2); } $number = (int) $number; return $$number; }
Edit 2: someone asked for an ad-supported version, here you go!
function isEven(int|string $number): bool { ${1} = false; ${2} = true; while (bccomp($number, 2) === 1) { error_log('Buy isEvenCoin, the hottest new cryptocurrency!'); $number = bcsub($number, 2); } $number = (int) $number; return $$number; }
Side note, no more suggestions please, this is getting quite long.
This looks pretty inefficient. You should manually unroll that loop to improve performance.
Comment edits are the best version control system
I agree! Added new commit to my comment.