From: Dennis Clarke <dclarke@blastwave.org>
To: gcc-help@gcc.gnu.org
Subject: Re: Should rand() return a RAND_MAX value for 32 bit target?
Date: Thu, 20 Sep 2018 15:46:00 -0000 [thread overview]
Message-ID: <c9ded4ce-9e8d-fe4d-be1d-bb61e0d93d5c@blastwave.org> (raw)
In-Reply-To: <20180920150550.GA4852@cventin.lip.ens-lyon.fr>
On 09/20/2018 11:05 AM, Vincent Lefevre wrote:
> Actually, there may be a bug with -m32:
>
> #include <stdio.h>
> #include <float.h>
>
> int main (void)
> {
> float f = 2147483646;
> printf ("FLT_EVAL_METHOD = %d\n", (int) FLT_EVAL_METHOD);
> if (f == 2147483647)
> {
> printf("%.20g\n", (double) f);
> }
> return 0;
> }
>
> $ gcc -std=c99 -m32 -O tst.c -o tst
> $ ./tst
> FLT_EVAL_METHOD = 2
> 2147483648
>
> Since FLT_EVAL_METHOD = 2, float_t is long double, thus shouldn't
> 2147483647 be converted to long double directly (as f is regarded
> as an operand of type long double), so that the result of the
> equality test should be false?
>
> The C standard says for FLT_EVAL_METHOD = 2: "evaluate all operations
> and constants to the range and precision of the long double type".
> ^^^^^^^^^^^^^
>
> Converting f first to float is contrary to the idea behind
> FLT_EVAL_METHOD = 2, which is to avoid loss of precision in
> intermediate operations.
>
Hrmmm ... I see FLT_EVAL_METHOD = 0 here with gcc 8.1.0 on sparc :
$ file ./flt_eval
./flt_eval: ELF 32-bit MSB executable SPARC32PLUS Version 1, V8+
Required, dynamically linked, not stripped, no debugging information
available
$ ./flt_eval
FLT_EVAL_METHOD = 0
2147483648
I see similar on ppc64 :
$ file flt_eval
flt_eval: ELF 32-bit MSB executable, PowerPC or cisco 4500, version 1
(SYSV), dynamically linked, interpreter /lib/ld.so.1, for GNU/Linux
3.2.0, not stripped
$ ./flt_eval
FLT_EVAL_METHOD = 0
2147483648
$
Not sure how you are getting FLT_EVAL_METHOD as 2.
What platform is this on ?
Dennis
next prev parent reply other threads:[~2018-09-20 15:46 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
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 [this message]
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=c9ded4ce-9e8d-fe4d-be1d-bb61e0d93d5c@blastwave.org \
--to=dclarke@blastwave.org \
--cc=gcc-help@gcc.gnu.org \
/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).