Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TAWK: floats limited to 14 digits

84 views
Skip to first unread message

Laurent Marc

unread,
Jun 9, 2015, 3:32:57 PM6/9/15
to
--Hi,

this code below failed because the input file has float numbers up to 14 digits,
but works fine with standard awk/gawk under unix.

function max_array(tab, max,i)
{
for(i in tab)
max = tab[i]> max ? tab[i] : max
return max;
}
{
array[NR]=$1
}
END{
print max_array(array);
}

awkw -f max.awk list.txt

awk: warning in max.awk(line 4) (FILENAME="list.txt" FNR=57):
floating point: too many significant digits
21.8339171127176

list.txt:

13.7825512452063
16.1962726675703
11.155315061747
13.0763953271788
20.118489269443
18.6432950638126
15.3478204565943
12.7282896888748
15.4706202612993
16.0578860443237
16.2209790309863
14.6504890794928
18.5146092154456
10.1286860540208
0.124114699546875
12.6730006534381
21.8339171127176
19.4679589674879
16.065099731372
12.5556518077224
17.8435336928095
15.8253200877248
15.7542683229801
15.1392739660766
17.8039422933073
10.9431387407982
11.5902282805772
20.9541154981632
19.4918618529047
17.8580906003215
13.6137793409958
17.9014741247489
16.4162385453881
16.0462098044651
13.6629402718361
18.1345311360914
10.095972583165
0.0295839895807075
12.8183426277323
19.3590886105295
19.2700733012037
16.4087064691554
13.5539157923002
17.5969070817101
15.884557737844
15.3559914917345
13.4336291569755
16.1503512331075
10.1210650388042
11.0953945638452
18.4511637700623
18.0096435251741
14.5166857850812
11.8009945903844
15.8860302558865
15.1022852831786
14.6108297932275

Ed Morton

unread,
Jun 9, 2015, 6:37:09 PM6/9/15
to
On 6/9/2015 2:32 PM, Laurent Marc wrote:
> --Hi,
>
> this code below failed because the input file has float numbers up to 14 digits,
> but works fine with standard awk/gawk under unix.
>
> function max_array(tab, max,i)
> {
> for(i in tab)
> max = tab[i]> max ? tab[i] : max
> return max;
> }
> {
> array[NR]=$1
> }
> END{
> print max_array(array);
> }
>
> awkw -f max.awk list.txt
>
> awk: warning in max.awk(line 4) (FILENAME="list.txt" FNR=57):
> floating point: too many significant digits

Yup, that looks like an error message all right. Do you have a question?

Ed.

Laurent Marc

unread,
Jun 10, 2015, 5:58:31 AM6/10/15
to

Yup, that looks like an error message all right. Do you have a question?

of course: how to get around this error ?


Kenny McCormack

unread,
Dec 25, 2015, 9:10:07 AM12/25/15
to
In article <9b9a39ca-c838-4d84...@googlegroups.com>,
Laurent Marc <scr...@gmail.com> wrote:
>
>Yup, that looks like an error message all right. Do you have a question?
>
>of course: how to get around this error ?
>
>

Well, there are 3 possible ways to go about answering your question.

1) Can I actually make it work - that is, actually do the right thing
with my data? The answer to this seems to be "no". It is what it
is.

2) Can I fix my data so that the warning goes away? Yes. Either with
a text editor (on the data file) or by fixing the program so that
it truncates it to something reasonable before converting the
string to a number. Details left as an exercise for the OP...

3) Can I inhibit (hide) the warning message? Yes, set the internal
variables "WARNINGS" to 0 (or read the manual to learn the other
possible values). Observe:

C:>awkw '{print $0+0}' OFMT=%.30g WARNINGS=0 -
tawk input? 2
2
tawk input? 12.1234567890123456789
12.123456789012346
tawk input?

--

"This ain't my first time at the rodeo"

is a line from the movie, Mommie Dearest, said by Joan Crawford at a board meeting.
0 new messages