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: Eli Zaretskii
Subject: Re: What is 0.01 here not 0.01 here 0.009999999999999?
Date: Fri, 02 Apr 2021 17:02:41 +0300

> Date: Fri, 02 Apr 2021 16:42:42 +0300
> From: Jean Louis <bugs@gnu.support>
> 
> 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

Welcome to floating-point computations.  0.01 doesn't have an exact
binary representation, which is why you get what you get.

Suggested reading:

  https://www.itu.dk/~sestoft/bachelor/IEEE754_article.pdf



reply via email to

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