Reference.Max History

Hide minor edits - Show changes to output

February 06, 2010, at 09:26 AM by David A. Mellis -
Changed lines 38-40 from:
* [[Mathh|math.h]]

to:

February 06, 2010, at 02:48 AM by Paul Badger -
Changed lines 38-39 from:

to:
* [[Mathh|math.h]]

January 27, 2009, at 12:53 PM by Paul Badger -
Changed line 30 from:
max(a, 0); // keep other math outside the function
to:
max(a, 0); // keep other math outside the function
January 27, 2009, at 12:25 PM by David A. Mellis -
Changed line 30 from:
min(a, 100); // keep other math outside the function
to:
max(a, 0); // keep other math outside the function
January 27, 2009, at 06:53 AM by Paul Badger -
January 27, 2009, at 06:52 AM by Paul Badger -
Changed lines 23-33 from:
to:
!!!!Warning
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
@]

November 04, 2007, at 05:30 AM by Paul Badger -
Changed lines 19-21 from:
// (effectively ensuring that it is at least 20)
@]
to:
// (effectively ensuring that it is at least 20)@]
November 04, 2007, at 05:30 AM by Paul Badger -
Added lines 22-25:
!!!!Note
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.

November 04, 2007, at 05:24 AM by Paul Badger -
Changed lines 15-16 from:
The larger of the two numbers.
to:
The larger of the two parameter values.
November 04, 2007, at 05:24 AM by Paul Badger -
Changed line 18 from:
[@sensVal = max(senVal, 20); // assigns sensVal to the bigger of sensVal or 20
to:
[@sensVal = max(senVal, 20); // assigns sensVal to the larger of sensVal or 20
November 04, 2007, at 05:23 AM by Paul Badger -
Changed line 19 from:
// (effectively ensuring that it is at least 20)
to:
// (effectively ensuring that it is at least 20)
November 04, 2007, at 05:23 AM by Paul Badger -
Changed lines 18-19 from:
[@sensVal = max(senVal, 20); // assigns sensVal to the bigger of sensVal or 20 (effectively ensuring that it is at least 20)
to:
[@sensVal = max(senVal, 20); // assigns sensVal to the bigger of sensVal or 20
// (effectively ensuring that it is at least 20)
April 16, 2007, at 06:05 PM by Paul Badger -
Changed line 26 from:
[[HomePage | Reference Home]]
to:
April 16, 2007, at 09:12 AM by David A. Mellis -
Changed line 18 from:
[@sensVal = max(senVal, 20); // limits sensor value to at least 20
to:
[@sensVal = max(senVal, 20); // assigns sensVal to the bigger of sensVal or 20 (effectively ensuring that it is at least 20)
Deleted lines 20-24:
!!!!Tips
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.
April 15, 2007, at 03:49 AM by Paul Badger -
Changed lines 17-18 from:
!!!!Examples
[@sensVal = max(senVal, 20); // limits sensor value to 20 MINIMUM
to:
!!!!Example
[@sensVal = max(senVal, 20); // limits sensor value to at least 20
Changed lines 21-26 from:
!!!!Common Programming Errors
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

to:
!!!!Tips
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.
April 14, 2007, at 06:11 AM by Paul Badger -
Changed lines 9-12 from:
x: the first number

y: the second number
to:
x: the first number, any data type

y: the second number, any data type
Changed lines 15-16 from:
The bigger of the two numbers.
to:
The larger of the two numbers.

!!!!Examples
[@sensVal = max(senVal, 20); // limits sensor value to 20 MINIMUM
@]

!!!!Common Programming Errors
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

December 02, 2006, at 07:00 PM by David A. Mellis -
Changed lines 20-22 from:
* [[constrain]]()
to:
* [[constrain]]()

[[HomePage | Reference Home]]
December 02, 2006, at 06:10 PM by David A. Mellis -
Added lines 1-20:
!!max(x, y)

!!!!Description

Calculates the maximum of two numbers.

!!!!Parameters

x: the first number

y: the second number

!!!!Returns

The bigger of the two numbers.

!!!!See also

* [[min]]()
* [[constrain]]()

Share