From: Joseph Myers <joseph@codesourcery.com>
To: Tejas Joshi <tejasjoshi9673@gmail.com>
Cc: <gcc-patches@gcc.gnu.org>, Martin Jambor <mjambor@suse.cz>
Subject: Re: [PATCH] builtin fadd variants implementation
Date: Mon, 02 Sep 2019 16:38:00 -0000 [thread overview]
Message-ID: <alpine.DEB.2.21.1909021633430.29869@digraph.polyomino.org.uk> (raw)
In-Reply-To: <CACMrGjDSOKSqZvduQUPEGCzje1uZD3o7Op0qH7v4VL2kNuWL4g@mail.gmail.com>
On Mon, 2 Sep 2019, Tejas Joshi wrote:
> Hello.
> Should a result like 1.4 be considered as inexact if truncating
> (narrowing?) from double to float? (due to loss of trailing bits)
If the mathematical result of the arithmetic operation is literally the
decimal number 1.4, as opposed to the double value represented by the C
constant 1.4 which is actually 0x1.6666666666666p+0, then it is inexact
regardless of the (non-decimal) types involved. For example, fdiv (7, 5),
ddivl (7, 5), etc. are always inexact.
If the mathematical result of the arithmetic operation is
0x1.6666666666666p+0, the closest approximation to 1.4 in IEEE binary64,
then it is inexact for result formats narrower than binary64 and exact for
result formats that can represent that value. For example, fadd (1.4,
0.0) is inexact (the truncation to float is inexact although the addition
is exact). But daddl (1.4, 0.0) - note the arguments are double
constants, not long double - is exact, because the mathematical result is
exactly representable in double. Whereas daddl (1.4L, 0.0L) would be
inexact if long double is wider than double.
The question is always whether the infinite-precision mathematical result
of the arithmetic operation - which takes values representable in its
argument types - is exactly representable in the final result type.
--
Joseph S. Myers
joseph@codesourcery.com
next prev parent reply other threads:[~2019-09-02 16:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-08 14:17 Tejas Joshi
2019-08-21 17:24 ` Joseph Myers
2019-08-26 5:19 ` Tejas Joshi
2019-08-27 23:47 ` Joseph Myers
2019-09-02 12:02 ` Tejas Joshi
2019-09-02 16:38 ` Joseph Myers [this message]
2019-09-09 16:06 ` Tejas Joshi
2019-09-09 21:24 ` Joseph Myers
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=alpine.DEB.2.21.1909021633430.29869@digraph.polyomino.org.uk \
--to=joseph@codesourcery.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=mjambor@suse.cz \
--cc=tejasjoshi9673@gmail.com \
/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).