bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Command line variable assignment problems with localized floats


From: Aharon Robbins
Subject: Re: Command line variable assignment problems with localized floats
Date: Sun, 07 Jan 2007 17:02:51 +0200

Greetings. I took another look at your original mail.
I am on a Fedora Core 2 system, using an unpatched gawk 3.1.5.

> Date: Fri, 22 Dec 2006 19:19:31 +0100
> From: "Heike C. Zimmerer" <address@hidden>
> Subject: Command line variable assignment problems with localized floats
> To: address@hidden
>
> Hello,
>
> I'm reporting a localization issue, checked with:
>
>  $ gawk --version
>  GNU Awk 3.1.5
>  Copyright (C) 1989, 1991-2005 Free Software Foundation.
>
> Problem 1:
>  Command line non-option variable assignments of floats are incorrecty
>  handled if the current locale (LC_NUMERIC) defines something else than
>  a dot (".") to represent a decimal point.  (Non-option assigment means:
>  awk '...{...}' var=val (as opposed to awk -v var=val '...{...}')..)
>
>  The fractional part is truncated for both "." and ",".
>
> Problem 2:
>
>  This is with the -v var=val form of command line assignments: Using
>  this form with a different character for the decimal point yields
>  about the opposite result: both characters are recognized as decimal
>  point sign.
>
>
> To reproduce the problem:
>
> Locale environment:
>  $ locale -a
>  [..]
>  de_DE.utf8
>  en_US.utf8
>  [..]
>
> Unless otherwise noted in the following examples, the en_US.utf8
> environment is used (it's my system wide default ($LANG)).
>
> given the following awk script (assigned to a shell variable):
>
> awktest='{
>   printf "a: \"%s\"->%f, b: \"%s\"->%f\n", a, a, b, b
> }'
>
> the following results are obtained:
>
>  $ echo | awk "$awktest" a=1.23 b=4,56
>  a: "1.23"->1.230000, b: "4,56"->4.000000
>
> ok.

$ echo | awk "$awktest" a=1.23 b=4,56
a: "1.23"->1.230000, b: "4,56"->4.000000

So far so good, everything is fine.

>  $ echo | LC_NUMERIC=de_DE.utf8 awk "$awktest" a=1.23 b=4,56
>  a: "1.23"->1,000000, b: "4,56"->4,000000

$ echo | LC_NUMERIC=de_DE.utf8 awk "$awktest" a=1.23 b=4,56
a: "1.23"->1.230000, b: "4,56"->4.000000

Here is where things diverge; I get the correct answer for a,
as well as the expected answer for b.

> Neither "." (correct) nor the now current deciaml point (",") are
> recognized.  (Btw, changing the last printf argument from `b´ into 
> `b ""´ (concatenation with the empty string) yields the correct result,
> which seems to indicate to me that the error happens very early during the
> interpretation of the command line argument).
>
> Now to problem #2 (which is less likely to cause real problems):
>
>  $ echo | awk -v a=1.23 -v b=1,23 "$awktest"
>  a: "1.23"->1.230000, b: "1,23"->1.000000
>
> Looks correct.

$ echo | awk -v a=1.23 -v b=1,23 "$awktest"
a: "1.23"->1.230000, b: "1,23"->1.000000

Here too. So far so good.

>  $ echo | LC_NUMERIC=de_DE.utf8 awk -v a=1.23 -v b=1,23 "$awktest"
>  a: "1.23"->1,230000, b: "1,23"->1,230000
>
> I'd expect 1,0000 for a's numeric value.

$ echo | LC_NUMERIC=de_DE.utf8 awk -v a=1.23 -v b=1,23 "$awktest"
a: "1.23"->1.230000, b: "1,23"->1.000000

Here too, I get the correct, expected results.

So, I don't know what to tell you. What system are you using?
Did you compile gawk from source?
Also, can you try the version from the public CVS at Savannah?

Thanks,

Arnold





reply via email to

[Prev in Thread] Current Thread [Next in Thread]