Questions tagged [int128]

Use this tag to refer to the 128-bit integers. For example, SIMD registers, a non-standard compiler extension on 64-bit platforms, or IPv6 addresses.

The 128-bit integers are a non-standard compiler extension on 64-bit platforms. The basic arithmetic and bitwise operations work on these data types in the same fashion as normal integers.

68 questions
8
votes
4 answers

C# Custom data type!

Possible Duplicate: Int128 in .Net? After I decided to implement my Int128 in C#, I thought it would be nice to make it look like other dotNet data types.. But I could not implement the following feature: suffix initialization: such as 13L and…
Betamoo
  • 14,964
  • 25
  • 75
  • 109
8
votes
3 answers

Is __int128_t arithmetic emulated by GCC, even with SSE?

I've heard that the 128-bit integer data-types like __int128_t provided by GCC are emulated and therefore slow. However, I understand that the various SSE instruction sets (SSE, SSE2, ..., AVX) introduced at least some instructions for 128-bit…
Douglas B. Staple
  • 10,510
  • 8
  • 31
  • 58
7
votes
1 answer

Integer overflow with UDL (user defined literal) for __int128 @ min negative value

For clarity and simplicity I will shorten the following numbers as follows: −170,141,183,460,469,231,731,687,303,715,884,105,728 as -170…728 170,141,183,460,469,231,731,687,303,715,884,105,727 as 170…727 These numbers represent the minimum and…
bolov
  • 72,283
  • 15
  • 145
  • 224
5
votes
3 answers

Can I access the two 64-bit registers in __uint128_t separately?

Consider the code below. We know that a __uint128_t variable is stored in 2 64-bit registers (Assume x64 processor). Requirement is to store the first 64 bits in one unsigned long variable and the next 64 bits in another unsigned long…
Knm
  • 55
  • 4
5
votes
1 answer

Why does gcc give a warning saying that the constant is unsigned because it is too large, when it is of the type __int128 and is signed?

Consider the following code: #include int main(void) { printf("%llu\n", 18446744073709551615); printf("%llu\n", 18446744073709551615ULL); return 0; } Upon compilation (gcc -std=c18), I get the following warnings: test1.c: In…
Box Box Box Box
  • 5,094
  • 10
  • 49
  • 67
5
votes
2 answers

An efficient way to do basic 128 bit integer calculations in C++?

Some years ago I needed a way to do some basic 128 bit integer math with Cuda: 128 bit integer on cuda?. Now I am having the same problem, but this time I need to run some basic 128 bit arithmetics (sums, bitshifts and multiplications) on a 32 bit…
Matteo Monti
  • 8,362
  • 19
  • 68
  • 114
4
votes
4 answers

Arithmetic with IPv6 addresses (large integers)

I'm working with IPv6 addresses in the form: FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF Internally, I store them in an array: TIp6Bytes = array [0..15] of Byte; I need to manipulate the IPv6 addresses in a number of ways including adding, dividing,…
norgepaul
  • 6,013
  • 4
  • 43
  • 76
4
votes
1 answer

__uint128_t not working with Clang and libstdc++

Consider the following small test program for type traits of the GNU-extensions for __uint128_t #include #include using uint128_t = __uint128_t; int main() { static_assert(std::is_unsigned{}, ""); …
TemplateRex
  • 69,038
  • 19
  • 164
  • 304
4
votes
1 answer

Fastest way to multiply two 64-bit ints to 128-bit then >> to 64-bit?

I need to multiply two signed 64-bit integers a and b together, then shift the (128-bit) result to a signed 64-bit integer. What's the fastest way to do that? My 64-bit integers actually represent fixed-point numbers with fmt fractional bits. fmt is…
Michel Rouzic
  • 1,013
  • 1
  • 9
  • 22
4
votes
1 answer

Is there a way to use __int128_t with the Android NDK?

Is there a way to use __int128_t with the Android NDK? I tried to use GNU toolchain 4.9 but I get the following error no matter how I try: error: '__int128_t' was not declared in this scope -std=gnu++11 is enabled of course.
Tamas
  • 3,254
  • 4
  • 29
  • 51
3
votes
1 answer

In C#, how do I extract the two UInt64 values that make up a UInt128?

Suppose I have a UInt128 like this UInt64 upperA = 7, lowerA = 8; UInt128 foo = new(upperA, lowerA); ++foo; And now I want to extract the two UInt64s from the updated foo. If they were properties, I could do this UInt64 upperB = foo.Upper, lowerB =…
Hal Heinrich
  • 544
  • 1
  • 4
  • 21
3
votes
2 answers

Multiplication of 2 positive numbers in Julia gives a negative product

In Julia 1.7.2 multiplication of 3037000691 and 3037000693 returns the negative product -9223370870501072753. The product I expected is 9223373203208478863. function m(a::BigInt, b::BigInt)::BigInt a * b end This function gives the same…
René
  • 4,594
  • 5
  • 23
  • 52
3
votes
1 answer

Square root of a u128

How can the square root of a u128 be calculated? The resulting number can be a u128 after some rounding. f64 has a f64::sqrt function, but I dont think we should be converting u128 to f64.
Nyxynyx
  • 61,411
  • 155
  • 482
  • 830
3
votes
1 answer

How to resolve a possible multiplicative overflow to get correct modulus operation?

I have to perform (a * b) % m, but a, b, and m are 128-bit unsigned types, and overflow during multiplication is a large possibility. How can I still get a correct answer (probably using % more)? I'm trying to implement the modular exponent function…
ARaspiK
  • 155
  • 10
3
votes
3 answers

C modulus returning negative number

I have data type unsigned __int128 data; so I don't think this is a type issue, but I have no idea why it is occuring #include int main(int argc, char *argv[]) { unsigned __int128 z = 1911602146; unsigned __int128 n =…
Kendall Weihe
  • 2,021
  • 4
  • 27
  • 53