FreeBSD/contrib/ntp/ntpdate/ntpdate.c
/*
 * clock_filter - determine a server's delay, dispersion and offset
 */
determine a server's delay, dispersion and offset
determine a server ' s delay dispersion and offset
static void
clock_filter(
	register struct server *server
	)
{
	register int i, j;
	int ord[NTP_SHIFT];
	for (i = 0; i < sys_samples; i++)
		ord[i] = i;
	for (i = 0; i < (sys_samples-1); i++) {
		for (j = i+1; j < sys_samples; j++) {
			if (server->filter_delay[ord[j]] == 0)
				continue;
			if (server->filter_delay[ord[i]] == 0
				|| (server->filter_delay[ord[i]]
				> server->filter_delay[ord[j]])) {
				register int tmp;
				tmp = ord[i];
				ord[i] = ord[j];
				ord[j] = tmp;
			}
		}
	}
	if (server->filter_delay[ord[0]] == 0) {
		server->delay = 0;
		L_CLR(&server->offset);
		server->soffset = 0;
		server->dispersion = PEER_MAXDISP;
	} else {
		register s_fp d;
		server->delay = server->filter_delay[ord[0]];
		server->offset = server->filter_offset[ord[0]];
		server->soffset = LFPTOFP(&server->offset);
		server->dispersion = 0;
		for (i = 1; i < sys_samples; i++) {
			if (server->filter_delay[ord[i]] == 0)
				d = PEER_MAXDISP;
			else {
				d = server->filter_soffset[ord[i]]
					- server->filter_soffset[ord[0]];
				if (d < 0)
					d = -d;
				if (d > PEER_MAXDISP)
					d = PEER_MAXDISP;
			}
			server->dispersion += (u_fp)(d) >> i;
		}
	}
}
static void clock_filter ( register struct server * server ) { register int i , j ; int ord [ NTP_SHIFT ] ; for ( i = 0 ; i < sys_samples ; i ++ ) ord [ i ] = i ; for ( i = 0 ; i < ( sys_samples - 1 ) ; i ++ ) { for ( j = i + 1 ; j < sys_samples ; j ++ ) { if ( server -> filter_delay [ ord [ j ] ] == 0 ) continue ; if ( server -> filter_delay [ ord [ i ] ] == 0 || ( server -> filter_delay [ ord [ i ] ] > server -> filter_delay [ ord [ j ] ] ) ) { register int tmp ; tmp = ord [ i ] ; ord [ i ] = ord [ j ] ; ord [ j ] = tmp ; } } } if ( server -> filter_delay [ ord [ 0 ] ] == 0 ) { server -> delay = 0 ; L_CLR ( & server -> offset ) ; server -> soffset = 0 ; server -> dispersion = PEER_MAXDISP ; } else { register s_fp d ; server -> delay = server -> filter_delay [ ord [ 0 ] ] ; server -> offset = server -> filter_offset [ ord [ 0 ] ] ; server -> soffset = LFPTOFP ( & server -> offset ) ; server -> dispersion = 0 ; for ( i = 1 ; i < sys_samples ; i ++ ) { if ( server -> filter_delay [ ord [ i ] ] == 0 ) d = PEER_MAXDISP ; else { d = server -> filter_soffset [ ord [ i ] ] - server -> filter_soffset [ ord [ 0 ] ] ; if ( d < 0 ) d = - d ; if ( d > PEER_MAXDISP ) d = PEER_MAXDISP ; } server -> dispersion += ( u_fp ) ( d ) >> i ; } } }
clock_filter - determine a server's delay, dispersion and offset
clock_filter - determine a server ' s delay dispersion and offset
/*
	 * Sort indices into increasing delay order
	 */ /*
	 * Now compute the dispersion, and assign values to delay and
	 * offset.	If there are no samples in the register, delay and
	 * offset go to zero and dispersion is set to the maximum.
	 */ /*
			 * XXX This *knows* PEER_FILTER is 1/2
			 */ /*
	 * We're done
	 */