diff options
author | DJ Delorie <dj@redhat.com> | 2009-03-29 02:15:39 +0000 |
---|---|---|
committer | DJ Delorie <dj@redhat.com> | 2009-03-29 02:15:39 +0000 |
commit | 3481f392b0f0df40d3556b376322066086d577bf (patch) | |
tree | 10db2be9e96ce57aef9083cea47c58084e248365 /libdecnumber/decContext.c | |
parent | 9259819687899b6c6d31a7b32c24bfadad4b73f0 (diff) | |
download | gdb-3481f392b0f0df40d3556b376322066086d577bf.zip gdb-3481f392b0f0df40d3556b376322066086d577bf.tar.gz gdb-3481f392b0f0df40d3556b376322066086d577bf.tar.bz2 |
merge from gcc
Diffstat (limited to 'libdecnumber/decContext.c')
-rw-r--r-- | libdecnumber/decContext.c | 83 |
1 files changed, 51 insertions, 32 deletions
diff --git a/libdecnumber/decContext.c b/libdecnumber/decContext.c index d2e3bed..b1d1cc4 100644 --- a/libdecnumber/decContext.c +++ b/libdecnumber/decContext.c @@ -38,15 +38,13 @@ #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,11 +374,41 @@ 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 */ /* */ /* oldstatus is the status word to be tested */ |