help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: What is 0.01 here not 0.01 here 0.009999999999999?


From: Emanuel Berg
Subject: Re: What is 0.01 here not 0.01 here 0.009999999999999?
Date: Fri, 16 Apr 2021 22:41:30 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Jean Louis wrote:

> I would like to get a number increased for 0.01:
>
> (defun rcd-vc-increase-decimal-revision-number (nn.nn)
>   (let* ((nn.nn (format "%s" nn.nn))
>        (nn.nn (format "%.2f" (string-to-number nn.nn)))
>        (nn.nn (string-to-number nn.nn)))
>     (+ nn.nn 0.01)))
>
> But result is not what I want, as I want to get 10.13,
> though it is tiny loss:
>
> (rcd-vc-increase-decimal-revision-number "10.12") ; 10.129999999999999

Indeed, good question...

It is a binary thing, how floats are implemented.

Conventional wisdom is, it doesn't matter, don't worry
about it.

In your case, if you want a version number that is
MAJOR.MINOR.PATCH what you can do is have them integer
integer integer and then a separate function to output them

  (format "%d.%d.%d" major minor patch)

I prefer to use the time of change for versions, but that's
just me - and what a horrible world it would be, if everyone
was the same - and for larger/join projects it should/could
be extended, but still, check out:

  https://dataswamp.org/~incal/emacs-init/time-insert.el

-- 
underground experts united
https://dataswamp.org/~incal




reply via email to

[Prev in Thread] Current Thread [Next in Thread]