Very useful machining formula

Dec 28, 2006 7 Replies

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.



formatting link
Dixon


I wrote a program a while ago to calculate many digits of the number "e".

######################################################################

#include #include

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 ) );

if( !e || !addition ) { fprintf( stderr, "Not enough memory.\n" ); exit( 1 ); } addition[0] = 1; e[0] = 1;

for( i=1, n_min = 0; n_min < e_size - 1; i++ ) { fprintf( stderr, "bef ==>i=%d, n_min=%d, e_size=%d...", i, n_min, e_size ); n_min = divide_by( addition, i, n_min, e_size ); add_to( e, addition, n_min, e_size ); fprintf( stderr, ", after i=%d, n_min=%d, e_size=%d...", i, n_min, e_size ); fprintf( stderr, "\r" ); /*sleep(1);*/ }

fprintf( stderr, "\n" );

for( i = 0; i < e_size; i++ ) { printf( "%d", e[i] ); if( i == 0 ) { printf( "." ); }

if( i % 70 == 69 ) { printf( "\n" ); } }

printf( "\n" );

}

I must have been absent the day they covered this in school, because I don't quite follow your "formula". Dixon

Where is the rest of it?

Regards,

Boris Mohar

Got Knock? - see: Viatrack Printed Circuit Designs (among other things)

formatting link
void _-void-_ in the obvious place

I'll try to find the million place site. You'll just have to get by with fifty thousand until then.

Works fine here under Borland C++ 1.01 (DOS)

e_size = 50. bef ==>i=41, n_min=48, e_size=50..., after i=41, n_min=50, e_size=50...

2.7182818284590452353602874713526624977572470936984

Only thing is its completely uncommented and I cant be bothered to plow through it decoding the algorithm.

Could be worse though,

supposedly also calculates 'e', but my compiler chokes on it with 'Bitfield too long'

Ran fine using cygwin / gcc.

CYGWIN_NT-5.0 barefoot 1.5.23(0.156/4/2) 2006-12-19 10:52 i686 Cygwin gcc version 3.4.4 (cygming special, gdc 0.12, using dmd 0.125)

Took it out to 50000 digits.

Wes S

On Wed, 27 Dec 2006 21:40:52 -0500, with neither quill nor qualm, "Dixon" quickly quoth:

--snip--

What, you don't speak C-language?

-- My future starts when I wake up every morning... Every day I find something creative to do with my life. -- Miles Davis

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required