Code Comments
Programming Forum and web based access to our favorite programming groups.Hi,
My system is Slackware 10 with gawk 3.1.3
When I run (in a bash) command
> cat times | awk --source '{akt=$1*100+$2*(1.67)
> print akt}'
where times is
----times----
00 06
05 11
00 32
10 23
-----end-----
I get:
10,02
518,37
53,44
1038,41
which is what I expect to get (times is HOURS MINUTES \n, output is hom
much shoud user pay for using computer...)
Now, when I run
> cat times | awk -v b=4 --source '{akt=$1*100+$2*(1.67)
> print akt}'
I get
6
511
32
1023
That is, gawk doesn't allo any floating point calculation. Why is that?
Is it possible it's a gawk-bug?
Best regards,
sirix.
Post Follow-up to this messageIn article <chkk44$rvr$1@news.onet.pl>, sirix <sirix@poczta.onet.pl> wrote: >Aharon Robbins wrote: > >wrote: >I thought it's my stupid typo rather than bug. > >Ok, it works now allright. Normally I use LC_ALL=pl_PL. I'm going to >download and compile 3.1.4 - as soon as I've done it I write you an >email with results. >Just in case anybody bothers with that in future - I send this post also >to c.l.awk newsgroup. > >I really appreciate your help, thanks very much. > >sirix. I hate bottom posting, but since everyone here will yell at me if I don't, what the heck. I've posted a fix in bug-gnu-utils group, but here it is in case anyone else wants it. Thanks, Arnold ----------------- cut here ------------------- Wed Sep 8 09:54:53 2004 Arnold D. Robbins <arnold@skeeve.com> * main.c (main): Force LC_NUMERIC locale to "C" before parsing the program, since a variable assignment with -v can leave the locale set incorrectly. --- ../gawk-3.1.4/main.c 2004-07-28 16:42:19.000000000 +0300 +++ main.c 2004-09-08 09:53:46.000000000 +0300 @@ -532,6 +538,15 @@ init_args(optind, argc, (char *) myname, argv); (void) tokexpand(); +#if defined(LC_NUMERIC) + /* + * FRAGILE! CAREFUL! + * Pre-initing the variables with arg_assign() can change the + * locale. Force it to C before parsing the program. + */ + setlocale(LC_NUMERIC, "C"); +#endif + /* Read in the program */ if (yyparse() != 0 || errcount != 0) exit(1); -- Aharon (Arnold) Robbins --- Pioneer Consulting Ltd. arnold AT skeeve DOT com P.O. Box 354 Home Phone: +972 8 979-0381 Fax: +1 206 350 8765 Nof Ayalon Cell Phone: +972 50 729-7545 D.N. Shimshon 99785 ISRAEL
Post Follow-up to this messageAharon Robbins wrote: >In article <chkgqd$i5r$1@news.onet.pl>, sirix <sirix@poczta.onet.pl> wrote: > > > >Greetings. First, you should send bug reports to bug-gawk@gnu.org instead >of posting them here; there's no guarantee otherwise that I'll see them. > I thought it's my stupid typo rather than bug. >Looking more closely, it smells like a locale issue; try > > export LC_ALL=C > Ok, it works now allright. Normally I use LC_ALL=pl_PL. I'm going to download and compile 3.1.4 - as soon as I've done it I write you an email with results. Just in case anybody bothers with that in future - I send this post also to c.l.awk newsgroup. I really appreciate your help, thanks very much. sirix.
Post Follow-up to this messageIn article <chkk44$rvr$1@news.onet.pl>, sirix <sirix@poczta.onet.pl> wrote: >Aharon Robbins wrote: > >wrote: >I thought it's my stupid typo rather than bug. > >Ok, it works now allright. Normally I use LC_ALL=pl_PL. I'm going to >download and compile 3.1.4 - as soon as I've done it I write you an >email with results. >Just in case anybody bothers with that in future - I send this post also >to c.l.awk newsgroup. > >I really appreciate your help, thanks very much. > >sirix. I hate bottom posting, but since everyone here will yell at me if I don't, what the heck. I've posted a fix in bug-gnu-utils group, but here it is in case anyone else wants it. Thanks, Arnold ----------------- cut here ------------------- Wed Sep 8 09:54:53 2004 Arnold D. Robbins <arnold@skeeve.com> * main.c (main): Force LC_NUMERIC locale to "C" before parsing the program, since a variable assignment with -v can leave the locale set incorrectly. --- ../gawk-3.1.4/main.c 2004-07-28 16:42:19.000000000 +0300 +++ main.c 2004-09-08 09:53:46.000000000 +0300 @@ -532,6 +538,15 @@ init_args(optind, argc, (char *) myname, argv); (void) tokexpand(); +#if defined(LC_NUMERIC) + /* + * FRAGILE! CAREFUL! + * Pre-initing the variables with arg_assign() can change the + * locale. Force it to C before parsing the program. + */ + setlocale(LC_NUMERIC, "C"); +#endif + /* Read in the program */ if (yyparse() != 0 || errcount != 0) exit(1); -- Aharon (Arnold) Robbins --- Pioneer Consulting Ltd. arnold AT skeeve DOT com P.O. Box 354 Home Phone: +972 8 979-0381 Fax: +1 206 350 8765 Nof Ayalon Cell Phone: +972 50 729-7545 D.N. Shimshon 99785 ISRAEL
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.