****************************************
*	 Prozeßnummer = 1
*	 Delay = 1000
*	 Eventsource = 0
*	 Number of Loops = 0
*	 Priorität = 0
*	 Version = 1
*	 FastStop = 0
*	 AdbasicVersion = 3020001
*	 ATSRAM = 0
*	 OPT_LEVEL = 1
*	 SAVECOMPIL = 0
****************************************
'<ADbasic Header, Headerversion 001.001>
'<Header End>
#DEFINE PI 4*arctan(1)

FUNCTION CEIL(value) AS FLOAT
  DIM floatValue AS FLOAT
  DIM integerValue AS INTEGER
	
  floatValue = value + 0.5
  integerValue = floatValue	
  CEIL = integerValue
ENDSUB

FUNCTION FLOOR(value) AS FLOAT
  DIM integerValue AS INTEGER
	
  integerValue = value	
  FLOOR = value
ENDSUB

FUNCTION TRUNC(value) AS INTEGER
	
  TRUNC = FLOOR(value)
ENDSUB


FUNCTION POWER(xValue,yValue) AS FLOAT
	
  POWER = xValue^(yValue)
ENDSUB

FUNCTION SIGN(xValue) AS FLOAT
  if(xValue > 0) then SIGN=1 endif
  if(xValue = 0) then SIGN=0 endif
  if(xValue < 0) then SIGN=-1 endif
ENDSUB

FUNCTION UPFRONT(value1, value2) AS INTEGER
	UPFRONT = 0
	if(value1 = 0) then
		if(value2 = 1) then
			UPFRONT = 1
		endif
	endif	
ENDSUB

FUNCTION MEDIAN(value1, value2, value3) AS FLOAT

	if(value1 > value2) then
		
		if(value1 > value3) then			
			if(value2 > value3) then
				MEDIAN = value2
			else
				MEDIAN = value3
			endif		
		else			
			MEDIAN = value1			
		endif
	
	else
	
		if(value1 < value3) then			
			if(value2 > value3) then
				MEDIAN = value3
			else
				MEDIAN = value2
			endif		
		else			
			MEDIAN = value1			
		endif
	
	endif

ENDSUB

FUNCTION BINARY_MEDIAN(value1, value2, value3) AS INTEGER
	DIM v1, v2, v3 AS INTEGER
	v1 = value1
	v2 = value2
	v3 = value3
	BINARY_MEDIAN = v1 AND v2 AND v3
ENDSUB
