How to enable __int128 on Visual Studio?

前端 未结 6 1331
天命终不由人
天命终不由人 2020-11-28 13:29

When I type __int128 in a C++ project in Visual Studio, the editor changes color of __int128 to blue (like keyword).

But when I compile the

6条回答
  •  不知归路
    2020-11-28 14:02

    Your conversions to/from string could use some improvement.

    For saftey, the interface for converting to a string should include the allocated length of the user provided string, so you can return an error if they didn't provide enough memory.

    Also, try to process strings in chunks: for example, suppose the user wants to convert a 128 bit number into base 10. Instead of repeatedly doing modulo 10, you could be doing modulo 1000000000ul, and using sprintf(s, "%09u", c).

    Converting from a string could be similarly optimized.

    It would not be a bad idea to include a divrem method, with a return type of std::pair<_uint128, _uint128>.

    It would be absolutely awesome if you had a integer class where the type used for hi and lo was a template parameter. Then, with a small handful of typedefs, you could create an int256, an int512, etc..

提交回复
热议问题