merge from gcc
[deliverable/binutils-gdb.git] / libdecnumber / decContext.c
index d2e3bed439750c1c845efab12b87004a4866c1da..b1d1cc4e47b4fdd8d9139c529a395d0d82e71b96 100644 (file)
 #include <string.h>          /* for strcmp */
 #include <stdio.h>           /* for printf if DECCHECK */
 #include "dconfig.h"         /* for GCC definitions */
-#include "decContext.h"              /* context and base types */
+#include "decContext.h"       /* context and base types */
 #include "decNumberLocal.h"   /* decNumber local types, etc. */
 
-#if DECCHECK
 /* compile-time endian tester [assumes sizeof(Int)>1] */
 static const  Int mfcone=1;                 /* constant 1 */
-static const  Flag *mfctop=(Flag *)&mfcone; /* -> top byte */
+static const  Flag *mfctop=(const Flag *)&mfcone; /* -> top byte */
 #define LITEND *mfctop            /* named flag; 1=little-endian */
-#endif
 
 /* ------------------------------------------------------------------ */
 /* round-for-reround digits                                          */
@@ -64,7 +62,7 @@ const uInt DECPOWERS[10]={1, 10, 100, 1000, 10000, 100000, 1000000,
 /*                                                                   */
 /*  context is the context structure to be queried                   */
 /*  mask indicates the bits to be cleared (the status bit that       */
-/*    corresponds to each 1 bit in the mask is cleared)                      */
+/*    corresponds to each 1 bit in the mask is cleared)              */
 /*  returns context                                                  */
 /*                                                                   */
 /* No error is possible.                                             */
@@ -80,9 +78,9 @@ decContext *decContextClearStatus(decContext *context, uInt mask) {
 /*  context is the structure to be initialized                       */
 /*  kind selects the required set of default values, one of:         */
 /*     DEC_INIT_BASE       -- select ANSI X3-274 defaults            */
-/*     DEC_INIT_DECIMAL32  -- select IEEE 754r defaults, 32-bit      */
-/*     DEC_INIT_DECIMAL64  -- select IEEE 754r defaults, 64-bit      */
-/*     DEC_INIT_DECIMAL128 -- select IEEE 754r defaults, 128-bit     */
+/*     DEC_INIT_DECIMAL32  -- select IEEE 754 defaults, 32-bit       */
+/*     DEC_INIT_DECIMAL64  -- select IEEE 754 defaults, 64-bit       */
+/*     DEC_INIT_DECIMAL128 -- select IEEE 754 defaults, 128-bit      */
 /*     For any other value a valid context is returned, but with     */
 /*     Invalid_operation set in the status field.                    */
 /*  returns a context structure with the appropriate initial values.  */
@@ -105,11 +103,11 @@ decContext * decContextDefault(decContext *context, Int kind) {
       break;
     case DEC_INIT_DECIMAL32:
       context->digits=7;                    /* digits */
-      context->emax=96;                             /* Emax */
+      context->emax=96;                     /* Emax */
       context->emin=-95;                    /* Emin */
       context->round=DEC_ROUND_HALF_EVEN;    /* 0.5 to nearest even */
-      context->traps=0;                             /* no traps set */
-      context->clamp=1;                             /* clamp exponents */
+      context->traps=0;                     /* no traps set */
+      context->clamp=1;                     /* clamp exponents */
       #if DECSUBSET
       context->extended=1;                  /* set */
       #endif
@@ -119,8 +117,8 @@ decContext * decContextDefault(decContext *context, Int kind) {
       context->emax=384;                    /* Emax */
       context->emin=-383;                   /* Emin */
       context->round=DEC_ROUND_HALF_EVEN;    /* 0.5 to nearest even */
-      context->traps=0;                             /* no traps set */
-      context->clamp=1;                             /* clamp exponents */
+      context->traps=0;                     /* no traps set */
+      context->clamp=1;                     /* clamp exponents */
       #if DECSUBSET
       context->extended=1;                  /* set */
       #endif
@@ -130,8 +128,8 @@ decContext * decContextDefault(decContext *context, Int kind) {
       context->emax=6144;                   /* Emax */
       context->emin=-6143;                  /* Emin */
       context->round=DEC_ROUND_HALF_EVEN;    /* 0.5 to nearest even */
-      context->traps=0;                             /* no traps set */
-      context->clamp=1;                             /* clamp exponents */
+      context->traps=0;                     /* no traps set */
+      context->clamp=1;                     /* clamp exponents */
       #if DECSUBSET
       context->extended=1;                  /* set */
       #endif
@@ -142,15 +140,6 @@ decContext * decContextDefault(decContext *context, Int kind) {
       decContextSetStatus(context, DEC_Invalid_operation); /* trap */
     }
 
-  #if DECCHECK
-  if (LITEND!=DECLITEND) {
-    const char *adj;
-    if (LITEND) adj="little";
-          else adj="big";
-    printf("Warning: DECLITEND is set to %d, but this computer appears to be %s-endian\n",
-          DECLITEND, adj);
-    }
-  #endif
   return context;} /* decContextDefault */
 
 /* ------------------------------------------------------------------ */
@@ -166,7 +155,7 @@ enum rounding decContextGetRounding(decContext *context) {
   } /* decContextGetRounding */
 
 /* ------------------------------------------------------------------ */
-/* decContextGetStatus -- return current status                              */
+/* decContextGetStatus -- return current status                      */
 /*                                                                   */
 /*  context is the context structure to be queried                   */
 /*  returns status                                                   */
@@ -181,8 +170,8 @@ uInt decContextGetStatus(decContext *context) {
 /* decContextRestoreStatus -- restore bits in current status         */
 /*                                                                   */
 /*  context is the context structure to be updated                   */
-/*  newstatus is the source for the bits to be restored                      */
-/*  mask indicates the bits to be restored (the status bit that              */
+/*  newstatus is the source for the bits to be restored              */
+/*  mask indicates the bits to be restored (the status bit that       */
 /*    corresponds to each 1 bit in the mask is set to the value of    */
 /*    the correspnding bit in newstatus)                             */
 /*  returns context                                                  */
@@ -252,7 +241,7 @@ decContext * decContextSetStatus(decContext *context, uInt status) {
 /*                                                                   */
 /*  returns the context structure, unless the string is equal to      */
 /*    DEC_Condition_MU or is not recognized.  In these cases NULL is  */
-/*    returned.                                                              */
+/*    returned.                                                      */
 /* ------------------------------------------------------------------ */
 decContext * decContextSetStatusFromString(decContext *context,
                                           const char *string) {
@@ -303,7 +292,7 @@ decContext * decContextSetStatusFromString(decContext *context,
 /*                                                                   */
 /*  returns the context structure, unless the string is equal to      */
 /*    DEC_Condition_MU or is not recognized.  In these cases NULL is  */
-/*    returned.                                                              */
+/*    returned.                                                      */
 /* ------------------------------------------------------------------ */
 decContext * decContextSetStatusFromStringQuiet(decContext *context,
                                                const char *string) {
@@ -356,11 +345,11 @@ decContext * decContextSetStatusQuiet(decContext *context, uInt status) {
   return context;} /* decContextSetStatusQuiet */
 
 /* ------------------------------------------------------------------ */
-/* decContextStatusToString -- convert status flags to a string              */
+/* decContextStatusToString -- convert status flags to a string       */
 /*                                                                   */
 /*  context is a context with valid status field                     */
 /*                                                                   */
-/*  returns a constant string describing the condition.         If multiple  */
+/*  returns a constant string describing the condition.  If multiple  */
 /*    (or no) flags are set, a generic constant message is returned.  */
 /* ------------------------------------------------------------------ */
 const char *decContextStatusToString(const decContext *context) {
@@ -385,10 +374,40 @@ const char *decContextStatusToString(const decContext *context) {
   #if DECSUBSET
   if (status==DEC_Lost_digits         ) return DEC_Condition_LD;
   #endif
-  if (status==0                               ) return DEC_Condition_ZE;
+  if (status==0                       ) return DEC_Condition_ZE;
   return DEC_Condition_MU;  /* Multiple errors */
   } /* decContextStatusToString */
 
+/* ------------------------------------------------------------------ */
+/* decContextTestEndian -- test whether DECLITEND is set correctly    */
+/*                                                                   */
+/*  quiet is 1 to suppress message; 0 otherwise                      */
+/*  returns 0 if DECLITEND is correct                                */
+/*         1 if DECLITEND is incorrect and should be 1               */
+/*        -1 if DECLITEND is incorrect and should be 0               */
+/*                                                                   */
+/* A message is displayed if the return value is not 0 and quiet==0.  */
+/*                                                                   */
+/* No error is possible.                                             */
+/* ------------------------------------------------------------------ */
+Int decContextTestEndian(Flag quiet) {
+  Int res=0;                 /* optimist */
+  uInt dle=(uInt)DECLITEND;   /* unsign */
+  if (dle>1) dle=1;          /* ensure 0 or 1 */
+
+  if (LITEND!=DECLITEND) {
+    const char *adj;
+    if (!quiet) {
+      if (LITEND) adj="little";
+            else adj="big";
+      printf("Warning: DECLITEND is set to %d, but this computer appears to be %s-endian\n",
+            DECLITEND, adj);
+      }
+    res=(Int)LITEND-dle;
+    }
+  return res;
+  } /* decContextTestEndian */
+
 /* ------------------------------------------------------------------ */
 /* decContextTestSavedStatus -- test bits in saved status            */
 /*                                                                   */
This page took 0.026468 seconds and 4 git commands to generate.