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的

1. ? – Nullable<T>

```[SerializableAttribute]
public struct Nullable<T> where T : struct, new()
```

C#里像int, bool, double这样的struct和enum类型都不能为null。如果确实想在值域上加上null的话，Nullable就派上用场了。T?是Nullable&ly;T>的语法糖。要将T?转为T可以通过类型转换，或者通过T?的Value属性，当然后者要高雅些。

```// Nullable<int> arg = -1;
int? arg = -1;
if (arg.HasValue) {
// int value = (int)arg;
int value = arg.Value;
}
```

2. ?? – operator ??

o ?? v可以看作是o == null ? v : o的语法糖。??运算符在左操作数非null时返回左操作数，否则返回右操作数。

```string result = gao();
Console.WriteLine(result ?? "<NULL>");
```

3. => – lambda expression

```Func<double, double, double> hypot = (x, y) => Math.Sqrt(x * x + y * y);
Func<double, double, string> gao = (x, y) =>
{
double z = hypot(x, y);
return String.Format("{0} ^ 2 + {1} ^ 2 = {2} ^ 2", x, y, z);
};
Console.WriteLine(gao(3, 4));
```

4. {} – initializer

collection initializer使得初始化一个List, Dictionary变得简单。

```List<string> list = new List<string>{"watashi", "rejudge"};
Dictionary<string, string> dic = new Dictionary<string, string>
{
{"watashi", "watashi wa watashi"},
{"rejudge", "-rejudge -pia2dea4"}
};
```