From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Israelsson Tampe Newsgroups: gmane.lisp.guile.devel Subject: Re: reader musings Date: Wed, 8 Jun 2022 14:52:49 +0200 Message-ID: References: Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000006efb1d05e0ef2feb" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21495"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-devel To: Maxime Devos Original-X-From: guile-devel-bounces+guile-devel=m.gmane-mx.org@gnu.org Wed Jun 08 15:26:10 2022 Return-path: Envelope-to: guile-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nyvhI-0005NF-OV for guile-devel@m.gmane-mx.org; Wed, 08 Jun 2022 15:26:08 +0200 Original-Received: from localhost ([::1]:38122 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyvhH-0002EQ-Fm for guile-devel@m.gmane-mx.org; Wed, 08 Jun 2022 09:26:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34508) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyvBI-0005oB-EI for guile-devel@gnu.org; Wed, 08 Jun 2022 08:53:05 -0400 Original-Received: from mail-ed1-x530.google.com ([2a00:1450:4864:20::530]:35430) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyvBG-0000wp-HP for guile-devel@gnu.org; Wed, 08 Jun 2022 08:53:04 -0400 Original-Received: by mail-ed1-x530.google.com with SMTP id x5so21858926edi.2 for ; Wed, 08 Jun 2022 05:53:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hhjIkAFemXkP9Ho+ygBdFz+vdHyOtC0YcbbpVV61CEE=; b=i1dYsWj0QGEZbJbiZNlTYAhOmzxngwobJPbwhGyJw3YaQm39UkQLKTLPJZre/hQPlq 3opT7hek5hl6MP7OLVu7ZrbKqPnLem5dAMbK00wcXr8FGQ1Ks6epbERtWj3Gp/GhtBdr n/qwi1/FEAr3YkRsUuw+ZiqR80fyGH3vwTptY/V9DIWZBA2PC8zl+ZKdINQ3VQOINQsI FZ9YHNSn2ZhwudinN6agjvG/evLTxKBuj9juRBaHkbxFOOS4EWfbc941sziVsP9uto9H Xv8GOxG8VkPBzZ+1hYPNqwqjpSoTb8lz/bFia06mTUpB7mjSVmlHi0rQFb4gGKZ65VMH G4+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hhjIkAFemXkP9Ho+ygBdFz+vdHyOtC0YcbbpVV61CEE=; b=hkcInNiWCzA9+FWGt0J7J9vF4qV+N/10fO489oqZ8Hj+rrZPbklyPnS0MkmbL+IMiq ppr5H6toBSGok3RqhL53Aeq5xDbqGzWfIijSpFmLeFAfcIUu0rH5997xsPvnl8YVIVQm jY20UL5QQRcrdvkuBXlMaZMVFa6C+RYargTuJ10thq8iNweGuXdBMLOY2pqEBmHYyQ0J uR14IPunTgx4i32SrXy7YY9IE8rqPXcVuSI7IWx7M4jtZvKdPTDcHvcvv9mL7StnvXBy I1/lVMtJrPT+1U0eZySbnBOECIk7t7NFHqgddT8ht3e7vJRmPh+kfit1/7IdultSgAdr 1xHA== X-Gm-Message-State: AOAM530NVnU06Xm/3GujO+1sikgQYzTNpevgum5n30lNBl5hDKtk5eBe VcSGszRnctmUBB88J2eIIVw8pKnorebIIA03cN626qcS X-Google-Smtp-Source: ABdhPJzBKw0uev31G++sq9l3PIzXnf7WMrqGcoXy3Wtzml6+G5NTsXtY71b60IuMKYUaznUhVCdB8J7f6Uid15LGtzw= X-Received: by 2002:a05:6402:2381:b0:42d:c8fe:d7fe with SMTP id j1-20020a056402238100b0042dc8fed7femr38574317eda.248.1654692781159; Wed, 08 Jun 2022 05:53:01 -0700 (PDT) In-Reply-To: Received-SPF: pass client-ip=2a00:1450:4864:20::530; envelope-from=stefan.itampe@gmail.com; helo=mail-ed1-x530.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.29 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-mx.org@gnu.org Original-Sender: "guile-devel" Xref: news.gmane.io gmane.lisp.guile.devel:21221 Archived-At: --0000000000006efb1d05e0ef2feb Content-Type: text/plain; charset="UTF-8" I found a better way to find the mantissa and exponent e.g. frexp and when constructing the double/float ldexp is great. That makes the code more portable. These functions are really fast and the call overhead is not terrible. On Wed, Jun 8, 2022 at 9:49 AM Maxime Devos wrote: > Stefan Israelsson Tampe schreef op wo 08-06-2022 om 01:07 [+0200]: > > https://gitlab.com/tampe/guile-persist/-/tree/master/ice-9 > > https://gitlab.com/tampe/guile-persist/-/tree/master/src/write > > > > I'm wondering if I should make a C library for other projects to take > > advantage of this work. > > Could they be integrated in Guile itself? That would reach the most > people I think. > > > int exp = (((*((uint64_t *) &d)) >> 52) & ((1L<<11)-1)) - 1023L; > uint64_t man = ((*((uint64_t *) &d)) & ((1L<<52)-1L)) + (1L << 52); > > double's aren't uint64_t, so maybe a strict aliasing vilation and hence > undefined behaviour. If so, maybe use -fno-strict-aliasing, or use > type punning through an union? > > Also, this assumes IEEE doubles, so maybe do some checks whether things > are actually IEEE (see m4/fpieee.m4, and maybe some checks like > sizeof(double)=sizeof(uint64_t) and alignof(double)=sizeof(uint64_t) > and check DBL_DIG, DBL_MANT_DIG, DBL_MAX_EXP, ...)? > > That line also assumes 'long' = 'uint64_t' (or at least, that they have > the same size), which to me seems a bold assumption to make in the > general case. > > Also, more generally, there was some paper on subtle errors that can > easily happen when printing floating point numbers and how to test for > them and avoid them, though I cannot find it anymore, and the > implementation isn't documented and doesn't seem to have automatic > tests. > > Greetings, > Maxime. > --0000000000006efb1d05e0ef2feb Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I found a better way to find the mantissa and exponent e.g= . frexp and when constructing the double/float
ldexp is great. That mak= es the code more portable. These functions are really fast and the call ove= rhead
is not terrible.

