clamp


Description:

[ CCode ( cname = "CLAMP" ) ]
public unichar clamp (unichar low, unichar high)

Ensures that x is between the limits set by low and high. If low is greater than high the result is undefined.

For example:

 CLAMP(5, 10, 15) is 10.
CLAMP(15, 5, 10) is 10.
CLAMP(20, 15, 25) is 20.

Example: Clamp:

public static int main (string[] args) {
// Output: ``j``
unichar c = ((unichar) 'e').clamp ('j', 'o');
print ("%s\n", c.to_string ());

// Output: ``j``
c = ((unichar) 'o').clamp ('e', 'j');
print ("%s\n", c.to_string ());

// Output: ``t``
c = ((unichar) 't').clamp ('o', 'y');
print ("%s\n", c.to_string ());

return 0;
}

valac --pkg glib-2.0 unichar.clamp.vala

Parameters:

low

the minimum value allowed

high

the maximum value allowed

Returns:

the value of x clamped to the range between low and high