Linux-man Archive on lore.kernel.org
 help / color / Atom feed
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: Florian Weimer <fweimer@redhat.com>,
	Alejandro Colomar via Libc-alpha <libc-alpha@sourceware.org>,
	linux-man@vger.kernel.org, gcc-patches@gcc.gnu.org,
	mtk.manpages@gmail.com
Subject: Re: [PATCH 1/4] system_data_types.7: Add '__int128'
Date: Sat, 3 Oct 2020 01:44:34 +0200
Message-ID: <1f1430df-4bca-5cb4-1fc9-ae24c6a355bf@gmail.com> (raw)
In-Reply-To: <936422e4-d292-d435-6c3c-333b924b8ad0@cs.ucla.edu>

Hi Paul,

On 2020-10-02 22:19, Paul Eggert wrote:
 > On 10/2/20 1:03 PM, Alejandro Colomar wrote:
 >> I know it's not in stdint,
 >> but I mean that it behaves as any other stdint type.

With caveats, of course.

 >
 > It doesn't. There's no portable way to use scanf and printf on it.

I didn't need to.  Yes that's a problem.
It may be possible to write a custom specifier for printf,
but I didn't try.  I wrote one for printing binary,
and it's not that difficult.

If you really need it, this might help:

https://github.com/alejandro-colomar/libalx/blob/d193b5648834c135824a5ba68d0ffcd2d38155a8/src/base/stdio/printf/b.c

 > You can't reliably convert it to intmax_t.

Well, intmax_t isn't really that useful.
I see it more like a generic type, than an actual type.

I guess you could have

typedef __int128 intwidest_t;

if you find it's useful to you.


 > It doesn't have the associated _MIN and _MAX macros
 > that the stdint types do. It's a completely different animal.

Those are really easy to write.
For my use cases, they have been enough.
These might be useful to you:


#define UINT128_C(c)	((uint128_t)c)
#define INT128_C(c)	(( int128_t)c)
#define UINT128_MAX	((uint128_t)~UINT128_C(0))
#define INT128_MAX	(( int128_t)(UINT128_MAX >> 1))
#define INT128_MIN	(( int128_t)(-INT128_MAX - 1))


 >
 > If all you need are a few bit-twiddling tricks on x86-64, it should
 > work. But watch out if you try to do something fancy, like multiply or
 > divide or read or print or atomics. There's a good reason it's excluded
 > from intmax_t.

I know, they aren't perfect.
But they are still very useful,
and don't see a good reason to not document them.

Cheers,

Alex

  reply index

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-01 16:34 [PATCH 0/4] Document 128-bit types Alejandro Colomar
2020-10-01 16:34 ` [PATCH 1/4] system_data_types.7: Add '__int128' Alejandro Colomar
2020-10-02 11:47   ` Florian Weimer
2020-10-02 17:52     ` Paul Eggert
2020-10-02 19:01       ` Alejandro Colomar
2020-10-02 19:54         ` Paul Eggert
2020-10-02 20:03           ` Alejandro Colomar
2020-10-02 20:19             ` Paul Eggert
2020-10-02 23:44               ` Alejandro Colomar [this message]
2020-10-02 23:53                 ` Paul Eggert
2020-10-05  7:12           ` Florian Weimer
2020-10-07  6:53             ` Michael Kerrisk (man-pages)
2020-10-07  6:57               ` Florian Weimer
2020-10-01 16:34 ` [PATCH 2/4] __int128.3: New link to system_data_types(7) Alejandro Colomar
2020-10-01 16:34 ` [PATCH 3/4] system_data_types.7: Add 'unsigned __int128' Alejandro Colomar
2020-10-01 16:34 ` [PATCH 4/4] unsigned-__int128.3: New link to system_data_types(7) Alejandro Colomar
2020-10-02 12:28 ` [PATCH v2 0/4] Document 128-bit types Alejandro Colomar
2020-10-02 12:28 ` [PATCH v2 1/4] system_data_types.7: Add '__int128' Alejandro Colomar
2020-10-02 12:28 ` [PATCH v2 2/4] __int128.3: New link to system_data_types(7) Alejandro Colomar
2020-10-02 12:28 ` [PATCH v2 3/4] system_data_types.7: Add 'unsigned __int128' Alejandro Colomar
2020-10-02 12:28 ` [PATCH v2 4/4] unsigned-__int128.3: New link to system_data_types(7) Alejandro Colomar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1f1430df-4bca-5cb4-1fc9-ae24c6a355bf@gmail.com \
    --to=colomar.6.4.3@gmail.com \
    --cc=eggert@cs.ucla.edu \
    --cc=fweimer@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libc-alpha@sourceware.org \
    --cc=linux-man@vger.kernel.org \
    --cc=mtk.manpages@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-man Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-man/0 linux-man/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-man linux-man/ https://lore.kernel.org/linux-man \
		linux-man@vger.kernel.org
	public-inbox-index linux-man

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-man


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git