********> bugfix.59 Author: Bill Ross Date: 12/18/95 Programs: Carnal Severity: Slight Problem: When calculating the deviation of values that are all quite close (i.e. deviation approximately 0), sqrt() domain errors can arise due to numbers e.g. -1.0e-200. Affects: Summary output. Cause: Presumably due to machine arithmetic. Fix: Make the following change to stats.c: --------------------------------------------------------------------- *** OLD stats.c --- NEW stats.c *************** *** 75,81 **** statstruct *stat; _REAL n; { ! _REAL avg; if (!stat->ct) { printf(" no data accumulated\n"); --- 75,81 ---- statstruct *stat; _REAL n; { ! _REAL avg, rms; if (!stat->ct) { printf(" no data accumulated\n"); *************** *** 92,107 **** return; } avg = stat->avg/n; if (convert) printf("avg %8.3f dev %8.3f max %8.3f min %8.3f\n", TODEG * avg, ! TODEG * sqrt(stat->avg2/n - avg*avg), TODEG * stat->max, TODEG * stat->min); else printf("avg %8.3f dev %8.3f max %8.3f min %8.3f\n", ! avg, sqrt(stat->avg2/n - avg*avg), ! stat->max, stat->min); } void --- 92,116 ---- return; } avg = stat->avg/n; + rms = stat->avg2/n - avg*avg; + if (rms < 0.0) { + /* + * flag if not plausibly due to roundoff error + */ + if (rms < -1.0e-15) + printf("possible programming error: sqrt(%e)\n", rms); + rms = 0.0; + } else + rms = sqrt(rms); if (convert) printf("avg %8.3f dev %8.3f max %8.3f min %8.3f\n", TODEG * avg, ! TODEG * rms, TODEG * stat->max, TODEG * stat->min); else printf("avg %8.3f dev %8.3f max %8.3f min %8.3f\n", ! avg, rms, stat->max, stat->min); } void --------------------------------------------------------------------- Temporary workarounds: none --