GNU social JP
  • FAQ
  • Login
GNU social JPは日本のGNU socialサーバーです。
Usage/ToS/admin/test/Pleroma FE
  • Public

    • Public
    • Network
    • Groups
    • Featured
    • Popular
    • People

Conversation

Notices

  1. Embed this notice
    greenshoots (greenshoots@poa.st)'s status on Wednesday, 12-Feb-2025 00:27:53 JST greenshoots greenshoots
    • d
    @deprecated_ii Apologies for the long post.
    =================================

    What if it was a " i % 2 != 0 " inside the if statement? Would that have been ok? That way you'd only need one avaluation structure to fetch the odd numbers from the array.

    Unless the library already has a built in function to do this like an "array.nOdd(i)" that could be assigned to a new array.

    What would've been your answer to clean up this code? I don't know how to code, but I would like learn about this stuff from the opinion of people that do know.
    In conversation about 5 months ago from poa.st permalink
    • Embed this notice
      d (deprecated_ii@poa.st)'s status on Wednesday, 12-Feb-2025 00:27:53 JST d d
      in reply to
      @greenshoots the fast way to check if an integer is odd is to look at the least significant bit and see if it's a 1 or a 0. an odd number is always going to have a 1 as the least significant bit. so "if(Array[i] & 1) { do whatever };"

      for the sake of readability and clarity that check might be made in an "is_odd" function

      there's nothing "wrong" with the mod 2 method but depending on the language and how often the check is happening it might be a significant performance problem. but that's the kind of thing you shouldn't worry about until you see the problem in a performance profiler

      but yeah the core point is to reduce the check to a single operation that you can put any integer into
      In conversation about 5 months ago permalink
      :ihavenomouth: likes this.
    • Embed this notice
      :ihavenomouth: (inginsub@clubcyberia.co)'s status on Wednesday, 12-Feb-2025 00:31:11 JST :ihavenomouth: :ihavenomouth:
      in reply to
      • d
      @deprecated_ii @greenshoots any real compiler with optimizations will turn %2 into &1
      In conversation about 4 months ago permalink
    • Embed this notice
      d (deprecated_ii@poa.st)'s status on Wednesday, 12-Feb-2025 00:36:16 JST d d
      in reply to
      • :ihavenomouth:
      @Inginsub @greenshoots yeah

      but then there's python
      In conversation about 4 months ago permalink
      :ihavenomouth: likes this.

Feeds

  • Activity Streams
  • RSS 2.0
  • Atom
  • Help
  • About
  • FAQ
  • TOS
  • Privacy
  • Source
  • Version
  • Contact

GNU social JP is a social network, courtesy of GNU social JP管理人. It runs on GNU social, version 2.0.2-dev, available under the GNU Affero General Public License.

Creative Commons Attribution 3.0 All GNU social JP content and data are available under the Creative Commons Attribution 3.0 license.