猛砸数限制? [英] Bash Number Limit?

查看:135
本文介绍了猛砸数限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我问一个问题更早,涉及拉大从文本文件素数,并把它们变成另一个文件。它应该抓住每一个主要截至及包括后2 ^ 32的第一个鼎盛时期,出于某种原因这个脚本停止工作。

 #!/斌/庆典
N = 4294967296
最后= 0
而阅读次数
    做
    如果[$最后-gt $ N]
    再突破
    科幻
    回声$号
最后= $号
完成< primes.txt> primes2.txt

它结束了通过这11个数字循环:

  4232004449
4232004479
4232004493
4232004509
4232004527
4232004533
4232004559
4232004589
4232004593
4232004613
004437

原始文件没有 004437 在里面,我的bash将处理超过 8999999999999999999

任何人是否有一个线索,为什么会这样?


  

64位的Ubuntu 10.04,16GB内存,8核@ 3.60 GHz的结果
  GNU的bash,版本4.1.5(1) - 释放下(x86_64-PC-Linux的GNU)


更新:

下载与编译通过jfgagne提供的固定bash和在我的bash脚本链接到它之后,它在相同的确切位置出错了。使用从我原来的首要问题显著更快的perl相当,我得到了一些文件大小从LS -al:

  11 next_prime(只是为了确保这是正确计算字节)
2147483659 primes2.txt
2147483670 one_too_many

2147483659 = 2 ^ 31 + 11

下一任( 4232004631 )的11个字节的大小
这包含所有的素数高达 4232004613 。我也意识到,在 004437 从黄金的结束这个错误循环的底部来临( 4232004437 ) 。这看起来似乎是试图前进,但卡住了。


解决方案

没有,它是独立于操作系统的bitsize。它取决于一个简单的声明深处bash的来源。

本声明自2002年以来各地__int64_t此后,bash的版本> = 3.00始终使用64位整型变量,它不依赖于架构!这仅取决于bash的版本。

庆典的

previous版本中使用的通常是32位整数,即使在64位操作系统。

I asked a question earlier that involved pulling large primes from a text file and putting them into another file. It was supposed to grab every prime up to and including the first prime after 2^32, and for some reason this script stopped working.

#!/bin/bash
n=4294967296
last=0
while read number
    do
    if [ $last -gt $n ]
    then break
    fi
    echo $number
last=$number
done < primes.txt > primes2.txt

It ended up looping through these 11 numbers:

4232004449  
4232004479  
4232004493  
4232004509  
4232004527  
4232004533  
4232004559  
4232004589  
4232004593  
4232004613  
004437

The original file didn't have 004437 in it, and my bash will handle numbers over 8999999999999999999

Does anybody have a clue as to why this happened?

64-bit Ubuntu 10.04, 16GB RAM, 8-cores @ 3.60 GHz
GNU bash, version 4.1.5(1)-release (x86_64-pc-linux-gnu)

Update:

After downloading and compiling the "fixed" bash provided by jfgagne and linking to it in my bash script, it errored out at the same exact spot. Using the significantly faster perl equivalent from my original prime question, I got some file sizes from ls -al:

        11  next_prime (just to make sure this was counting bytes accurately)
2147483659  primes2.txt
2147483670  one_too_many

2147483659 = 2^31 + 11

The size of the next prime (4232004631) is 11 bytes This holds all primes up to 4232004613. I also realized that the 004437 is coming from the end of the prime at the bottom of this error loop (4232004437). It seems like something is trying to advance, but stuck.

解决方案

No, it is independent from the bitsize of your OS. It depends upon a simple declaration deep in the bash sources.

This declaration is __int64_t since around 2002. Since then, bash versions >= 3.00 always use 64bit integer variables, and it doesn't depend on the architecture! It only depends on the bash version.

Previous versions of bash used always 32 bit integer, even on 64 bit OS.

这篇关于猛砸数限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