Where can I find the “clamp” function in .NET?

前端 未结 9 1067
野的像风
野的像风 2020-11-27 04:24

I would like to clamp a value x to a range [a, b]:

x = (x < a) ? a : ((x > b) ? b : x);

This is quite basic

9条回答
  •  离开以前
    2020-11-27 05:06

    There isn't one in the System.Math namespace.

    There is a MathHelper Class where it is available for the XNA game studio if that happens to be what you are doing:

提交回复
热议问题