我想通过此链接中的 pow 等函数在 SML 中执行大整数计算:
http://www.standardml.org/Basis/int-inf.html#IntInf:STR:SPEC http://www.standardml.org/Basis/int-inf.html#IntInf:STR:SPEC
但我如何才能使用这个“图书馆”呢?
UPDATE:
感谢你的回答。我得到了它。我还必须更改打印限制
Control.Print.intinfDepth := 10000;
我为 IntInfs 创建了自己的 pow 函数(并且它有效),如下所示:
fun power 0 = IntInf.toLarge 1
| power n = IntInf.toLarge 2 * power(n-1);
这取决于您使用的实现,但通常您需要使用以下命令将 Int 转换为 LageInt/InfInf 类型Int.toLarge
:
(* will be types as an IntInf *)
val aa = 10983298432984329843298432984329843298432987987987432987987987432987
val a = IntInf.pow(aa,10);
(* explicit type as if some other constraint had enforced this*)
val b = 10 : int
val c = Int.toLarge b;
val d = IntInf.pow(c, b);
变量aa
可能无法在您的解释器中进行解析。这取决于你使用什么。我已经在聚和米尔顿中测试过它。
其中上面获取类型(由带有 -show-basis 标志的 mlton 给出):
val a: intInf
val aa: intInf
val b: int32
val c: intInf
val d: intInf
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)