/* TEST 2 EXERCISER PROGRAM FOR THE MULTI-LAYER PERCEPTRON TESTING WITH MAXIMUM INPUT AND WEIGHT Author: Robert John Morton YE572246C December 1997 */ #include #define NI 77 //number of inputs to the neuron int I, W = 32767; long SplitLong(void) { //long product with two long accumulators int i; long x, Hi, Lo; for(Hi = 0, Lo = 0, i = 0; i < NI; i++) { x = (long)I * W; Hi += x >> 16; Lo += x & 0xFFFF; } return(((Hi << 1) + (Lo >> 15)) / NI); } main() { int i, c; long x; char s[512], *r; FILE *fh; fh = fopen("results.txt","a"); //open file for appending i = sprintf(s ,"TESTING WITH MAXIMUM INPUT AND WEIGHT\n"); I = 32767; x = SplitLong(); c = x; i += sprintf(s + i," For max positive inputs %+6d %9lX\n", c, x); I = 0; x = SplitLong(); c = x; i += sprintf(s + i," For zero inputs... %+6d %9lX\n", c, x); I = -32767; x = SplitLong(); c = x; i += sprintf(s + i," For max negative inputs %+6d %9lX\n\n\n", c, x); for (r = s; (c = *r) > '\0'; r++) putc(c, fh); fclose(fh); //close the file }