Under http://www.cpp.sh long same size as long long

1
2
3
4
5
6
7
8
9
// Test long vs long long
#include <iostream>

int main()
{
    unsigned long long x(~0), y(0), z(x);
    for (; z > 0; ++y, z /= 2);
    std::cout << x << " = 2^" << y << "-1";
}

long long or long only makes not difference. Or is there an option I've overlooked?
some systems, they are the same.
The size depends on your system/compiler.

int is at least 16 bits.
long is at least 32 bits.
long long is at least 64 bits.
long long is at least 64 bits.

With long it's already 64 bits , so I hoped to get with long long a bit more, or two ;)
On gcc you can include <cstdint> and try __int128_t or __uint128_t.
I don't think cout knows how to output them, though, so you may have to write your own output routine.
For arbitrarily greater than 64-bit integers, one must look into "BigInteger" or "Multiprecision" libraries.

Alternatively, if only up to 128-bit integers are needed, gcc and clang have __int128 (if supported on your system), and boost has its version of int128 as well.
https://stackoverflow.com/a/35026162/8690169 (gcc/clang __int128)
https://stackoverflow.com/a/18439628/8690169 (boost int128)
Last edited on
For arbitrarily greater than 64-bit integers, one must look into "BigInteger" or "Multiprecision" libraries.

I just try to fathom the "plain" system without additional libraries. It's for fun, not for advantage -- silly as speed driving.
silly as speed driving

Are you just a random phrase generator?
On gcc you can include <cstdint> and try __int128_t or __uint128_t.
1
2
3
4
5
6
7
8
9
10
11
// Test __uint128_t vs long long
#include <iostream>
#include <cstdint>

int main()
{
    __uint128_t x(~0), z(x);
    unsigned y(0);
    for (; z > 0; ++y, z /= 2);
    std::cout << "x = 2^" << y << "-1";
}

Works, tnx.
Registered users can post here. Sign in or register to post.