[ruby-cvs:72837] shyouhei:r65737 (trunk): hash.c: cast from double to unsigned is undefined
shyouhei at ruby-lang.org
shyouhei at ruby-lang.org
Thu Nov 15 15:17:53 JST 2018
shyouhei 2018-11-15 15:17:53 +0900 (Thu, 15 Nov 2018)
New Revision: 65737
https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65737
Log:
hash.c: cast from double to unsigned is undefined
When a negative double is casted into an unsigned type, that operation
is undefined (cf: ISO/IEC 9899:1990 section 6.2.9.3). Recent versions
of C kindly footnotes that "The remaindering operation performed when
a value of integer type is converted to unsigned type need not be
performed when a value of real floating type is converted to unsigned
type" (cf: ISO/IEC 9899:1999 section 6.3.1.4 footnote 50).
So it is a wrong idea to just cast a double to st_data_t.
The intention of the code is commented as "mix the actual float value
in". It seems we should do a reinterpret_cast and rule out
static_cast.
Confirmed this changeset does not affect `make benchmark`.
Modified files:
trunk/hash.c
More information about the ruby-cvs
mailing list