all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: John Yates <john@yates-sheets.org>
To: John Yates <john@yates-sheets.org>,
	Stefan Monnier <monnier@iro.umontreal.ca>,
	 Help Gnu Emacs mailing list <help-gnu-emacs@gnu.org>
Subject: Re: What is 0.01 here not 0.01 here 0.009999999999999?
Date: Fri, 2 Apr 2021 18:04:14 -0400	[thread overview]
Message-ID: <CAJnXXojtOvzkCXxaSfL4T+EQS5cRgAOysTuSXo8mvZd2u1bUKg@mail.gmail.com> (raw)
In-Reply-To: <YGeKTuYRzEbm0Hv9@protected.localdomain>

> I did not find the word "significand", but I think you mean that above
> definition.

https://en.wikipedia.org/wiki/Significand

> Yes, I need arithmetic on imprecise representations... to deliver what
> I want, and it is doing what I want. `calc-eval' is doing it, and my
> function is delivering me string that is increased for 0.01 -- well
> that is what I wanted, and is happening... several times per hour
> those numbers are increasing, function is working ;-p

This will probably work because each time you increment by an
approximation of 0.01 you convert back to a decimal representation
via a path that applies a number of heuristics to guess what value
you want to see.  Having rendered your incremented value as a
decimal string, when you read it back in you _do not_ recreate
a bit for bit copy of the earlier sum, but rather a floating point
number that is the closest approximation possible to the decimal
number being presented.  Put another way, each output / input
iteration prevents you from accumulating errors.

If you wanted to support more general arithmetic on your version
numbers I would advise using scaled integer arithmetic.  Assuming
that you can guarantee the granularity of your version numbers will
always be 0.01 then you can represent 0.01 as 1 and 11.07 as
1107.  Then to recover the major version you just divide by 100 and
to recover the minor version you mod by 100.

Using 100 is necessary if you want 10.99 + 0.01 to return 11.00.
If you never expect to handle a carry from your minor version field
into your major version field then you could scale by a power of
two (e.g. 128).  Then division reduces to right shifting and mod
to masking (e.g. for 128 that means anding with 127).

/john



  reply	other threads:[~2021-04-02 22:04 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-02 13:42 What is 0.01 here not 0.01 here 0.009999999999999? Jean Louis
2021-04-02 13:56 ` Stefan Monnier
2021-04-02 17:03   ` Jean Louis
2021-04-02 17:41     ` Teemu Likonen
2021-04-02 18:44       ` Jean Louis
2021-04-02 20:46     ` John Yates
2021-04-02 21:19       ` Jean Louis
2021-04-02 22:04         ` John Yates [this message]
2021-04-02 23:29           ` Jean Louis
2021-04-03  4:39             ` Arthur Miller
2021-04-03  5:36               ` Jean Louis
2021-04-03  3:56     ` Arthur Miller
2021-04-03  5:19       ` Jean Louis
2021-04-03 13:54         ` Stefan Monnier
2021-04-03 16:26           ` Packages for ELPA, emacs-libpq Jean Louis
2021-04-02 14:02 ` What is 0.01 here not 0.01 here 0.009999999999999? Eli Zaretskii
2021-04-02 17:07   ` Jean Louis
2021-04-03  4:49     ` Arthur Miller
2021-04-16 20:41 ` Emanuel Berg via Users list for the GNU Emacs text editor
2021-04-17 10:53   ` Jean Louis
2021-04-19 10:51   ` Eric S Fraga

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=CAJnXXojtOvzkCXxaSfL4T+EQS5cRgAOysTuSXo8mvZd2u1bUKg@mail.gmail.com \
    --to=john@yates-sheets.org \
    --cc=help-gnu-emacs@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.