P:/wx_LIB/Dcml/decContext.h

Aller à la documentation de ce fichier.
00001 /* ------------------------------------------------------------------ */
00002 /* Decimal Context module header                                      */
00003 /* ------------------------------------------------------------------ */
00004 /* Copyright (c) IBM Corporation, 2000, 2008.  All rights reserved.   */
00005 /*                                                                    */
00006 /* This software is made available under the terms of the IBM         */
00007 /* alphaWorks License Agreement (distributed with this software as    */
00008 /* alphaWorks-License.txt).  Your use of this software indicates      */
00009 /* your acceptance of the terms and conditions of that Agreement.     */
00010 /*                                                                    */
00011 /* The description and User's Guide ("The decNumber C Library") for   */
00012 /* this software is called decNumber.pdf.  This document is           */
00013 /* available, together with arithmetic and format specifications,     */
00014 /* testcases, and Web links, on the General Decimal Arithmetic page.  */
00015 /*                                                                    */
00016 /* Please send comments, suggestions, and corrections to the author:  */
00017 /*   mfc@uk.ibm.com                                                   */
00018 /*   Mike Cowlishaw, IBM Fellow                                       */
00019 /*   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         */
00020 /* ------------------------------------------------------------------ */
00021 /*                                                                    */
00022 /* Context variables must always have valid values:                   */
00023 /*                                                                    */
00024 /*  status   -- [any bits may be cleared, but not set, by user]       */
00025 /*  round    -- must be one of the enumerated rounding modes          */
00026 /*                                                                    */
00027 /* The following variables are implied for fixed size formats (i.e.,  */
00028 /* they are ignored) but should still be set correctly in case used   */
00029 /* with decNumber functions:                                          */
00030 /*                                                                    */
00031 /*  clamp    -- must be either 0 or 1                                 */
00032 /*  digits   -- must be in the range 1 through 999999999              */
00033 /*  emax     -- must be in the range 0 through 999999999              */
00034 /*  emin     -- must be in the range 0 through -999999999             */
00035 /*  extended -- must be either 0 or 1 [present only if DECSUBSET]     */
00036 /*  traps    -- only defined bits may be set                          */
00037 /*                                                                    */
00038 /* ------------------------------------------------------------------ */
00039 
00040 #if !defined(DECCONTEXT)
00041   #define DECCONTEXT
00042   #define DECCNAME     "decContext"                     /* Short name */
00043   #define DECCFULLNAME "Decimal Context Descriptor"   /* Verbose name */
00044   #define DECCAUTHOR   "Mike Cowlishaw"               /* Who to blame */
00045 
00046   #if !defined(int32_t)
00047     #include <stdint.h>            /* C99 standard integers           */
00048   #endif
00049   #include <stdio.h>               /* for printf, etc.                */
00050   #include <signal.h>              /* for traps                       */
00051 
00052   /* Extended flags setting -- set this to 0 to use only IEEE flags   */
00053   #if !defined(DECEXTFLAG)
00054   #define DECEXTFLAG 1             /* 1=enable extended flags         */
00055   #endif
00056 
00057   /* Conditional code flag -- set this to 0 for best performance      */
00058   #if !defined(DECSUBSET)
00059   #define DECSUBSET  0             /* 1=enable subset arithmetic      */
00060   #endif
00061 
00062   /* Context for operations, with associated constants                */
00063   enum rounding {
00064     DEC_ROUND_CEILING,             /* round towards +infinity         */
00065     DEC_ROUND_UP,                  /* round away from 0               */
00066     DEC_ROUND_HALF_UP,             /* 0.5 rounds up                   */
00067     DEC_ROUND_HALF_EVEN,           /* 0.5 rounds to nearest even      */
00068     DEC_ROUND_HALF_DOWN,           /* 0.5 rounds down                 */
00069     DEC_ROUND_DOWN,                /* round towards 0 (truncate)      */
00070     DEC_ROUND_FLOOR,               /* round towards -infinity         */
00071     DEC_ROUND_05UP,                /* round for reround               */
00072     DEC_ROUND_MAX                  /* enum must be less than this     */
00073     };
00074   #define DEC_ROUND_DEFAULT DEC_ROUND_HALF_EVEN;
00075 
00076   typedef struct {
00077     int32_t  digits;               /* working precision               */
00078     int32_t  emax;                 /* maximum positive exponent       */
00079     int32_t  emin;                 /* minimum negative exponent       */
00080     enum     rounding round;       /* rounding mode                   */
00081     uint32_t traps;                /* trap-enabler flags              */
00082     uint32_t status;               /* status flags                    */
00083     uint8_t  clamp;                /* flag: apply IEEE exponent clamp */
00084     #if DECSUBSET
00085     uint8_t  extended;             /* flag: special-values allowed    */
00086     #endif
00087     } decContext;
00088 
00089   /* Maxima and Minima for context settings                           */
00090   #define DEC_MAX_DIGITS 999999999
00091   #define DEC_MIN_DIGITS         1
00092   #define DEC_MAX_EMAX   999999999
00093   #define DEC_MIN_EMAX           0
00094   #define DEC_MAX_EMIN           0
00095   #define DEC_MIN_EMIN  -999999999
00096   #define DEC_MAX_MATH      999999 /* max emax, etc., for math funcs. */
00097 
00098   /* Classifications for decimal numbers, aligned with 754 (note that */
00099   /* 'normal' and 'subnormal' are meaningful only with a decContext   */
00100   /* or a fixed size format).                                         */
00101   enum decClass {
00102     DEC_CLASS_SNAN,
00103     DEC_CLASS_QNAN,
00104     DEC_CLASS_NEG_INF,
00105     DEC_CLASS_NEG_NORMAL,
00106     DEC_CLASS_NEG_SUBNORMAL,
00107     DEC_CLASS_NEG_ZERO,
00108     DEC_CLASS_POS_ZERO,
00109     DEC_CLASS_POS_SUBNORMAL,
00110     DEC_CLASS_POS_NORMAL,
00111     DEC_CLASS_POS_INF
00112     };
00113   /* Strings for the decClasses */
00114   #define DEC_ClassString_SN  "sNaN"
00115   #define DEC_ClassString_QN  "NaN"
00116   #define DEC_ClassString_NI  "-Infinity"
00117   #define DEC_ClassString_NN  "-Normal"
00118   #define DEC_ClassString_NS  "-Subnormal"
00119   #define DEC_ClassString_NZ  "-Zero"
00120   #define DEC_ClassString_PZ  "+Zero"
00121   #define DEC_ClassString_PS  "+Subnormal"
00122   #define DEC_ClassString_PN  "+Normal"
00123   #define DEC_ClassString_PI  "+Infinity"
00124   #define DEC_ClassString_UN  "Invalid"
00125 
00126   /* Trap-enabler and Status flags (exceptional conditions), and      */
00127   /* their names.  The top byte is reserved for internal use          */
00128   #if DECEXTFLAG
00129     /* Extended flags */
00130     #define DEC_Conversion_syntax    0x00000001
00131     #define DEC_Division_by_zero     0x00000002
00132     #define DEC_Division_impossible  0x00000004
00133     #define DEC_Division_undefined   0x00000008
00134     #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails]  */
00135     #define DEC_Inexact              0x00000020
00136     #define DEC_Invalid_context      0x00000040
00137     #define DEC_Invalid_operation    0x00000080
00138     #if DECSUBSET
00139     #define DEC_Lost_digits          0x00000100
00140     #endif
00141     #define DEC_Overflow             0x00000200
00142     #define DEC_Clamped              0x00000400
00143     #define DEC_Rounded              0x00000800
00144     #define DEC_Subnormal            0x00001000
00145     #define DEC_Underflow            0x00002000
00146   #else
00147     /* IEEE flags only */
00148     #define DEC_Conversion_syntax    0x00000010
00149     #define DEC_Division_by_zero     0x00000002
00150     #define DEC_Division_impossible  0x00000010
00151     #define DEC_Division_undefined   0x00000010
00152     #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails]  */
00153     #define DEC_Inexact              0x00000001
00154     #define DEC_Invalid_context      0x00000010
00155     #define DEC_Invalid_operation    0x00000010
00156     #if DECSUBSET
00157     #define DEC_Lost_digits          0x00000000
00158     #endif
00159     #define DEC_Overflow             0x00000008
00160     #define DEC_Clamped              0x00000000
00161     #define DEC_Rounded              0x00000000
00162     #define DEC_Subnormal            0x00000000
00163     #define DEC_Underflow            0x00000004
00164   #endif
00165 
00166   /* IEEE 754 groupings for the flags                                 */
00167   /* [DEC_Clamped, DEC_Lost_digits, DEC_Rounded, and DEC_Subnormal    */
00168   /* are not in IEEE 754]                                             */
00169   #define DEC_IEEE_754_Division_by_zero  (DEC_Division_by_zero)
00170   #if DECSUBSET
00171   #define DEC_IEEE_754_Inexact           (DEC_Inexact | DEC_Lost_digits)
00172   #else
00173   #define DEC_IEEE_754_Inexact           (DEC_Inexact)
00174   #endif
00175   #define DEC_IEEE_754_Invalid_operation (DEC_Conversion_syntax |     \
00176                                           DEC_Division_impossible |   \
00177                                           DEC_Division_undefined |    \
00178                                           DEC_Insufficient_storage |  \
00179                                           DEC_Invalid_context |       \
00180                                           DEC_Invalid_operation)
00181   #define DEC_IEEE_754_Overflow          (DEC_Overflow)
00182   #define DEC_IEEE_754_Underflow         (DEC_Underflow)
00183 
00184   /* flags which are normally errors (result is qNaN, infinite, or 0) */
00185   #define DEC_Errors (DEC_IEEE_754_Division_by_zero |                 \
00186                       DEC_IEEE_754_Invalid_operation |                \
00187                       DEC_IEEE_754_Overflow | DEC_IEEE_754_Underflow)
00188   /* flags which cause a result to become qNaN                        */
00189   #define DEC_NaNs    DEC_IEEE_754_Invalid_operation
00190 
00191   /* flags which are normally for information only (finite results)   */
00192   #if DECSUBSET
00193   #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact    \
00194                           | DEC_Lost_digits)
00195   #else
00196   #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact)
00197   #endif
00198 
00199   /* IEEE 854 names (for compatibility with older decNumber versions) */
00200   #define DEC_IEEE_854_Division_by_zero  DEC_IEEE_754_Division_by_zero
00201   #define DEC_IEEE_854_Inexact           DEC_IEEE_754_Inexact
00202   #define DEC_IEEE_854_Invalid_operation DEC_IEEE_754_Invalid_operation
00203   #define DEC_IEEE_854_Overflow          DEC_IEEE_754_Overflow
00204   #define DEC_IEEE_854_Underflow         DEC_IEEE_754_Underflow
00205 
00206   /* Name strings for the exceptional conditions                      */
00207   #define DEC_Condition_CS "Conversion syntax"
00208   #define DEC_Condition_DZ "Division by zero"
00209   #define DEC_Condition_DI "Division impossible"
00210   #define DEC_Condition_DU "Division undefined"
00211   #define DEC_Condition_IE "Inexact"
00212   #define DEC_Condition_IS "Insufficient storage"
00213   #define DEC_Condition_IC "Invalid context"
00214   #define DEC_Condition_IO "Invalid operation"
00215   #if DECSUBSET
00216   #define DEC_Condition_LD "Lost digits"
00217   #endif
00218   #define DEC_Condition_OV "Overflow"
00219   #define DEC_Condition_PA "Clamped"
00220   #define DEC_Condition_RO "Rounded"
00221   #define DEC_Condition_SU "Subnormal"
00222   #define DEC_Condition_UN "Underflow"
00223   #define DEC_Condition_ZE "No status"
00224   #define DEC_Condition_MU "Multiple status"
00225   #define DEC_Condition_Length 21  /* length of the longest string,   */
00226                                    /* including terminator            */
00227 
00228   /* Initialization descriptors, used by decContextDefault            */
00229   #define DEC_INIT_BASE         0
00230   #define DEC_INIT_DECIMAL32   32
00231   #define DEC_INIT_DECIMAL64   64
00232   #define DEC_INIT_DECIMAL128 128
00233   /* Synonyms */
00234   #define DEC_INIT_DECSINGLE  DEC_INIT_DECIMAL32
00235   #define DEC_INIT_DECDOUBLE  DEC_INIT_DECIMAL64
00236   #define DEC_INIT_DECQUAD    DEC_INIT_DECIMAL128
00237 
00238   /* decContext routines                                              */
00239   extern decContext  * decContextClearStatus(decContext *, uint32_t);
00240   extern decContext  * decContextDefault(decContext *, int32_t);
00241   extern enum rounding decContextGetRounding(decContext *);
00242   extern uint32_t      decContextGetStatus(decContext *);
00243   extern decContext  * decContextRestoreStatus(decContext *, uint32_t, uint32_t);
00244   extern uint32_t      decContextSaveStatus(decContext *, uint32_t);
00245   extern decContext  * decContextSetRounding(decContext *, enum rounding);
00246   extern decContext  * decContextSetStatus(decContext *, uint32_t);
00247   extern decContext  * decContextSetStatusFromString(decContext *, const char *);
00248   extern decContext  * decContextSetStatusFromStringQuiet(decContext *, const char *);
00249   extern decContext  * decContextSetStatusQuiet(decContext *, uint32_t);
00250   extern const char  * decContextStatusToString(const decContext *);
00251   extern int32_t       decContextTestEndian(uint8_t);
00252   extern uint32_t      decContextTestSavedStatus(uint32_t, uint32_t);
00253   extern uint32_t      decContextTestStatus(decContext *, uint32_t);
00254   extern decContext  * decContextZeroStatus(decContext *);
00255 
00256 #endif

Généré le Mon Jul 20 18:22:14 2009 pour Decimal par  doxygen 1.5.1-p1