shiny_shine's blog

By shiny_shine, history, 8 months ago, In English

As you know, in this reason, 64-bit C++ compilers are temporarily disabled.

In order to keep using __int128 (at least partially) in 32-bit compilers, I'm trying writing a template of the unsigned version of __int128.

On 2024/3/15, I completed writing the alpha version of it.

If you find bugs in my code, please leave a comment below. Thanks!

UPD:

2024/3/14: added (maybe) all operators that an __int128 has except for operator/ / fixed infinite-recursion bug in several operators

2024/3/15: added operator/ / fixed many bugs in almost all arithmetic operators / completed first (buggy) version of this handmade __int128

Here's it:

integer_128_impl.cpp
  • Vote: I like it
  • +19
  • Vote: I do not like it

»
8 months ago, # |
  Vote: I like it +11 Vote: I do not like it

This works similar to how people would hack higher precision real numbers into older system that does not provide support a long time ago. Pretty cool!

»
8 months ago, # |
  Vote: I like it 0 Vote: I do not like it

The code is pretty neat.

Meanwhile, I found something similar to your implementation: the std::_Signed128 and std::_Unsigned128 in MSC++2019, which may be a firm reference for implementing signed __int128.

»
8 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by shiny_shine (previous revision, new revision, compare).

»
8 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Very nice code! There is also an alternative one adapted from abseil, with some modification. Unfortunately, it is tediously long.

Spoiler
»
8 months ago, # |
  Vote: I like it 0 Vote: I do not like it
    ll min(ll x,ll y){
        return x<y?x:y;
    }

    ll max(ll x,ll y){
        return x>y?x:y;
    }

Seriously?

  • »
    »
    8 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    In fact it doesn't matter if you remove them

    but I think this impl has a better performance

»
8 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by shiny_shine (previous revision, new revision, compare).

»
8 months ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by shiny_shine (previous revision, new revision, compare).