This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


On 2018-09-20 17:58:30 +0200, Vincent Lefevre wrote:
> 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...
> 
> > 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.

Similarly, for

  float a, b;
  double c;

  (a + b) + c;

I would expect the result of a + b to be kept in long double instead
of being converted to double due to the operand c.

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]