I introduce a new variable "roundingError", its valued was mistakenly
added to the 'other' class, later it was added to "total" again,
causing duplication. So I change it to only add to
the 'other' named stat.
The comparison "if n >= 0.01" is wrong, since we take 2 digits
accuracy, so it should compare against 0.005, see "significantStat".
Also "roundStat" is totally useless because it rounds to the third
digit. We can rely on "FORMAT" to do the rounding.
I also modified "makeStatString" to simplify the code a bit.
- Qian
diff --git a/src/interp/g-timer.boot b/src/interp/g-timer.boot
index 2b6e2473..689d614c 100644
--- a/src/interp/g-timer.boot
+++ b/src/interp/g-timer.boot
@@ -41,56 +41,46 @@ makeLongStatStringByProperty _
total := 0
str := '""
otherStatTotal := GET('other, property)
+ roundingError := 0
for [name,class,:ab] in listofnames repeat
- name = 'other => 'iterate
cl := first LASSOC(class, listofclasses)
n := GET(name, property)
PUT(cl, classproperty, n + GET(cl, classproperty))
total := total + n
- if n >= 0.01
- then timestr := normalizeStatAndStringify n
- else
- timestr := '""
- otherStatTotal := otherStatTotal + n
- str := makeStatString(str, timestr, name, flag)
- PUT('other, property, otherStatTotal)
- if otherStatTotal > 0 then
- timestr := normalizeStatAndStringify otherStatTotal
- str := makeStatString(str, timestr, 'other, flag)
- total := total + otherStatTotal
- cl := first LASSOC('other, listofnames)
- cl := first LASSOC(cl, listofclasses)
- PUT(cl, classproperty, otherStatTotal + GET(cl, classproperty))
+ name = 'other => 'iterate
+ if significantStat n then
+ str := makeStatString(str, n, name, flag)
+ else
+ roundingError := roundingError + n
+ str := makeStatString(str, otherStatTotal + roundingError, 'other, flag)
if flag ~= 'long then
total := 0
str := '""
for [class,name,:ab] in listofclasses repeat
n := GET(name, classproperty)
- n = 0.0 or n = 0 => 'iterate
total := total + n
- timestr := normalizeStatAndStringify n
- str := makeStatString(str,timestr,ab,flag)
+ str := makeStatString(str, n, ab, flag)
total := STRCONC(normalizeStatAndStringify total,'" ", units)
str = '"" => total
STRCONC(str, '" = ", total)
normalizeStatAndStringify t ==
FLOATP t =>
- t := roundStat t
- t = 0.0 => '"0"
- FORMAT(nil,'"~,2F",t)
+ significantStat t => FORMAT(nil, '"~,2F", t)
+ '"0"
INTEGERP t => FORMAT(nil, '"~:d", t)
STRINGIMAGE t
-roundStat t ==
- not FLOATP t => t
- (TRUNCATE (0.5 + t * 1000.0)) / 1000.0
+-- check if argument is significant enough to be printed.
+-- current printing accuracy is 2 digits after decimal point.
+significantStat t == t >= 0.005
makeStatString(oldstr,time,abb,flag) ==
- time = '"" => oldstr
+ not significantStat time => oldstr
opening := (flag = 'long => '"("; '" (")
- oldstr = '"" => STRCONC(time,opening,abb,'")")
- STRCONC(oldstr,'" + ",time,opening,abb,'")")
+ timestr := normalizeStatAndStringify time
+ oldstr = '"" => STRCONC(timestr, opening, abb, '")")
+ STRCONC(oldstr, '" + ", timestr, opening, abb, '")")
peekTimedName() == IFCAR $timedNameStack