Should rand() return a RAND_MAX value for 32 bit target?
Vincent Lefevre
vincent+gcc@vinc17.org
Sat Sep 22 08:17:00 GMT 2018
On 2018-09-21 10:49:19 +0800, Liu Hao wrote:
> å¨ 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.
Forgot what I said at that time. It's an integer constant, thus it
is always evaluated *exactly* as an integer. Then, the rules for
type conversions in a floating-point expression are the same, whether
the values come from constants and non-constants.
Thus if one does
float a;
int b;
/* ... */
a + b;
with FLT_EVAL_METHOD = 2, the evaluation type of a is long double, b
is converted to the semantic type float, but its evaluation type is
long double, so that its value should not change if representable as
a long double. That's what FLT_EVAL_METHOD means. The *only* cases
for which the precision and range need to be reduced to those of the
semantic type if for assignment and cast, but here one just has an
implicit conversion.
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
More information about the Gcc-help
mailing list