LBRY Block Explorer

LBRY Claims • don’t-let-floor-division-ruin-your-day

4839d9328647c34fb0819b5e2025218b4982f2b0

Published By
Anonymous
Created On
12 Aug 2021 01:46:24 UTC
Transaction ID
Cost
Safe for Work
Free
Yes
Don’t Let Floor Division Ruin Your Day
Floor division is the default for C, Python 2, POSIX Shell (NOT Zsh), bash, and Go. But there’s a good chance what happens with you divide three by two isn’t what you expect, at first. Would expect 3/2 = 1? Probably not, but that is exactly what floor division is. To get around this, always add a decimal point to your number when you care about such things (3.0/2=1.5). There’s not much more do say about this except to make sure the language you are using does what you expect.<br /><br />Another safety measure is to never do direct equality when checking conditions involving numbers. Use greater than or less than since they will always work, even if you make a mistake like the one involving floor division, to a point.<br /><br />Thanks sponsors, subs, and followers:<br /><br />- GitHub: <a href="https://github.com/sponsors/rwxrob" target="_blank" rel="nofollow">https://github.com/sponsors/rwxrob</a><br />- Twitch: <a href="https://www.twitch.tv/subs/rwxrob" target="_blank" rel="nofollow">https://www.twitch.tv/subs/rwxrob</a><br />- Twitter: <a href="https://twitter.com/rwxrob" target="_blank" rel="nofollow">https://twitter.com/rwxrob</a><br />- Discord: <a href="https://discord.com/invite/9wydZXY" target="_blank" rel="nofollow">https://discord.com/invite/9wydZXY</a><br /><br />[ZETID:20210811224641]<br /><a href="https://github.com/rwxrob/zet/tree/main/20210811224641" target="_blank" rel="nofollow">https://github.com/rwxrob/zet/tree/main/20210811224641</a><br />...<br /><a href="https://www.youtube.com/watch?v=5i4YustK0tA" target="_blank" rel="nofollow">https://www.youtube.com/watch?v=5i4YustK0tA</a>
Author
Content Type
Unspecified
video/mp4
Language
English
Open in LBRY