src/tse/test.c
void rms_error(const char *name, float x0, float x1, float dx, float (*f0)(float), float (*f1)(float)) {
	float x = x0;
	float max_err = FLT_MIN;
	float min_err = FLT_MAX;
	float sum_err2 = 0.f;
	int n = 0;
	while (x < x1) {
		float y0 = f0(x);
		float y1 = f1(x);
		float err = fabsf(y1 - y0);
		//log_debug("x %f y0 %f y1 %f err %f", x, y0, y1, err);
		sum_err2 += err * err;
		if (err < min_err) {
			min_err = err;
		}
		if (err > max_err) {
			max_err = err;
		}
		x += dx;
		n++;
	}
	float rms_err = sqrtf(sum_err2 / (float)n);
	log_info("%s: min %f max %f rms %f", name, min_err, max_err, rms_err);
}
//-----------------------------------------------------------------------------
// Error Analysis
// Compare a "fast" function against the known-accurate "slow" function
// Log the error stats to see how good the fast function is.
Error Analysis
Compare a "fast" function against the known-accurate "slow" function
Log the error stats to see how good the fast function is.
Error Analysis Compare a " fast " function against the known - accurate " slow " function Log the error stats to see how good the fast function is .
void rms_error(const char *name, float x0, float x1, float dx, float (*f0)(float), float (*f1)(float)) {
	float x = x0;
	float max_err = FLT_MIN;
	float min_err = FLT_MAX;
	float sum_err2 = 0.f;
	int n = 0;
	while (x < x1) {
		float y0 = f0(x);
		float y1 = f1(x);
		float err = fabsf(y1 - y0);
		sum_err2 += err * err;
		if (err < min_err) {
			min_err = err;
		}
		if (err > max_err) {
			max_err = err;
		}
		x += dx;
		n++;
	}
	float rms_err = sqrtf(sum_err2 / (float)n);
	log_info("%s: min %f max %f rms %f", name, min_err, max_err, rms_err);
}
void rms_error ( const char * name , float x0 , float x1 , float dx , float ( * f0 ) ( float ) , float ( * f1 ) ( float ) ) { float x = x0 ; float max_err = FLT_MIN ; float min_err = FLT_MAX ; float sum_err2 = 0.f ; int n = 0 ; while ( x < x1 ) { float y0 = f0 ( x ) ; float y1 = f1 ( x ) ; float err = fabsf ( y1 - y0 ) ; sum_err2 += err * err ; if ( err < min_err ) { min_err = err ; } if ( err > max_err ) { max_err = err ; } x += dx ; n ++ ; } float rms_err = sqrtf ( sum_err2 / ( float ) n ) ; log_info ( " " , name , min_err , max_err , rms_err ) ; }
Error Analysis
Compare a "fast" function against the known-accurate "slow" function
Log the error stats to see how good the fast function is.
Error Analysis Compare a " fast " function against the known - accurate " slow " function Log the error stats to see how good the fast function is .
//log_debug("x %f y0 %f y1 %f err %f", x, y0, y1, err);