简体   繁体   中英

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. (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).

"Bigint" libraries accomplish their magic by wrapping the standard library in mathematical algorithms and such. 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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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