tOutputType ActivateNeuron(tNeuronType type, tOutputType accum) { fixedpt fpAccum,fpMaxfwd,tmp; tmp=fixedpt_fromint(0); if(type==INNERN) { fpMaxfwd=fixedpt_fromint(MAX_NEURON_OUT); } else { fpMaxfwd=fixedpt_fromint(MAXFWD); } if((accum<FIXED_POS_LIMIT)&&(accum>FIXED_NEG_LIMIT)) { fpAccum=fixedpt_fromint(accum); } else { if(accum>FIXED_POS_LIMIT) { if(type==INNERN) { fpAccum=fixedpt_fromint((FIXED_POS_LIMIT-1)); } else { fpAccum=fixedpt_fromint((FIXED_POS_LIMIT-MAXFWD)); } } else { if(type==INNERN) { fpAccum=fixedpt_fromint((FIXED_POS_LIMIT+1)); } else { fpAccum=fixedpt_fromint((FIXED_POS_LIMIT+MAXFWD)); } } } switch (type) { case INNERN: tmp=fixedpt_abs(fpAccum); tmp=fixedpt_add(tmp,FIXEDPT_ONE); tmp=fixedpt_div(fpAccum,tmp); tmp=fixedpt_mul(tmp,fpMaxfwd); break; case OUTERN: tmp=fixedpt_abs(fpAccum); tmp=fixedpt_add(tmp,fpMaxfwd); tmp=fixedpt_div(fpAccum,tmp); tmp=fixedpt_mul(tmp,fpMaxfwd); break; } return fixedpt_toint(tmp); }
int Reg_ActivateNeuron(unsigned char type, int accum) { //char frc[12]; fixedpt fpAccum,fpMaxfwd,tmp; tmp=fixedpt_fromint(0); if(type==INNER) { fpMaxfwd=fixedpt_fromint(MAX_NEURON_OUT); } else { fpMaxfwd=fixedpt_fromint(MAXFWD); } if((accum<FIXED_POS_LIMIT)&&(accum>FIXED_NEG_LIMIT)) { //printf("accum=%d\r\n",accum); fpAccum=fixedpt_fromint(accum); } else { if(accum>FIXED_POS_LIMIT) { if(type==INNER) { fpAccum=fixedpt_fromint((FIXED_POS_LIMIT-1)); } else { fpAccum=fixedpt_fromint((FIXED_POS_LIMIT-MAXFWD)); } } else { if(type==INNER) { fpAccum=fixedpt_fromint((FIXED_POS_LIMIT+1)); } else { fpAccum=fixedpt_fromint((FIXED_POS_LIMIT+MAXFWD)); } } } switch (type) { case INNER: tmp=fixedpt_abs(fpAccum); tmp=fixedpt_add(tmp,FIXEDPT_ONE); tmp=fixedpt_div(fpAccum,tmp); tmp=fixedpt_mul(tmp,fpMaxfwd); break; case OUTER: tmp=fixedpt_abs(fpAccum); tmp=fixedpt_add(tmp,fpMaxfwd); //fixedpt_str(tmp,frc); //printf("tmp=%s\r\n",frc); tmp=fixedpt_div(fpAccum,tmp); tmp=fixedpt_mul(tmp,fpMaxfwd); break; } //printf("lol"); return fixedpt_toint(tmp); }
int main() { fixedpt A, B, C; printf("fixedptc library version: %s\n", FIXEDPT_VCSID); printf("Using %d-bit precision, %d.%d format\n\n", FIXEDPT_BITS, FIXEDPT_WBITS, FIXEDPT_FBITS); printf("The most precise number: "); fixedpt_print(1); printf("The biggest number: "); fixedpt_print(0x7fffff00); printf("Here are some example numbers:\n"); printf("Random number: "); fixedpt_print(fixedpt_rconst(143.125)); printf("PI: "); fixedpt_print(FIXEDPT_PI); printf("e: "); fixedpt_print(FIXEDPT_E); puts(""); A = fixedpt_rconst(2.5); B = fixedpt_fromint(3); fixedpt_print(A); puts("+"); fixedpt_print(B); C = fixedpt_add(A, B); puts("="); fixedpt_print(C); puts(""); fixedpt_print(A); puts("*"); fixedpt_print(B); puts("="); C = fixedpt_mul(A, B); fixedpt_print(C); puts(""); A = fixedpt_rconst(1); B = fixedpt_rconst(4); C = fixedpt_div(A, B); fixedpt_print(A); puts("/"); fixedpt_print(B); puts("="); fixedpt_print(C); printf("exp(1)="); fixedpt_print(fixedpt_exp(FIXEDPT_ONE)); puts(""); puts("sqrt(pi)="); fixedpt_print(fixedpt_sqrt(FIXEDPT_PI)); puts(""); puts("sqrt(25)="); fixedpt_print(fixedpt_sqrt(fixedpt_rconst(25))); puts(""); puts("sin(pi/2)="); fixedpt_print(fixedpt_sin(FIXEDPT_HALF_PI)); puts(""); puts("sin(3.5*pi)="); fixedpt_print(fixedpt_sin(fixedpt_mul(fixedpt_rconst(3.5), FIXEDPT_PI))); puts(""); puts("4^3.5="); fixedpt_print(fixedpt_pow(fixedpt_rconst(4), fixedpt_rconst(3.5))); puts(""); puts("4^0.5="); fixedpt_print(fixedpt_pow(fixedpt_rconst(4), fixedpt_rconst(0.5))); return (0); }