English 中文(简体)
awk
原标题:Printing long integers in awk

我有一个有几处田的管道有限饲料档案。 自2006年以来 我只需要几个方面,我想利用awk来为我的测试目的而加以捕获。 但是,我注意到,<><>>>>如果我使用%d”,则对数值作了改动。 如果我使用<><><>>>%s>,则该编码可操作。

Feed File Sample:

<><>>>[雅斯特:~/Temp] cat temp

<>strong30261000741 19769909943390313:20:02:02:606-01-2012:20:03.307 00:0017:20:20:03.03.307 007 00 007 00 007 00 007 007 007 007 007 007 007 480 480 480 0044 _______________________________________________________________________________________________________________________________________________0403030390 _____________0 _________________________________________________________________0 MOBIL CELLULAR, INC INCBELL MOBILITY CELLULAR, INCBellITY MX ARGENTINA SA. Claro aka C. C Movil, RG, TI/code>

我有兴趣了解second栏。 http://strong>197699043993903

Here are my tests:

[jaypal:~/Temp] awk -F"|"  {printf ("%d
",$2)}  temp
19769904399993904   # Value is changed

但是,以下两项测试是有效的:

[jaypal:~/Temp] awk -F"|"  {printf ("%s
",$2)}  temp
19769904399993903   # Value remains same

[jaypal:~/Temp] awk -F"|"  {print $2}  temp
19769904399993903   # Value remains same

因此,%d”的限额无法处理长期分类账。 如果是这样,为什么要增加一个而不是缩小这个数目?

我已用<<><<>条码>>和(<>条码>/code>>版<<><><><><><>><>>><>>>>进行了尝试。

Version Info:

[jaypal:~/Temp] gawk --version
GNU Awk 4.0.0
Copyright (C) 1989, 1991-2011 Free Software Foundation.

[jaypal:~/Temp] awk --version
awk version 20070501
最佳回答

我认为,本案的基本数字格式是“电子计算方法”的两倍。 因此,变值是浮动点准确错误的结果。 如果实际需要将大数值作为数字处理,并保持准确的准确性,那么最好使用像Perl、Riu、或Ze等有能力(可能通过延伸)处理武断的算术的东西。

问题回答

http://git.savannah.gnu.org/cgit/gawk.git/tree/doc/gawk.1?id=gawk-4.1.0#n345“rel=“noreferer” 页: 1

$ awk  BEGIN {print 19769904399993903} 
19769904399993904

$ awk --bignum  BEGIN {print 19769904399993903} 
19769904399993903

页: 1 Awk s Floating Point Represent Issues。 我不认为,你可以在一夫一妻框架内找到工作,准确计算大量数字。

我认为,只有可能的(和粗略的)方式,才能将巨额资金细分为小丘,重复计算并再次使用,或更好地利用比高强的Perl/PHP/TCL/bsh等文字。

Using nawk on Solaris 11, I convert the number to a string by adding (concatenate) a null to the end, and then use %15s as the format string:

printf("%15s
", bignum "")   

another caveat about the precision : the errors pile up with extra operations ::

echo 19769904399993903 | mawk2  { CONVFMT = "%.2000g";
                                     OFMT =   "%.20g"; 
        } {
           print;
           print +$0; 
           print $0/1.0
           print $0^1.0; 

           print exp(-log($0))^-1; 
           print exp(1*log($0))
           print sqrt(exp(exp(log(20)-log(10))*log($0))) 
           print (exp(exp(log(6)-log(3))*log($0)))^2^-1   
        } 
19769904399993903
19769904399993904
19769904399993904
19769904399993904
19769904399993912
19769904399993908
19769904399993628 <<<—— -275
19769904399993768 <<<—- -135

The first few only off by less than 10. last 2 equations have triple digit deltas.

对于任何需要打电话帮助者数学功能的版本来说,仅仅获得M牌大金是不够的。 还必须确定PREC变量。

对于这种外在物质而言,PREC=64OFMT=%.17g>应当足够。

相对于巴勒斯坦经济共同体而言,你知道如何将外汇储备定得太高,否则就象这样:

gawk -M -v PREC=256 -e  { CONVFMT="%.2000g"; OFMT="%.80g";... }  

19769904399993903
19769904399993903.000000000000000000000000000000000000000000000000000000000003734
19769904399993903.000000000000000000000000000000000000000000000000000000000003734
19769904399993903.000000000000000000000000000000000000000000000000000000000003734
19769904399993903.000000000000000000000000000000000000000000000000000000000003734

80 重要数字以来,至少需要精确到265.75,因此基本上需要<代码>266-bits,但gawk已经足够快,你可能安全地在PREC=4096/8192之前就安装这一系统,而不是每时都不得不担心。





相关问题
How to render a printable image from a SWF

I m working on a project at the moment where the client uses an off-the-shelf Flash library to display data against a map. It s a SWF that we feed some XML data and it renders it in various ways, such ...

Html printed page resolution (or size in pixels)

Does anybody know what is the resolution that will be used to render a printed HTML page. I d like to know what size (in centimeters or inches) will be a printed image of say 500x500pixels. I know ...

How can I select a different printer in a web application?

I have a Web application programmed in C#. There are several printers and I want to choose any of them and execute the action, I would like some kind of Form to load all printers. I found this for ...

Visual Studio 2010 Beta 2: Can I print in color?

I have to turn in a hard copy of some code with an assignment. Is there any way in Visual Studio 2010 to print C# source code with syntax highlighting? PS: The assignment is solving a math problem, ...

热门标签