[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gawk 3.1.2g problems with NaNs and substr etc.
From: |
Stepan Kasal |
Subject: |
Re: gawk 3.1.2g problems with NaNs and substr etc. |
Date: |
Tue, 8 Jul 2003 14:29:15 +0200 |
User-agent: |
Mutt/1.2.5.1i |
Hello,
I'd just like to comment on one of the points of your mail.
On Mon, Jul 07, 2003 at 11:08:06AM -0700, Paul Eggert wrote:
> > > gawk-3.1.2g: cmd. line:1: warning: substr: non-integer length 0.1 will be
> > > truncated
>
> It's OK, but I think it's simpler and more consistent to say that all
> values less than 1 are treated as 1, rather than to have a special
> case for non-integer values. It's not a huge deal either way.
You've missed that this is _length_ which can be 0, and all negative values
are treated as 0. The code indeed looks roughly like this:
if (d_length < 0) {
lintwarn("inalid length, using 0");
length = 0;
} else if (double_to_int(d_length) != d_length) {
lintwarn("truncating length");
length = d_length;
}
So really, 0.1 is truncated, while -0.1 is "invalid" and thus replaced by 0.
> A more general question is whether gawk should faithfully reflect the
> quirks of the underyling floating point, or whether it should impose
> its own opinion. Personally I favor the former, as IEEE floating
> point is nearly universal and is well understood. But gawk does the
> latter, most likely for historical reasons.
>
> For example, gawk refuses to let me compute 1.0 / 0.0, even though the
> computation is perfectly well-defined with IEEE floating point. In
> contrast, mawk does the right thing (in my opinion): it quietly
> returns infinity.
>
> I could submit patches along these lines if the Gawk maintainer is
> interested. (Obviously gawk should still be portable to non-IEEE
> hosts; I wouldn't change that.)
If you write that patch, I'd be glad to see it and perhaps publish it;
maybe I'll get a collection of patches and I'll get some people to test
it. This way I could pass to Arnold Robbins (the maintainer) a
"verified" collection of patches.
But I'm not the maintainer. You should probably wait what Arnold says,
to be sure that your work will fit with his opinions.
Stepan