I just need an even/odd functionality. Don't think D has a built-in operator.

// Found this C code online.

    int isEven(int num)
    {
        return !(num & 1);
    }

// found this in std.functional.unaryFun

alias isEven = unaryFun!("(a & 1) == 0");
assert(isEven(2) && !isEven(1));

If interested just in speed, is either one faster?
  • quick question, ... WhatMeWorry via Digitalmars-d-learn
    • Re: quick q... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
      • Re: qui... WhatMeWorry via Digitalmars-d-learn
        • Re:... H. S. Teoh via Digitalmars-d-learn
        • Re:... Richard (Rikki) Andrew Cattermole via Digitalmars-d-learn
        • Re:... Cecil Ward via Digitalmars-d-learn
          • ... Cecil Ward via Digitalmars-d-learn

Reply via email to