This is the mail archive of the newlib@sourceware.org mailing list for the newlib 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: struct ldieee should be packed



On 01/30/2016 01:56 AM, Shoichi Sakon wrote:
Hello,

The following test program prints 1.0 instead of -1.0.
-------------------------------------
#include <stdio.h>
int main() {
         double x = -1.0;
         printf("%f\n",x);
	return 0;
}
-------------------------------------

I believe the cause of the problem is the struct ldieee
defined in newlib/libc/stdio/vfieeefp.h is not "packed",
and in the function cvt in newlib/libc/stdio/vfieeefp.h
ld.ieee.sign does not get the proper sign.

When I change all the definitions of
  struct ldieee
to
  struct __attribute__ ((__packed__)) ldieee
I can get the right result at the test program.
What compiler version and platform are you targeting?
Can you try the following as an experiment? instead of adding packed (which is non-standard), merge the bitfields to be under a single element instead of separate ones for you entry of interest. For example, change
#if LDBL_MANT_DIG == 24
 struct ldieee
 {
   unsigned manh:23;
   unsigned exp:8;
   unsigned sign:1;
 };

to

 {
   unsigned manh:23,
                  exp:8,
                  sign:1;
 };

Craig


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