0

Is there such a thing as a Limit operator that lets you control the maximum or minium value of a variable.

if variable > value then variable = value

My question is not language specific, but answers in different languages are appreciated (esp. Delhpi).

I know operators differ from language to language, but mostly in syntax.

Would an operator like this be usefull enough?

4

2 回答 2

1

某些语言具有可用于此目的的“min”运算符:variable = min(variable, limit)

于 2013-06-07T09:58:21.327 回答
0

基本上,运算符只不过是一个函数。

一元运算符如 ! (not) 可以用函数 Boolean not(Boolean) 映射

像 + (plus) 这样的二元运算符可以用函数 Integer plus(Integer, Integer) 进行映射

...

因此,您可以自己将任何缺少的“运算符”定义为函数。许多语言不允许您自己定义运算符。在 Groovy 中,您可以重载现有的运算符:

http://groovy.codehaus.org/Operator+Overloading

于 2013-06-07T10:04:49.103 回答