unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: Stefan Israelsson Tampe <stefan.itampe@gmail.com>
To: Maxime Devos <maximedevos@telenet.be>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: reader musings
Date: Wed, 8 Jun 2022 14:52:49 +0200	[thread overview]
Message-ID: <CAGua6m3gs=KLVHzRp1mstibbiFH4MskY7wnEyt5QZfYJyhyVaA@mail.gmail.com> (raw)
In-Reply-To: <abeaeb283618715bc8970063063e93cadb28cc04.camel@telenet.be>

[-- Attachment #1: Type: text/plain, Size: 1774 bytes --]

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 <maximedevos@telenet.be> 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.
>

[-- Attachment #2: Type: text/html, Size: 2503 bytes --]

      reply	other threads:[~2022-06-08 12:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-07 23:07 reader musings Stefan Israelsson Tampe
2022-06-08  7:49 ` Maxime Devos
2022-06-08 12:52   ` Stefan Israelsson Tampe [this message]

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

  List information: https://www.gnu.org/software/guile/

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

  git send-email \
    --in-reply-to='CAGua6m3gs=KLVHzRp1mstibbiFH4MskY7wnEyt5QZfYJyhyVaA@mail.gmail.com' \
    --to=stefan.itampe@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=maximedevos@telenet.be \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).