简体   繁体   English

仅使用C ++标准库的256位整数?

[英]256-bit integer using only the C++ standard library?

Let's consider we want to store 128/256-bit integers and perform arithmetical operations on them, using the C++ standard library only. 考虑到我们想存储128/256位整数并仅使用C ++标准库对其执行算术运算。 (no additional libraries) (没有其他库)

Is this possible? 这可能吗?

Is this possible? 这可能吗?

Of course! 当然! How did you think the libraries are constructed? 您如何看待图书馆的建设?

Every component in programming is constructed from smaller components, ultimately the building blocks of the language itself and its standard library (and potentially some platform-specific native API). 编程中的每个组件都是由较小的组件构成的,最终是语言本身及其标准库(可能还有某些特定于平台的本机API)的构建块。

"Bigint" libraries accomplish their magic by wrapping the standard library in mathematical algorithms and such. “ Bigint”库通过将标准库包装在数学算法等中来实现其魔力。 You could do the same if you had the time. 如果有时间,您也可以这样做。 You can create one without even the standard library: ultimately, all you need are some classes, some int s and some bit shifts. 您甚至可以创建一个甚至没有标准库的库:最终,您所需要的只是一些类,一些int和一些移位。 In fact, you could do it without the classes — just pass eight 32-bit integers into every function, and have those functions perform mathematics to accomplish your goal. 实际上,您可以在没有类的情况下做到这一点-只需将八个32位整数传递给每个函数,然后让这些函数执行数学即可实现您的目标。 Whether the result will be any "good" is debatable. 结果是否将是“好”是有争议的。

People write those libraries in order to make the most performant approach as convenient and easy-to-use as possible, for example by bundling those eight integers into a single type. 人们编写这些库是为了使最高效的方法尽可能方便和易于使用,例如,将这八个整数捆绑为一个类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM