From: "Liu Hao" <lh_mouse@126.com>
To: "Andrew Haley" <aph@redhat.com>,
"Neha Gowda" <neha.gnu.gcc@gmail.com>,
gcc-help@gcc.gnu.org
Subject: Re: Should rand() return a RAND_MAX value for 32 bit target?
Date: Fri, 21 Sep 2018 02:49:00 -0000 [thread overview]
Message-ID: <702886d4.135ef.165fa081a93.Coremail.lh_mouse@126.com> (raw)
In-Reply-To: <20180920155829.GA304@joooj.vinc17.net>
在 2018-09-20 23:58, Vincent Lefevre 写道:
> On 2018-09-20 23:21:23 +0800, Liu Hao wrote:
>> `2147483647` is an integer constant. This rule only describes floating
>> constants, so it does not apply.
>
> Actually the fact that it is a constant doesn't matter, but...
>
The paragraph quoted by the previous message contains a sentence saying
'... and of floating constants are evaluated to a format ...'. While
all following paragraphs don't mention `floating constants` explicitly,
it is implied.
If it could be said that 'constants' included integer constants here
then I would also reasonably think that 'all operations' here also
included operations involving only integers - which does not make any
sense at all.
This is not the place for discussion of the C standard. Anyway I don't
see any problems in GCC's implementation.
>> According to '6.3.1.8 Usual arithmetic conversions', here `2147483647`
>> is converted to a value having type `float`, which is then compared with
>> `f` using the internal `long double` type.
>
> The conversion of the int needs to be done with the precision and
> range of long double since this is neither an assignment nor a cast.
>
If there is no indeterminate results (as in your example) then there is
no difference.
An example where this truncation does matter is as follows, tested on
Linux Mint 19, x64 with GCC 7.3 :
-----
lh_mouse@lhmouse-ideapad ~/Desktop $ cat test.c
#include <stdio.h>
#include <float.h>
float a = 0x1.0002p0;
float b = 0x1.0003p0;
float c = 0x1.0005p0;
int main(void)
{
printf("FLT_EVAL_METHOD = %d\n", (int)FLT_EVAL_METHOD);
printf("a * b == c ? %d\n", a * b == c);
printf("a * b == (float)c ? %d\n", a * b == (float)c);
}
lh_mouse@lhmouse-ideapad ~/Desktop $ gcc test.c -std=c99 -O0 -m32
-march=pentium4 -mfpmath=sse && ./a.out
FLT_EVAL_METHOD = 0
a * b == c ? 1
a * b == (float)c ? 1
lh_mouse@lhmouse-ideapad ~/Desktop $ gcc test.c -std=c99 -O0 -m32 &&
./a.out
FLT_EVAL_METHOD = 2
a * b == c ? 0
a * b == (float)c ? 0
-----
--
Best regards,
LH_Mouse
next prev parent reply other threads:[~2018-09-21 2:49 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-09-18 12:22 Neha Gowda
2018-09-18 13:09 ` Xi Ruoyao
2018-09-18 13:17 ` Xi Ruoyao
2018-09-18 13:49 ` Jonathan Wakely
2018-09-18 13:46 ` Andrew Haley
2018-09-20 14:42 ` Vincent Lefevre
2018-09-20 15:05 ` Vincent Lefevre
2018-09-20 15:21 ` Liu Hao
2018-09-20 15:58 ` Vincent Lefevre
2018-09-20 16:12 ` Vincent Lefevre
2018-09-21 2:49 ` Liu Hao [this message]
2018-09-22 8:17 ` Vincent Lefevre
2018-09-22 10:08 ` Vincent Lefevre
2018-09-22 13:52 ` Liu Hao
2018-09-22 22:12 ` Vincent Lefevre
2018-09-20 15:46 ` Dennis Clarke
2018-09-20 16:16 ` Vincent Lefevre
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=702886d4.135ef.165fa081a93.Coremail.lh_mouse@126.com \
--to=lh_mouse@126.com \
--cc=aph@redhat.com \
--cc=gcc-help@gcc.gnu.org \
--cc=neha.gnu.gcc@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).