How do I check if a number is positive or negative in C#?

前端 未结 17 1484
轻奢々
轻奢々 2020-12-04 05:55

How do I check if a number is positive or negative in C#?

17条回答
  •  我在风中等你
    2020-12-04 06:11

    This code takes advantage of SIMD instructions to improve performance.

    public static bool IsPositive(int n)
    {
      var v = new Vector(n);
      var result = Vector.GreaterThanAll(v, Vector.Zero);
      return result;
    }
    

提交回复
热议问题