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: Teemu Likonen
Subject: Re: What is 0.01 here not 0.01 here 0.009999999999999?
Date: Fri, 02 Apr 2021 20:41:53 +0300
User-agent: Notmuch/0.31.4 (https://notmuchmail.org) Emacs/27.1.91 (x86_64-pc-linux-gnu)

* 2021-04-02 20:03:54+0300, Jean Louis wrote:

> Not that I need the absolute internally, just the practical
> result as we learned it in school like that 10.11 plus 0.01
> results with 10.12 and not something else. Results are used for
> automated version numbers (in some cases).

As you have learned, floating point numbers are not decimal numbers even
if they are read and printed as such. For decimal mathematics you can
use calc-eval function. Some comparison:

    ELISP> (+ 10.12 0.01)
    10.129999999999999

    ELISP> (calc-eval "10.12 + 0.01")
    "10.13"

    ELISP> (* 3 0.1)
    0.30000000000000004

    ELISP> (calc-eval "3 * 0.1")
    "0.3"

-- 
/// Teemu Likonen - .-.. https://www.iki.fi/tlikonen/
// OpenPGP: 4E1055DC84E9DFF613D78557719D69D324539450

Attachment: signature.asc
Description: PGP signature


reply via email to

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