This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/28038] Double to char conversion fails at 32769.0
- From: "barryb at cwipapps dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 15 Jun 2006 17:15:32 -0000
- Subject: [Bug c/28038] Double to char conversion fails at 32769.0
- References: <bug-28038-12832@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #4 from barryb at cwipapps dot net 2006-06-15 17:15 -------
Sorry, you are right; you have to cast it twice.
I'd moved on to
d is 32765.000000, as integer is 0x00007ffd, and (ushort)d is 0x7ffd while
(uchar)(ushort)d is 0xfd
d is 32766.000000, as integer is 0x00007ffe, and (ushort)d is 0x7ffe while
(uchar)(ushort)d is 0xfe
d is 32767.000000, as integer is 0x00007fff, and (ushort)d is 0x7fff while
(uchar)(ushort)d is 0xff
d is 32768.000000, as integer is 0x00008000, and (ushort)d is 0x8000 while
(uchar)(ushort)d is 0x00
d is 32769.000000, as integer is 0x00008001, and (ushort)d is 0x8001 while
(uchar)(ushort)d is 0x01
d is 32770.000000, as integer is 0x00008002, and (ushort)d is 0x8002 while
(uchar)(ushort)d is 0x02
Which works for this width of integer.
For some reason the following code
*to++= (char) (floor(my_rnd(&rand_st)*31)+64);
seems to work in MySQL 4.0.23 for Linux, but not when I use it.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28038