intl/icu/source/i18n/decContext.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/intl/icu/source/i18n/decContext.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,268 @@
     1.4 +/* ------------------------------------------------------------------ */
     1.5 +/* Decimal Context module header                                      */
     1.6 +/* ------------------------------------------------------------------ */
     1.7 +/* Copyright (c) IBM Corporation, 2000-2011.   All rights reserved.   */
     1.8 +/*                                                                    */
     1.9 +/* This software is made available under the terms of the             */
    1.10 +/* ICU License -- ICU 1.8.1 and later.                                */
    1.11 +/*                                                                    */
    1.12 +/* The description and User's Guide ("The decNumber C Library") for   */
    1.13 +/* this software is called decNumber.pdf.  This document is           */
    1.14 +/* available, together with arithmetic and format specifications,     */
    1.15 +/* testcases, and Web links, on the General Decimal Arithmetic page.  */
    1.16 +/*                                                                    */
    1.17 +/* Please send comments, suggestions, and corrections to the author:  */
    1.18 +/*   mfc@uk.ibm.com                                                   */
    1.19 +/*   Mike Cowlishaw, IBM Fellow                                       */
    1.20 +/*   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         */
    1.21 +/* ------------------------------------------------------------------ */
    1.22 +
    1.23 +/* Modified version, for use from within ICU.
    1.24 + *    Renamed public functions, to avoid an unwanted export of the 
    1.25 + *    standard names from the ICU library.
    1.26 + *
    1.27 + *    Use ICU's uprv_malloc() and uprv_free()
    1.28 + *
    1.29 + *    Revert comment syntax to plain C
    1.30 + *
    1.31 + *    Remove a few compiler warnings.
    1.32 + */
    1.33 +#include "unicode/utypes.h"
    1.34 +#include "putilimp.h"
    1.35 +
    1.36 +/*                                                                    */
    1.37 +/* Context variables must always have valid values:                   */
    1.38 +/*                                                                    */
    1.39 +/*  status   -- [any bits may be cleared, but not set, by user]       */
    1.40 +/*  round    -- must be one of the enumerated rounding modes          */
    1.41 +/*                                                                    */
    1.42 +/* The following variables are implied for fixed size formats (i.e.,  */
    1.43 +/* they are ignored) but should still be set correctly in case used   */
    1.44 +/* with decNumber functions:                                          */
    1.45 +/*                                                                    */
    1.46 +/*  clamp    -- must be either 0 or 1                                 */
    1.47 +/*  digits   -- must be in the range 1 through 999999999              */
    1.48 +/*  emax     -- must be in the range 0 through 999999999              */
    1.49 +/*  emin     -- must be in the range 0 through -999999999             */
    1.50 +/*  extended -- must be either 0 or 1 [present only if DECSUBSET]     */
    1.51 +/*  traps    -- only defined bits may be set                          */
    1.52 +/*                                                                    */
    1.53 +/* ------------------------------------------------------------------ */
    1.54 +
    1.55 +#if !defined(DECCONTEXT)
    1.56 +  #define DECCONTEXT
    1.57 +  #define DECCNAME     "decContext"                     /* Short name */
    1.58 +  #define DECCFULLNAME "Decimal Context Descriptor"   /* Verbose name */
    1.59 +  #define DECCAUTHOR   "Mike Cowlishaw"               /* Who to blame */
    1.60 +
    1.61 +  #if !defined(int32_t)
    1.62 +/* #include <stdint.h>   */         /* C99 standard integers           */
    1.63 +  #endif
    1.64 +  #include <stdio.h>               /* for printf, etc.                */
    1.65 +  #include <signal.h>              /* for traps                       */
    1.66 +
    1.67 +  /* Extended flags setting -- set this to 0 to use only IEEE flags   */
    1.68 +  #if !defined(DECEXTFLAG)
    1.69 +  #define DECEXTFLAG 1             /* 1=enable extended flags         */
    1.70 +  #endif
    1.71 +
    1.72 +  /* Conditional code flag -- set this to 0 for best performance      */
    1.73 +  #if !defined(DECSUBSET)
    1.74 +  #define DECSUBSET  0             /* 1=enable subset arithmetic      */
    1.75 +  #endif
    1.76 +
    1.77 +  /* Context for operations, with associated constants                */
    1.78 +  enum rounding {
    1.79 +    DEC_ROUND_CEILING,             /* round towards +infinity         */
    1.80 +    DEC_ROUND_UP,                  /* round away from 0               */
    1.81 +    DEC_ROUND_HALF_UP,             /* 0.5 rounds up                   */
    1.82 +    DEC_ROUND_HALF_EVEN,           /* 0.5 rounds to nearest even      */
    1.83 +    DEC_ROUND_HALF_DOWN,           /* 0.5 rounds down                 */
    1.84 +    DEC_ROUND_DOWN,                /* round towards 0 (truncate)      */
    1.85 +    DEC_ROUND_FLOOR,               /* round towards -infinity         */
    1.86 +    DEC_ROUND_05UP,                /* round for reround               */
    1.87 +    DEC_ROUND_MAX                  /* enum must be less than this     */
    1.88 +    };
    1.89 +  #define DEC_ROUND_DEFAULT DEC_ROUND_HALF_EVEN;
    1.90 +
    1.91 +  typedef struct {
    1.92 +    int32_t  digits;               /* working precision               */
    1.93 +    int32_t  emax;                 /* maximum positive exponent       */
    1.94 +    int32_t  emin;                 /* minimum negative exponent       */
    1.95 +    enum     rounding round;       /* rounding mode                   */
    1.96 +    uint32_t traps;                /* trap-enabler flags              */
    1.97 +    uint32_t status;               /* status flags                    */
    1.98 +    uint8_t  clamp;                /* flag: apply IEEE exponent clamp */
    1.99 +    #if DECSUBSET
   1.100 +    uint8_t  extended;             /* flag: special-values allowed    */
   1.101 +    #endif
   1.102 +    } decContext;
   1.103 +
   1.104 +  /* Maxima and Minima for context settings                           */
   1.105 +  #define DEC_MAX_DIGITS 999999999
   1.106 +  #define DEC_MIN_DIGITS         1
   1.107 +  #define DEC_MAX_EMAX   999999999
   1.108 +  #define DEC_MIN_EMAX           0
   1.109 +  #define DEC_MAX_EMIN           0
   1.110 +  #define DEC_MIN_EMIN  -999999999
   1.111 +  #define DEC_MAX_MATH      999999 /* max emax, etc., for math funcs. */
   1.112 +
   1.113 +  /* Classifications for decimal numbers, aligned with 754 (note that */
   1.114 +  /* 'normal' and 'subnormal' are meaningful only with a decContext   */
   1.115 +  /* or a fixed size format).                                         */
   1.116 +  enum decClass {
   1.117 +    DEC_CLASS_SNAN,
   1.118 +    DEC_CLASS_QNAN,
   1.119 +    DEC_CLASS_NEG_INF,
   1.120 +    DEC_CLASS_NEG_NORMAL,
   1.121 +    DEC_CLASS_NEG_SUBNORMAL,
   1.122 +    DEC_CLASS_NEG_ZERO,
   1.123 +    DEC_CLASS_POS_ZERO,
   1.124 +    DEC_CLASS_POS_SUBNORMAL,
   1.125 +    DEC_CLASS_POS_NORMAL,
   1.126 +    DEC_CLASS_POS_INF
   1.127 +    };
   1.128 +  /* Strings for the decClasses */
   1.129 +  #define DEC_ClassString_SN  "sNaN"
   1.130 +  #define DEC_ClassString_QN  "NaN"
   1.131 +  #define DEC_ClassString_NI  "-Infinity"
   1.132 +  #define DEC_ClassString_NN  "-Normal"
   1.133 +  #define DEC_ClassString_NS  "-Subnormal"
   1.134 +  #define DEC_ClassString_NZ  "-Zero"
   1.135 +  #define DEC_ClassString_PZ  "+Zero"
   1.136 +  #define DEC_ClassString_PS  "+Subnormal"
   1.137 +  #define DEC_ClassString_PN  "+Normal"
   1.138 +  #define DEC_ClassString_PI  "+Infinity"
   1.139 +  #define DEC_ClassString_UN  "Invalid"
   1.140 +
   1.141 +  /* Trap-enabler and Status flags (exceptional conditions), and      */
   1.142 +  /* their names.  The top byte is reserved for internal use          */
   1.143 +  #if DECEXTFLAG
   1.144 +    /* Extended flags */
   1.145 +    #define DEC_Conversion_syntax    0x00000001
   1.146 +    #define DEC_Division_by_zero     0x00000002
   1.147 +    #define DEC_Division_impossible  0x00000004
   1.148 +    #define DEC_Division_undefined   0x00000008
   1.149 +    #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails]  */
   1.150 +    #define DEC_Inexact              0x00000020
   1.151 +    #define DEC_Invalid_context      0x00000040
   1.152 +    #define DEC_Invalid_operation    0x00000080
   1.153 +    #if DECSUBSET
   1.154 +    #define DEC_Lost_digits          0x00000100
   1.155 +    #endif
   1.156 +    #define DEC_Overflow             0x00000200
   1.157 +    #define DEC_Clamped              0x00000400
   1.158 +    #define DEC_Rounded              0x00000800
   1.159 +    #define DEC_Subnormal            0x00001000
   1.160 +    #define DEC_Underflow            0x00002000
   1.161 +  #else
   1.162 +    /* IEEE flags only */
   1.163 +    #define DEC_Conversion_syntax    0x00000010
   1.164 +    #define DEC_Division_by_zero     0x00000002
   1.165 +    #define DEC_Division_impossible  0x00000010
   1.166 +    #define DEC_Division_undefined   0x00000010
   1.167 +    #define DEC_Insufficient_storage 0x00000010 /* [when malloc fails]  */
   1.168 +    #define DEC_Inexact              0x00000001
   1.169 +    #define DEC_Invalid_context      0x00000010
   1.170 +    #define DEC_Invalid_operation    0x00000010
   1.171 +    #if DECSUBSET
   1.172 +    #define DEC_Lost_digits          0x00000000
   1.173 +    #endif
   1.174 +    #define DEC_Overflow             0x00000008
   1.175 +    #define DEC_Clamped              0x00000000
   1.176 +    #define DEC_Rounded              0x00000000
   1.177 +    #define DEC_Subnormal            0x00000000
   1.178 +    #define DEC_Underflow            0x00000004
   1.179 +  #endif
   1.180 +
   1.181 +  /* IEEE 754 groupings for the flags                                 */
   1.182 +  /* [DEC_Clamped, DEC_Lost_digits, DEC_Rounded, and DEC_Subnormal    */
   1.183 +  /* are not in IEEE 754]                                             */
   1.184 +  #define DEC_IEEE_754_Division_by_zero  (DEC_Division_by_zero)
   1.185 +  #if DECSUBSET
   1.186 +  #define DEC_IEEE_754_Inexact           (DEC_Inexact | DEC_Lost_digits)
   1.187 +  #else
   1.188 +  #define DEC_IEEE_754_Inexact           (DEC_Inexact)
   1.189 +  #endif
   1.190 +  #define DEC_IEEE_754_Invalid_operation (DEC_Conversion_syntax |     \
   1.191 +                                          DEC_Division_impossible |   \
   1.192 +                                          DEC_Division_undefined |    \
   1.193 +                                          DEC_Insufficient_storage |  \
   1.194 +                                          DEC_Invalid_context |       \
   1.195 +                                          DEC_Invalid_operation)
   1.196 +  #define DEC_IEEE_754_Overflow          (DEC_Overflow)
   1.197 +  #define DEC_IEEE_754_Underflow         (DEC_Underflow)
   1.198 +
   1.199 +  /* flags which are normally errors (result is qNaN, infinite, or 0) */
   1.200 +  #define DEC_Errors (DEC_IEEE_754_Division_by_zero |                 \
   1.201 +                      DEC_IEEE_754_Invalid_operation |                \
   1.202 +                      DEC_IEEE_754_Overflow | DEC_IEEE_754_Underflow)
   1.203 +  /* flags which cause a result to become qNaN                        */
   1.204 +  #define DEC_NaNs    DEC_IEEE_754_Invalid_operation
   1.205 +
   1.206 +  /* flags which are normally for information only (finite results)   */
   1.207 +  #if DECSUBSET
   1.208 +  #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact    \
   1.209 +                          | DEC_Lost_digits)
   1.210 +  #else
   1.211 +  #define DEC_Information (DEC_Clamped | DEC_Rounded | DEC_Inexact)
   1.212 +  #endif
   1.213 +
   1.214 +  /* IEEE 854 names (for compatibility with older decNumber versions) */
   1.215 +  #define DEC_IEEE_854_Division_by_zero  DEC_IEEE_754_Division_by_zero
   1.216 +  #define DEC_IEEE_854_Inexact           DEC_IEEE_754_Inexact
   1.217 +  #define DEC_IEEE_854_Invalid_operation DEC_IEEE_754_Invalid_operation
   1.218 +  #define DEC_IEEE_854_Overflow          DEC_IEEE_754_Overflow
   1.219 +  #define DEC_IEEE_854_Underflow         DEC_IEEE_754_Underflow
   1.220 +
   1.221 +  /* Name strings for the exceptional conditions                      */
   1.222 +  #define DEC_Condition_CS "Conversion syntax"
   1.223 +  #define DEC_Condition_DZ "Division by zero"
   1.224 +  #define DEC_Condition_DI "Division impossible"
   1.225 +  #define DEC_Condition_DU "Division undefined"
   1.226 +  #define DEC_Condition_IE "Inexact"
   1.227 +  #define DEC_Condition_IS "Insufficient storage"
   1.228 +  #define DEC_Condition_IC "Invalid context"
   1.229 +  #define DEC_Condition_IO "Invalid operation"
   1.230 +  #if DECSUBSET
   1.231 +  #define DEC_Condition_LD "Lost digits"
   1.232 +  #endif
   1.233 +  #define DEC_Condition_OV "Overflow"
   1.234 +  #define DEC_Condition_PA "Clamped"
   1.235 +  #define DEC_Condition_RO "Rounded"
   1.236 +  #define DEC_Condition_SU "Subnormal"
   1.237 +  #define DEC_Condition_UN "Underflow"
   1.238 +  #define DEC_Condition_ZE "No status"
   1.239 +  #define DEC_Condition_MU "Multiple status"
   1.240 +  #define DEC_Condition_Length 21  /* length of the longest string,   */
   1.241 +                                   /* including terminator            */
   1.242 +
   1.243 +  /* Initialization descriptors, used by decContextDefault            */
   1.244 +  #define DEC_INIT_BASE         0
   1.245 +  #define DEC_INIT_DECIMAL32   32
   1.246 +  #define DEC_INIT_DECIMAL64   64
   1.247 +  #define DEC_INIT_DECIMAL128 128
   1.248 +  /* Synonyms */
   1.249 +  #define DEC_INIT_DECSINGLE  DEC_INIT_DECIMAL32
   1.250 +  #define DEC_INIT_DECDOUBLE  DEC_INIT_DECIMAL64
   1.251 +  #define DEC_INIT_DECQUAD    DEC_INIT_DECIMAL128
   1.252 +
   1.253 +  /* decContext routines                                              */
   1.254 +  U_INTERNAL decContext  * U_EXPORT2 uprv_decContextClearStatus(decContext *, uint32_t);
   1.255 +  U_INTERNAL decContext  * U_EXPORT2 uprv_decContextDefault(decContext *, int32_t);
   1.256 +  U_INTERNAL enum rounding U_EXPORT2 uprv_decContextGetRounding(decContext *);
   1.257 +  U_INTERNAL uint32_t      U_EXPORT2 uprv_decContextGetStatus(decContext *);
   1.258 +  U_INTERNAL decContext  * U_EXPORT2 uprv_decContextRestoreStatus(decContext *, uint32_t, uint32_t);
   1.259 +  U_INTERNAL uint32_t      U_EXPORT2 uprv_decContextSaveStatus(decContext *, uint32_t);
   1.260 +  U_INTERNAL decContext  * U_EXPORT2 uprv_decContextSetRounding(decContext *, enum rounding);
   1.261 +  U_INTERNAL decContext  * U_EXPORT2 uprv_decContextSetStatus(decContext *, uint32_t);
   1.262 +  U_INTERNAL decContext  * U_EXPORT2 uprv_decContextSetStatusFromString(decContext *, const char *);
   1.263 +  U_INTERNAL decContext  * U_EXPORT2 uprv_decContextSetStatusFromStringQuiet(decContext *, const char *);
   1.264 +  U_INTERNAL decContext  * U_EXPORT2 uprv_decContextSetStatusQuiet(decContext *, uint32_t);
   1.265 +  U_INTERNAL const char  * U_EXPORT2 uprv_decContextStatusToString(const decContext *);
   1.266 +  U_INTERNAL int32_t       U_EXPORT2 uprv_decContextTestEndian(uint8_t);
   1.267 +  U_INTERNAL uint32_t      U_EXPORT2 uprv_decContextTestSavedStatus(uint32_t, uint32_t);
   1.268 +  U_INTERNAL uint32_t      U_EXPORT2 uprv_decContextTestStatus(decContext *, uint32_t);
   1.269 +  U_INTERNAL decContext  * U_EXPORT2 uprv_decContextZeroStatus(decContext *);
   1.270 +
   1.271 +#endif

mercurial