9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* Re: [9fans] a bug in awk?
@ 2009-01-10 21:45 erik quanstrom
  2009-01-11  7:07 ` Russ Cox
  2009-01-11  9:30 ` Tharaneedharan Vilwanathan
  0 siblings, 2 replies; 9+ messages in thread
From: erik quanstrom @ 2009-01-10 21:45 UTC (permalink / raw)
  To: 9fans

> For what it's worth, bwk awk does not have this problem, so the error
> must be in code introduced later.
>
>> Note the 5946903e318 which AWK may mistakenly treat as a floating
>> point constant.  Now to figure how to prevent such errors...

from the better than nothin' department ...

i have an inelegant couple of lines that prevent overflow.

one would expect that for a postitive exponent that if
	nwholedigits + exponent - 1 > the maximum exp.
then you'll have an overflow.  (ideally one should do this
computation in ieee space, but that's not what the code
does.)  i put this simple test in the natural place and
it seems to avoid the floating point exception (tested on intel
machines).  the problem seems to be that the code deals
with very small overflows, but isn't prepared to deal with
a number that's going to overflow by a lot.  in this case,
we're 1^(10 + 6) too big.

; diffy strtod.c
396a397,398
> 		if(nd0 + e1 - 1> DBL_MAX_10_EXP)
> 			goto ovfl;
431a434,435
> 		if(e1 - (nd-nd0) > DBL_MAX_10_EXP)
> 			goto undfl;

is it even legal to return DBL_MAX for numbers that should
be +Inf or DBL_MIN for numbers that should yield -Inf?

is there some reason that the regular strtod is unsuitable for
ape?

- erik




^ permalink raw reply	[flat|nested] 9+ messages in thread
* [9fans] a bug in awk?
@ 2009-01-10  5:57 Tharaneedharan Vilwanathan
  2009-01-10  6:26 ` lucio
  0 siblings, 1 reply; 9+ messages in thread
From: Tharaneedharan Vilwanathan @ 2009-01-10  5:57 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

hi,

while i was playing with venti archive, i found something interesting.

i used dumpvacroots.new (from contrib) and for some reason, awk bailed
out with floating point error whenever it saw a line with a specific
root score.

here are the two sample lines (i used customized printarena.c which
prints the date for me at the end):

              11260359 d05544897ff642ca36e58174bc753b0f3382b793   0
8192 Jan  9 18:09
              11258672 5946903e318d3596c21e35b42a13c1dea5fd32cc   0
8192 Jan  9 18:09

awk seems to be okay with the first line but not the second line.

here is the output when i use awk:

mill# awk ' { print $0; print NF}' /tmp/out1.dat
              11260359 d05544897ff642ca36e58174bc753b0f3382b793   0
8192 Jan  9 18:09
7
              11258672 5946903e318d3596c21e35b42a13c1dea5fd32cc   0
8192 Jan  9 18:09
awk: floating point exception 6
 input record /tmp/out1.dat:2
 source line 1

i figured that:

- awk runs fine if i dont print NF. (so, it parses the line on-demand
and parsing fails?)
- awk doesnt seem to like the score 5946....32cc. If I change that
score to something else and rerun, it seems to be fine.

to confirm that this is a plan9 specific awk issue, i tried the same
with my Mac machine. it seems to be okay:

$ awk ' { print $0; print NF }' out1.dat
              11260359 d05544897ff642ca36e58174bc753b0f3382b793   0
8192 Jan  9 18:09
7
              11258672 5946903e318d3596c21e35b42a13c1dea5fd32cc   0
8192 Jan  9 18:09
7

what could be the issue? any clues?

i initially thought my venti data got corrupted but i am now convinced
that this is something else, since i was also able to reliably archive
data.

thanks
dharani



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-01-11  9:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-10 21:45 [9fans] a bug in awk? erik quanstrom
2009-01-11  7:07 ` Russ Cox
2009-01-11  7:24   ` erik quanstrom
2009-01-11  9:30 ` Tharaneedharan Vilwanathan
  -- strict thread matches above, loose matches on Subject: below --
2009-01-10  5:57 Tharaneedharan Vilwanathan
2009-01-10  6:26 ` lucio
2009-01-10  6:39   ` Tharaneedharan Vilwanathan
2009-01-10 16:19   ` John Stalker
2009-01-10 19:43     ` erik quanstrom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).