=
On Wed, Jun 8, 2022 at 9:49 AM Maxime= Devos <maximedevos@telenet.be= > wrote:
= Stefan Israelsson Tampe schreef op wo 08-06-2022 om 01:07 [+0200]:
> https://gitlab.com/tampe/guile-persis= t/-/tree/master/ice-9
> https://gitlab.com/tampe/guile-pe= rsist/-/tree/master/src/write
>
> I'm wondering if I should make a C library for other projects to t= ake
> advantage of this work.

Could they be integrated in Guile itself?=C2=A0 That would reach the most people I think.


=C2=A0 int=C2=A0 =C2=A0 =C2=A0 exp =3D (((*((uint64_t *) &d)) >> = 52) & ((1L<<11)-1)) - 1023L;
=C2=A0 uint64_t man =3D ((*((uint64_t *)=C2=A0 &d)) & ((1L<<5= 2)-1L)) + (1L << 52);

double's aren't uint64_t, so maybe a strict aliasing vilation and h= ence
undefined behaviour.=C2=A0 If so, maybe use -fno-strict-aliasing, or use type punning through an union?

Also, this assumes IEEE doubles, so maybe do some checks whether things
are actually IEEE (see m4/fpieee.m4, and maybe some checks like
sizeof(double)=3Dsizeof(uint64_t) and alignof(double)=3Dsizeof(uint64_t) and check DBL_DIG, DBL_MANT_DIG, DBL_MAX_EXP, ...)?

That line also assumes 'long' =3D 'uint64_t' (or at least, = that they have
the same size), which to me seems a bold assumption to make in the
general case.

Also, more generally, there was some paper on subtle errors that can
easily happen when printing floating point numbers and how to test for
them and avoid them, though I cannot find it anymore, and the
implementation isn't documented and doesn't seem to have automatic<= br> tests.

Greetings,
Maxime.
--0000000000006efb1d05e0ef2feb--