9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: erik quanstrom <quanstro@quanstro.net>
To: 9fans@9fans.net
Subject: Re: [9fans] a bug in awk?
Date: Sat, 10 Jan 2009 16:45:15 -0500	[thread overview]
Message-ID: <1f008c20c3fcaf5ebcc59a63642a32fb@quanstro.net> (raw)

> 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




             reply	other threads:[~2009-01-10 21:45 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-10 21:45 erik quanstrom [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1f008c20c3fcaf5ebcc59a63642a32fb@quanstro.net \
    --to=quanstro@quanstro.net \
    --cc=9fans@9fans.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).