Hide minor edits - Show changes to markup
max(a, 0); // mantener las operaciones fuera de la función.
max(a, 0); // mantener cualquier operación fuera de los paréntesis.
Debido a la forma en que la función max()es implementada, debes evitar usar otras funciones al definir los parámetros, puede derivar en resultados incorrectos.
Debido a la forma en que la función max() es implementada, debes evitar usar otras funciones al definir los parámetros, puede derivar en resultados incorrectos.
Calculates the maximum of two numbers.
x: the first number, any data type
y: the second number, any data type
The larger of the two parameter values.
sensVal = max(senVal, 20); // assigns sensVal to the larger of sensVal or 20
// (effectively ensuring that it is at least 20)
Perhaps counter-intuitively, max() is often used to constrain the lower end of a variable's range, while min() is used to constrain the upper end of the range.
Because of the way the max() function is implemented, avoid using other functions inside the brackets, it may lead to incorrect results
Calcula el máximo de dos números.
x: El primer número, cualquier tipo de dato.
y: El segundo número, cualquier tipo de dato.
El mayor de ambos parámetros.
sensVal = max(senVal, 20); // asigna a sensVal su propio valor o, de ser superior, 20.
// (una forma efectiva de asegurarse que el valor mínimo de senVal sea 20)
max() suele ser usado para restringir el valor más bajo del rango de una variable, mientras que min() es utilizado para restringir el valor máximo del rango.
Debido a la forma en que la función max()es implementada, debes evitar usar otras funciones al definir los parámetros, puede derivar en resultados incorrectos.
max(a--, 0); // avoid this - yields incorrect results
a--; // use this instead - max(a, 0); // keep other math outside the function
max(a--, 0); // evitar esto - puede dar resultados incorrectos.
a--; // en su lugar, hacerlo así - max(a, 0); // mantener las operaciones fuera de la función.
max(a, 0); // keep other math outside the function
max(a, 0); // keep other math outside the function
min(a, 100); // keep other math outside the function
max(a, 0); // keep other math outside the function
Because of the way the max() function is implemented, avoid using other functions inside the brackets, it may lead to incorrect results
max(a--, 0); // avoid this - yields incorrect results a--; // use this instead - min(a, 100); // keep other math outside the function
// (effectively ensuring that it is at least 20)
@]
// (effectively ensuring that it is at least 20)@]
Perhaps counter-intuitively, max() is often used to constrain the lower end of a variable's range, while min() is used to constrain the upper end of the range.
The larger of the two numbers.
The larger of the two parameter values.
[@sensVal = max(senVal, 20); // assigns sensVal to the bigger of sensVal or 20
[@sensVal = max(senVal, 20); // assigns sensVal to the larger of sensVal or 20
// (effectively ensuring that it is at least 20)
// (effectively ensuring that it is at least 20)
[@sensVal = max(senVal, 20); // assigns sensVal to the bigger of sensVal or 20 (effectively ensuring that it is at least 20)
[@sensVal = max(senVal, 20); // assigns sensVal to the bigger of sensVal or 20
// (effectively ensuring that it is at least 20)
[@sensVal = max(senVal, 20); // limits sensor value to at least 20
[@sensVal = max(senVal, 20); // assigns sensVal to the bigger of sensVal or 20 (effectively ensuring that it is at least 20)
max is useful for limiting the range a variable (say reading a sensor) can move. Even though the name max would seem to suggest it should be used to limit the sensor's maximum value, its real effect is to limit the variable's lowest value. This can be slightly counterintuitive.
Programmers coming to C from the BASIC language may also expect max to affect a variable without assigning the returned result to anything.
[@sensVal = max(senVal, 20); // limits sensor value to 20 MINIMUM
[@sensVal = max(senVal, 20); // limits sensor value to at least 20
Paradoxically, even though max would seem to limit the desired variable to a maximum value, it is really used to set the minimum value to which a variable can descend.
Programmers coming to C from the BASIC language may expect max to affect a variable without assigning the returned result to anything
max is useful for limiting the range a variable (say reading a sensor) can move. Even though the name max would seem to suggest it should be used to limit the sensor's maximum value, its real effect is to limit the variable's lowest value. This can be slightly counterintuitive.
Programmers coming to C from the BASIC language may also expect max to affect a variable without assigning the returned result to anything.
x: the first number
y: the second number
x: the first number, any data type
y: the second number, any data type
The bigger of the two numbers.
The larger of the two numbers.
sensVal = max(senVal, 20); // limits sensor value to 20 MINIMUM
Paradoxically, even though max would seem to limit the desired variable to a maximum value, it is really used to set the minimum value to which a variable can descend.
Programmers coming to C from the BASIC language may expect max to affect a variable without assigning the returned result to anything