Re: Should rand() return a RAND_MAX value for 32 bit target?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx> - 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)



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux