From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Arne Babenhauserheide Newsgroups: gmane.lisp.guile.devel Subject: Re: Immediate doubles (up to 2^256) and rationals coming to Guile 3 Date: Sat, 08 Jun 2019 10:07:45 +0200 Message-ID: <87blz8wlda.fsf@web.de> References: <87zhmvaw5p.fsf@netris.org> <877e9wc210.fsf@netris.org> Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="151136"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: mu4e 1.2.0; emacs 26.1 To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Sat Jun 08 10:08:03 2019 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hZWOR-000dC3-CD for guile-devel@m.gmane.org; Sat, 08 Jun 2019 10:08:03 +0200 Original-Received: from localhost ([::1]:56082 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hZWOQ-0006JP-CX for guile-devel@m.gmane.org; Sat, 08 Jun 2019 04:08:02 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58338) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hZWON-0006JJ-Kl for guile-devel@gnu.org; Sat, 08 Jun 2019 04:08:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hZWOM-0005hp-Fd for guile-devel@gnu.org; Sat, 08 Jun 2019 04:07:59 -0400 Original-Received: from mout.web.de ([212.227.15.14]:60323) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1hZWOM-0005eT-1C for guile-devel@gnu.org; Sat, 08 Jun 2019 04:07:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1559981270; bh=QNV5kFw6zzdFc6jFN/eBerRB4gEzwj8N/qpkzR1gNik=; h=X-UI-Sender-Class:References:From:To:Subject:In-reply-to:Date; b=GCd40qiDojJ2IblK4H6VimN5y1gkwZvdBxqZF4VLjSqj87jUXx0Z/Z+kizc4lrv8F H+p89rsK/YmYO3djSF5CZpLAEzEekkYCcylbekKebqooHbn+EjR+kxyaXJnjTEA0Dv 6Ko6rqf6tnPUOP9dccnPZ5gTNTtiN//ND8B4VeYg= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Original-Received: from fluss ([84.149.88.72]) by smtp.web.de (mrweb003 [213.165.67.108]) with ESMTPSA (Nemesis) id 0MGifp-1hM1zz3QK9-00DYIg; Sat, 08 Jun 2019 10:07:50 +0200 In-reply-to: <877e9wc210.fsf@netris.org> X-Provags-ID: V03:K1:Hq1xVcivk02KGYlJoQXZJ2hRFzEWUMraTQdi9psJME7z7AFzJZL vrA9WlcINt7p10jBtqThkH4AKzm4KefGdXZrxTi91AQQMdMkTwxkBi9Yu/gVTg59DJhVMsp KTr47Jbs+lOATt+oR0aGU3KbxrJ8D/slBAxjJScpq2+vMY5yiWiNFYhZs4SP3scTVSNuir1 Mm0B15kiKb45GsQ2gScfw== X-UI-Out-Filterresults: notjunk:1;V03:K0:Z9K5ttIZyq8=:zYhAnBOjTqIG4cGcbavqEm zwrl9zc22QRzlEyYkA7CQse8a3ytRN+yfsBfik2hzvJAWPLsfei/a6kyG2oKmiAcz+PC8V9cz cBsNOm8TR7uJzly5CM2/AWAiyvzReVstZzLIbvx251rUp3jhfK4QglklUAyeD3n0Ps/k5cLDX /bVylb5bMeAx/+GIFJMnfYQVOh7L3R6AOTXUtJ9I4wZcCTwcq+4tQL44BVlJAwtwxS8YtsuIy 5SZ6LuaTI6gVOpzrmPBCDdaDvmlfnjSyjVUDzE02nrsvBdxFOVM4fahK8f+OoOcC5h81BifDc jBgdBsrc/Z/cECXjv9kE2uFVEjPc6tiMW4KspxsNXuxgQo5JK6aA7sELg4mrMiJZPcu3rCZY+ Z5kykFGL2MhAovgU1F6Z4TbqiTVgPEnreFuMtRZEi2MmTbFxvMBhRhTwBTQu8PN+lYiEquZlk Q7KBAW9FI5IgDJTIODADEyOVcsJHdml1TgaXe3qu8VMB+HeQVrePvBhBxC3pBTlczWyasmgTo g== X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 212.227.15.14 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.org gmane.lisp.guile.devel:19953 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mark H Weaver writes: > Mark H Weaver writes: > >> Here's the format of fixrats on 64-bit systems: =E2=80=A6=20 > This allows for an elegant packing operation: > > if (SCM_I_INUMP (numerator) && SCM_I_INUMP (denominator)) > { > union { double f; uint64_t u; } u; > u.f =3D SCM_I_INUM (numerator); > u.u +=3D SCM_I_INUM (denominator); Wow, I didn=E2=80=99t know that you could do that. However: "The details of that allocation are implementation-defined, and it's undefined behavior to read from the member of the union that wasn't most recently written." https://en.cppreference.com/w/cpp/language/union Can you guarantee that this works? > if ((scm_t_inum) u.f =3D=3D SCM_I_INUM (numerator)) > { > u.u +=3D 0xc010000000000000; > u.u =3D (u.u << 6) | (u.u >> 58); > if ((u.u & 0x1f) =3D=3D 0) > return SCM_PACK (u.u | scm_fixrat_tag); > } > } > > We start by converting the numerator into an IEEE double. We then use > unsigned integer addition to add the denominator to the 64-bit > representation of that double. We now check that this new IEEE double > has integer part equal to the numerator. If it doesn't, this indicates > either that the numerator is too large to be represented exactly, or > that the denominator is too large to fit in the remaining bits. > > The only thing that remains to be done at this point is to rotate left 6 > bits, so that the 5 highest exponent bits become the lowest 5 bits, > where the fixrat tag will go, and to add a value which adjusts the IEEE > biased exponent field to be 0 when the numerator is 1 or -1. It is really cool to read these deep details =E2=80=94 is there a chance th= at when this lands you could re-vamp the emails you wrote here into a blog-post we can easily link to? Best wishes, Arne =2D- Unpolitisch sein hei=C3=9Ft politisch sein ohne es zu merken --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEE801qEjXQSQPNItXAE++NRSQDw+sFAlz7bNIACgkQE++NRSQD w+uqSw//QGOoASvA78zG6GglQtCFBt6IcLDxiJCAJtx/sJAPns1UkaEUawaNY5bZ c7Rxew0q39vYnLFrzsmfgEIWECb58VOQAUZ4C3muk7J6GlH6lOu7MlqCBfEtFSGw lZNHIozWzQUgsM3QE3U6QJgB9lSEJWAyygy3dbQaHlR+FUM6cdCcIsFC0Sph+dJV kVwFuLTDE4Szk5hpYMUs5i70M0GkQyUbeHhudsQn7PSFLLNP/yuDQPUXUclUQzcB YEKIqz1wA3RirwlrEhsmlSeQoRPKMqKdajrHPjru/TpBhCanudNkb6LMJDkqLj5j E5PPkJYUYa0trT96pUWoNRS4ipY60m+wjj4KpjWUQPE22Wn8+cVThUOJhFpiE9fz Z8uyZalg17cqAHUfXs/Cw4v14N8ZftOCscLgH6R5YX5UasamZr9YEFj20Ht4cn8K liK9m3RREwp4LinGKj8KFIbuQqSJ6+pbJmWUxBe+9qMAVm3CAZAIMVDYZwLvQVF9 oEgx7hnJFlh+9Co/JMsW+FGxAHt9iqmZ3sjIb78+49sJa7T3bn4G2QvU7V9tcCSE rEVwgc73dKVAmOPbTKU+3RRKfiRDyoIa/vCIJ6uFQvr+FF/AjloM9OuiuXUxhuS4 qdQTzanxbhCmYSfzxrMdA4HfEQvIexEH3zc+fTIAaL//WRdOTEaIswQBAQgAHRYh BN0ovebZh1yrzkqLHdzPDbMLwQVIBQJc+2zVAAoJENzPDbMLwQVI1JUEAJiUaa8A NTkyegJKqs+JtLniXhqluAS5ZAoe9B/yJYfd3SDf4MpyPaiaR1rkz+JlvogaA3aa jA7Ean3hnNZ9PJjIO2YkdyW6ouly0ZkPv95d86GNPMrU1gEA+cGYyE9+r4CQjZh+ ywhx0iD82zNb1QSR8uKWpZtdj4eNJlOxudDh =i29E -----END PGP SIGNATURE----- --=-=-=--