• backgroundcow@lemmy.world
    link
    fedilink
    arrow-up
    0
    ·
    1 year ago

    Ackchyually-- IEEE 754 guarantees any integer with absolute value less than 2^24 to be exactly representable as a single precision float. So, the “divide by 2, check for decimals” should be safe as long as the origin of the number being checked is somewhat reasonable.

    • Chobbes@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      1 year ago

      Of course, but it’s somewhat nasty when all of a sudden is_even doesn’t do what you expect :).