Обсуждение: 128-bit integers can range only up to (2 ^ 63 -1)
include/pg_config.h
14: #define ALIGNOF_PG_INT128_TYPE 16
355: #define MAXIMUM_ALIGNOF 8
374: #define PG_INT128_TYPE __int128
/include/c.h
507: /*
508: * 128-bit signed and unsigned integers
509: * There currently is only limited support for such types.
510: * E.g. 128bit literals and snprintf are not supported; but math is.
511: * Also, because we exclude such types when choosing MAXIMUM_ALIGNOF,
512: * it must be possible to coerce the compiler to allocate them on no
513: * more than MAXALIGN boundaries.
514: */
515: #if defined(PG_INT128_TYPE)
516: #if defined(pg_attribute_aligned) || ALIGNOF_PG_INT128_TYPE <= MAXIMUM_ALIGNOF
517: #define HAVE_INT128 1
518:
519: typedef PG_INT128_TYPE int128
520: #if defined(pg_attribute_aligned)
521: pg_attribute_aligned(MAXIMUM_ALIGNOF)
522: #endif
523: ;
524:
525: typedef unsigned PG_INT128_TYPE uint128
526: #if defined(pg_attribute_aligned)
527: pg_attribute_aligned(MAXIMUM_ALIGNOF)
528: #endif
529: ;
530:
531: #endif
532: #endif
533:
14: #define ALIGNOF_PG_INT128_TYPE 16
355: #define MAXIMUM_ALIGNOF 8
374: #define PG_INT128_TYPE __int128
/include/c.h
507: /*
508: * 128-bit signed and unsigned integers
509: * There currently is only limited support for such types.
510: * E.g. 128bit literals and snprintf are not supported; but math is.
511: * Also, because we exclude such types when choosing MAXIMUM_ALIGNOF,
512: * it must be possible to coerce the compiler to allocate them on no
513: * more than MAXALIGN boundaries.
514: */
515: #if defined(PG_INT128_TYPE)
516: #if defined(pg_attribute_aligned) || ALIGNOF_PG_INT128_TYPE <= MAXIMUM_ALIGNOF
517: #define HAVE_INT128 1
518:
519: typedef PG_INT128_TYPE int128
520: #if defined(pg_attribute_aligned)
521: pg_attribute_aligned(MAXIMUM_ALIGNOF)
522: #endif
523: ;
524:
525: typedef unsigned PG_INT128_TYPE uint128
526: #if defined(pg_attribute_aligned)
527: pg_attribute_aligned(MAXIMUM_ALIGNOF)
528: #endif
529: ;
530:
531: #endif
532: #endif
533:
Hi.
I am slightly confused by the int128 type. I thought the 128 bit integer means range type will be upto 2 ^ 127 - 1.
Now just copy the above code and test the int128 range.
int128 can only up to 9223372036854775807 (2 ^ 63 -1).
also
File: /home/jian/helloc/pg/pg_interval/include/pg_config_ext.h
6: /* Define to the name of a signed 64-bit integer type. */
7: #define PG_INT64_TYPE long int
6: /* Define to the name of a signed 64-bit integer type. */
7: #define PG_INT64_TYPE long int
I also thought that 64-bit means range up to 2 ^ 63 -1. Obviously I was wrong.
So when we say "128 bit" what does it actually mean?
I recommend David Deutsch's <<The Beginning of Infinity>>
Jian
jian he <jian.universality@gmail.com> writes: > I am slightly confused by the int128 type. I thought the 128 bit integer > means range type will be upto 2 ^ 127 - 1. > Now just copy the above code and test the int128 range. > int128 can only up to 9223372036854775807 (2 ^ 63 -1). What's your grounds for claiming that? regards, tom lane
On Tue, Jan 3, 2023 at 8:50 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
jian he <jian.universality@gmail.com> writes:
> I am slightly confused by the int128 type. I thought the 128 bit integer
> means range type will be upto 2 ^ 127 - 1.
> Now just copy the above code and test the int128 range.
> int128 can only up to 9223372036854775807 (2 ^ 63 -1).
What's your grounds for claiming that?
regards, tom lane
I did something like int128 a1 = 9223372036854775807 + 1;
I also did something like int128 a1 = (int128)9223372036854775807000;
I misread the warning. I should do the cast first.
The second expression has a warning. I guess because
There is no support in GCC for expressing an integer constant of type__int128
for targets withlong long
integer less than 128 bits wide.
jian he <jian.universality@gmail.com> writes: > On Tue, Jan 3, 2023 at 8:50 PM Tom Lane <tgl@sss.pgh.pa.us> wrote: >> What's your grounds for claiming that? > I did something like int128 a1 = 9223372036854775807 + > 1; Well, that's going to do the arithmetic in (probably) long int. regards, tom lane