# -----------------------------------------------------------------
#   DESCRIPTION:  The function returns the lesser of two numbers
#                 passed to the function as parameters.
#
#   PARAMETERS:  in a and in b - two numbers to get
#                the lesser of them
#
#   RETURN CODE:  Lesser of the two parameters
#                 passed to the function.
# -----------------------------------------------------------------
public function min(in a, in b)
{
  if (a > b)
	return(b);
  else
	return(a);
}

# -----------------------------------------------------------------
#   DESCRIPTION:  The function returns the greater of two numbers
#                 passed to the function as parameters.
#
#   PARAMETERS:  in a and in b - two numbers to get
#                the greater of them
#
#   RETURN CODE:  Greater of the two parameters
#                 passed to the function .
# -----------------------------------------------------------------
public function max(in a, in b)
{
   if (a > b)
	return(a);
   else
	return(b);
}

# -----------------------------------------------------------------
# The code above is placed into a Function Library
# Compiled Module
# -----------------------------------------------------------------


# -----------------------------------------------------------------
# The code below is run in the Init script or some other script.
# -----------------------------------------------------------------
generator_add_function ( "min"
 	, "The function returns the lesser of \n"
	& "two numbers passed to the function as parameters."
 	, 2
 	, "First Value", "type_edit", "1"
	, "Second Value", "type_edit", "2"
);

generator_add_function ( "max"
 	, "The function returns the greater of \n"
	& "two numbers passed to the function as parameters."
 	, 2
 	, "First Value", "type_edit", "1"
	, "Second Value", "type_edit", "2"
);


 generator_add_category("CAA Functions");
 generator_add_function_to_category("CAA Functions", "min");
 generator_add_function_to_category("CAA Functions", "max");

# -----------------------------------------------------------------
# After the code above has been run the Functions should exist
# in the "Insert Function from Function Generator" <F7>.
# -----------------------------------------------------------------


min1 = min ( 1, 2 );
printf ( "Minimum of 1 and 2 is %s\r\n", min1 );

max1 = max ( 1, 2 );
printf ( "Maximum of 1 and 2 is %s\r\n", max1 );

min2 = min ( 11.5, 18.2 );
printf ( "Minimum of 11.5 and 18.2 is %s\r\n", min2 );

max2 = max( 11.5, 18.2 );
printf ( "Maximum of 11.5 and 18.2 is %s\r\n", max2 );


