### Perl: Math::BigInt

Math::BigInt提供了非常多方法，而且很多方法也有对应的运算符重载，支持bin, oct, dec, hex格式字符串与BigInt之间的相互转化，几乎没有不支持的操作，包括三角函数，二项式系数都有。不过Math::BigInt有很多不同的实现，其中最快的是Math::BigInt::GMP，效果还是非常理想的，但是默认的Math::BigInt::Calc就慢得不能忍了，远比php, java, ruby, python的都要慢。另外Math::BigFloat是基于Math::BigInt的高精度浮点数。

```use Math::BigInt lib => 'GMP';
use Math::BigFloat try => 'GMP';
print Math::BigFloat->bpi(64), "\n"; # 3.14...
my \$x = new Math::BigInt('0x123456789abcdef');
my \$y = Math::BigInt->new('0b101010101010101');
print \$x + \$y, "\n";
print join(":", \$x->copy()->bdiv(\$y)), "\n";
```

### Bash: bc

```#!/usr/bin/bc -q

define e(n) {
auto i, p, s;
p = 10 ^ n;
s = 2 * p;
for (i = 2; p > 0; ++i) {
p /= i;
s += p;
}
return s;
}

print "input a integer: "
e(x)
quit

# input a integer: 40
# 27182818284590452353602874713526624977552
```

### Php: BCMath

bc是Binary Calculator的

SPOJ24. Small factorials[FCTRL2]就是阶乘计算加高精度运算。以下是用内置大数支持的perl, php, java, ruby, python, haskell, bash, scheme等语言实现的代码。

```main = interact \$ unlines . map (\i -> show \$ f !! read i) . tail . words
where f = scanl (*) 1 [1 ..]
```

### perl

```#!/usr/bin/perl -w

use strict;
use Math::BigInt lib => 'GMP';

my @f = ();
push @f, Math::BigInt->new(1);
for (my \$i = 1; \$i <= 100; ++\$i) {
push @f, \$f[\$#f]->copy()->bmul(\$i);
}
chomp(my \$re = <STDIN>);
for (my \$ri = 1; \$ri <= \$re; ++\$ri) {
chomp(my \$n = <STDIN>);
print "\$f[\$n]\n";
}
```

### php

C

```/* A + B Problem in C */
#include <stdio.h>

int main(void) {
int a, b;

while (scanf("%d%d", &a, &b) != EOF) {
printf("%d\n", a + b);
}

return 0;
}
```