🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.sources.bugs
Article #897

VC -- Two bugs in the AVG routine

#897
From: Kevin Rushforth
Date: Sat, 17 Jan 1987 06:13
79 lines
2656 bytes
I have found two bugs in VC relating to the "@AVG" function.  The first
is an error in the gram.y file causing the function to be incorrectly
recognized by the string "@AVE" instead of the correct "@AVG".  The
save file routine (P command) writes the average function out as "@avg"
which is subsequently not recognized when the save file is read in (G
command).  The second bug occurs in the averaging routine itself when
no valid values are found in the specified range.  This causes a divide
by 0 error which aborts execution on many machines.  Following are the
context diffs for "gram.y" and "interp.c"

diff -c OLD/gram.y NEW/gram.y
*** OLD/gram.y	Fri Jan 16 22:29:56 1987
--- NEW/gram.y	Fri Jan 16 22:29:15 1987
***************
*** 46,52
  %token K_FIXED
  %token K_SUM
  %token K_PROD
! %token K_AVE
  
  %left '?' ':'
  %left '|'

--- 46,52 -----
  %token K_FIXED
  %token K_SUM
  %token K_PROD
! %token K_AVG
  
  %left '?' ':'
  %left '|'
***************
*** 86,92
  				{ $$ = new (O_REDUCE('+'), $4, $6); }
  	|       '@' K_PROD '(' var ':' var ')' 
  				{ $$ = new (O_REDUCE('*'), $4, $6); }
! 	|       '@' K_AVE '(' var ':' var ')' 
  				{ $$ = new (O_REDUCE('a'), $4, $6); }
  	|	'(' e ')'	{ $$ = $2; }
  	|	'+' term	{ $$ = $2; }

--- 86,92 -----
  				{ $$ = new (O_REDUCE('+'), $4, $6); }
  	|       '@' K_PROD '(' var ':' var ')' 
  				{ $$ = new (O_REDUCE('*'), $4, $6); }
! 	|       '@' K_AVG '(' var ':' var ')' 
  				{ $$ = new (O_REDUCE('a'), $4, $6); }
  	|	'(' e ')'	{ $$ = $2; }
  	|	'+' term	{ $$ = $2; }
diff -c OLD/interp.c NEW/interp.c
*** OLD/interp.c	Fri Jan 16 22:30:31 1987
--- NEW/interp.c	Fri Jan 16 22:29:15 1987
***************
*** 60,66
  		count++;
  	    }
  
!     return (v / (double)count);
  }
  
  double eval(e)

--- 60,69 -----
  		count++;
  	    }
  
!     if(count == 0)
! 	return 0.0;
!     else
! 	return (v / (double)count);
  }
  
  double eval(e)
-- 
                Kevin C. Rushforth
                Evans & Sutherland Computer Corporation

UUCP Address:   {ihnp4,decvax}!decwrl!esunix!rushfort
Alternate:      {ihnp4,seismo}!utah-cs!utah-gr!uplherc!esunix!rushfort
Technical Details
Message-ID: <319@esunix.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!ut-sally!utah-cs!utah-gr!uplherc!esunix!rushfort

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!ut-sally!utah-cs!utah-gr!uplherc!esunix!rushfort
From: rushfort@esunix.UUCP (Kevin Rushforth)
Newsgroups: net.sources.bugs,comp.sources.d
Subject: VC -- Two bugs in the AVG routine
Message-ID: <319@esunix.UUCP>
Date: Sat, 17-Jan-87 01:13:10 EST
Article-I.D.: esunix.319
Posted: Sat Jan 17 01:13:10 1987
Date-Received: Tue, 20-Jan-87 19:00:20 EST
Lines: 79