char resistor_rcsid[] ="@(#)$Header";
/*+ "RCS info"*/
/*
 * Funktionen für struct resistor:
 * res_set
 * res_eq
 * res_add
 * res_sub
 *
 * $Revision: 2.2 $
 * $State: Exp $
 * $Author: cts $
 * $Locker:  $
 * $Date: 1997/10/18 02:34:02 $
 *
 * $Log: resistor.c $
 * Revision 2.2  1997/10/18  02:34:02  cts
 * catchup
 *
 * Revision 1.1  1997/10/17 23:24:37  cts
 * Initial revision
 *
*/
/*- */
#include "main.h"

/*+ "double res_val(struct resistor r)" */
double res_val(struct resistor r)
{
	return r.value * r.scale;
}
/*- */

/*+ "struct resistor res_set(double value)" */
struct resistor res_set(double value)
{
	struct resistor r;

	r.value = value;
	r.scale = 1.;
	r.index = 1;
	return res_scale(r);
}
/*- */

/*+ "struct resistor res_eq(struct resistor r)" */
struct resistor res_eq(struct resistor r)
{
	return res_scale(r);
}
/*- */

/*+ "struct resistor res_scale(struct resistor r)" */
struct resistor res_scale(struct resistor r)
/* Wid skalieren auf 1<=r<10, scale setzen */
/* quick'n dirty, mit logarithmus gehts schneller */
/* bug(?): index wird nicht gesetzt!!! */
{
	if ( r.value <= 0 ) {
		return r;
	}
	while ( ( r.value <1. ) || ( r.value >= 10. ) ) {
		if ( r.value < 1. ) {
			r.scale /= 10.;
			r.value *= 10.;
		}
		else if ( r.value >= 10. ) {
			r.scale *= 10.;
			r.value /= 10.;
		}
	}
	return r;
}
/*- */

/*+ "struct resistor res_add(struct resistor r1, struct resistor r2)" */
struct resistor res_add(struct resistor r1, struct resistor r2)
{
	return res_set( res_val(r1) + res_val(r2) );
}
/*- */

/*+ "struct resistor res_sub(struct resistor r1, struct resistor r2)" */
struct resistor res_sub(struct resistor r1, struct resistor r2)
{
	if ( res_val(r1) > res_val(r2) ) {
		return res_set( res_val(r1) - res_val(r2) );
	}
	else {
		return res_set(0.);
	}
}
/*- */

/*+ "int res_print(struct resistor r)" */
int res_print(struct resistor r)
{
	printf ( "%8.3f\n", r.value * r.scale );

	return 0;
}
/*- */

