Are you ready to compete with global competition? Stop doing so-so work and finally get some real accuracy. You probably wonder why your scrap rate is high. If you're sick of the "Oh, thats close enough attitude", use this info. It may take a little longer but the end product is worth it. Even if you don't have a current application it is facinating reading.
void add_to( int * add_to, const int * add_from, int n_min, int n_max ) { int remainder = 0; int i = n_max; for( i--; i >= 0 && (i >= n_min || remainder); i-- ) { int c = remainder + add_to[i]; if( i >= n_min ) c += add_from[i]; add_to[i] = c % 10; remainder = c / 10; } }
/* returns new n_min */ int divide_by( int * divide, int divisor, int n_min, int n_max ) { int remainder = 0; int new_n_min = -1; int i; for( i = 0; i < n_max; i++ ) { int x = remainder * 10 + divide[i]; remainder = x % divisor; divide[i] = x / divisor; if( new_n_min == -1 && divide[i] ) new_n_min = i; } if( new_n_min == -1 ) new_n_min = n_max; return new_n_min; }
int main( int argc, char *argv[] ) { int e_size; int *e, *addition; int i, n_min; if( argc != 2 || (e_size = atoi( argv[1] )) == 0) { fprintf( stderr, "Usage: %s number_of_digits\n", argv[0] ); exit( 1 ); } printf( "e_size = %d.\n", e_size );
e = (int *)calloc( e_size+3, sizeof( int ) ); addition = (int *)calloc( e_size+3, sizeof( int ) );
PolyTech Forum website is not affiliated with any of the manufacturers or service providers discussed here.
All logos and trade names are the property of their respective owners.