Threadwell

Recent Notes

  • DemetriSpanos

    Oct 06, 2026

    • archive
    • twitter
    • demetrispanos
  • NOTimothyLottes

    Oct 06, 2026

    • archive
    • twitter
    • notimothylottes
  • bonzajplc

    Oct 06, 2026

    • archive
    • twitter
    • bonzajplc
Home

❯

Archive

❯

Threads

❯

EricLengyel

❯

Needs repeating: You can always perform a signed integer range test with a single comparison.

Needs repeating: You can always perform a signed integer range test with a single comparison.

Properties5
typearchive
sourcetwitter
date2017-05-26
tagsarchive, twitter, ericlengyel
descriptionNeeds repeating: You can always perform a signed integer range test with a single comparison.

May 26, 20171 min read

  • archive
  • twitter
  • ericlengyel

Source

  • URL: https://x.com/EricLengyel/status/867967467770920960
  • Author: Eric Lengyel (@EricLengyel)
  • Posted: 2017-05-26 04:55:45

Thread

1/ @EricLengyel

Needs repeating: You can always perform a signed integer range test with a single comparison. unsigned(x - lo) <= unsigned(hi - lo)

Branches: 2017-05-26-vaughncato-shouldnt-that-be-unsigned-x-unsigned-lo-unsigned, 2017-05-26-vaughncato-otherwise-ub-if-hi-int-max-and-lo-int-min, 2017-05-26-noop_dev-yeah-this-is-one-of-the-things-coworkers-hate-me, 2017-05-27-sreekotay-one-of-my-favs-and-special-cases-possible-for

4 items under this folder.

  • May 27, 2017

    @EricLengyel @Atrix256 One of my favs.

    • archive
    • twitter
    • ericlengyel
  • May 26, 2017

    @EricLengyel @dsuoch Yeah, this is one of the things coworkers hate me for

    • archive
    • twitter
    • ericlengyel
  • May 26, 2017

    @EricLengyel Otherwise UB if hi == INT_MAX and lo == INT_MIN

    • archive
    • twitter
    • ericlengyel
  • May 26, 2017

    @EricLengyel Shouldn't that be `unsigned(x)-unsigned(lo) <= unsigned(hi)-unsigned(lo)`

    • archive
    • twitter
    • ericlengyel

Created with Quartz v5.0.0 © 2026

  • GitHub