chromium/third_party/icu/source/i18n/decContext.h

// © 2016 and later: Unicode, Inc. and others.
// License & terms of use: http://www.unicode.org/copyright.html
/* ------------------------------------------------------------------ */
/* Decimal Context module header                                      */
/* ------------------------------------------------------------------ */
/* Copyright (c) IBM Corporation, 2000-2011.   All rights reserved.   */
/*                                                                    */
/* This software is made available under the terms of the             */
/* ICU License -- ICU 1.8.1 and later.                                */
/*                                                                    */
/* The description and User's Guide ("The decNumber C Library") for   */
/* this software is called decNumber.pdf.  This document is           */
/* available, together with arithmetic and format specifications,     */
/* testcases, and Web links, on the General Decimal Arithmetic page.  */
/*                                                                    */
/* Please send comments, suggestions, and corrections to the author:  */
/*   [email protected]                                                   */
/*   Mike Cowlishaw, IBM Fellow                                       */
/*   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         */
/* ------------------------------------------------------------------ */

/* Modified version, for use from within ICU.
 *    Renamed public functions, to avoid an unwanted export of the 
 *    standard names from the ICU library.
 *
 *    Use ICU's uprv_malloc() and uprv_free()
 *
 *    Revert comment syntax to plain C
 *
 *    Remove a few compiler warnings.
 */
#include "unicode/utypes.h"
#include "putilimp.h"

/*                                                                    */
/* Context variables must always have valid values:                   */
/*                                                                    */
/*  status   -- [any bits may be cleared, but not set, by user]       */
/*  round    -- must be one of the enumerated rounding modes          */
/*                                                                    */
/* The following variables are implied for fixed size formats (i.e.,  */
/* they are ignored) but should still be set correctly in case used   */
/* with decNumber functions:                                          */
/*                                                                    */
/*  clamp    -- must be either 0 or 1                                 */
/*  digits   -- must be in the range 1 through 999999999              */
/*  emax     -- must be in the range 0 through 999999999              */
/*  emin     -- must be in the range 0 through -999999999             */
/*  extended -- must be either 0 or 1 [present only if DECSUBSET]     */
/*  traps    -- only defined bits may be set                          */
/*                                                                    */
/* ------------------------------------------------------------------ */

#if !defined(DECCONTEXT)
  #define DECCONTEXT
  #define DECCNAME
  #define DECCFULLNAME
  #define DECCAUTHOR

  #if !defined(int32_t)
/* #include <stdint.h>   */         /* C99 standard integers           */
  #endif
  #include <stdio.h>               /* for printf, etc.                */
  #include <signal.h>              /* for traps                       */

  /* Extended flags setting -- set this to 0 to use only IEEE flags   */
  #if !defined(DECEXTFLAG)
  #define DECEXTFLAG
  #endif

  /* Conditional code flag -- set this to 0 for best performance      */
  #if !defined(DECSUBSET)
  #define DECSUBSET
  #endif

  /* Context for operations, with associated constants                */
  enum rounding {};
  #define DEC_ROUND_DEFAULT

  decContext;

  /* Maxima and Minima for context settings                           */
  #define DEC_MAX_DIGITS
  #define DEC_MIN_DIGITS
  #define DEC_MAX_EMAX
  #define DEC_MIN_EMAX
  #define DEC_MAX_EMIN
  #define DEC_MIN_EMIN
  #define DEC_MAX_MATH

  /* Classifications for decimal numbers, aligned with 754 (note that */
  /* 'normal' and 'subnormal' are meaningful only with a decContext   */
  /* or a fixed size format).                                         */
  enum decClass {};
  /* Strings for the decClasses */
  #define DEC_ClassString_SN
  #define DEC_ClassString_QN
  #define DEC_ClassString_NI
  #define DEC_ClassString_NN
  #define DEC_ClassString_NS
  #define DEC_ClassString_NZ
  #define DEC_ClassString_PZ
  #define DEC_ClassString_PS
  #define DEC_ClassString_PN
  #define DEC_ClassString_PI
  #define DEC_ClassString_UN

  /* Trap-enabler and Status flags (exceptional conditions), and      */
  /* their names.  The top byte is reserved for internal use          */
  #if DECEXTFLAG
    /* Extended flags */
    #define DEC_Conversion_syntax
    #define DEC_Division_by_zero
    #define DEC_Division_impossible
    #define DEC_Division_undefined
    #define DEC_Insufficient_storage
    #define DEC_Inexact
    #define DEC_Invalid_context
    #define DEC_Invalid_operation
    #if DECSUBSET
    #define DEC_Lost_digits
    #endif
    #define DEC_Overflow
    #define DEC_Clamped
    #define DEC_Rounded
    #define DEC_Subnormal
    #define DEC_Underflow
  #else
    /* IEEE flags only */
    #define DEC_Conversion_syntax
    #define DEC_Division_by_zero
    #define DEC_Division_impossible
    #define DEC_Division_undefined
    #define DEC_Insufficient_storage
    #define DEC_Inexact
    #define DEC_Invalid_context
    #define DEC_Invalid_operation
    #if DECSUBSET
    #define DEC_Lost_digits
    #endif
    #define DEC_Overflow
    #define DEC_Clamped
    #define DEC_Rounded
    #define DEC_Subnormal
    #define DEC_Underflow
  #endif

  /* IEEE 754 groupings for the flags                                 */
  /* [DEC_Clamped, DEC_Lost_digits, DEC_Rounded, and DEC_Subnormal    */
  /* are not in IEEE 754]                                             */
  #define DEC_IEEE_754_Division_by_zero
  #if DECSUBSET
  #define DEC_IEEE_754_Inexact
  #else
  #define DEC_IEEE_754_Inexact
  #endif
  #define DEC_IEEE_754_Invalid_operation
  #define DEC_IEEE_754_Overflow
  #define DEC_IEEE_754_Underflow

  /* flags which are normally errors (result is qNaN, infinite, or 0) */
  #define DEC_Errors
  /* flags which cause a result to become qNaN                        */
  #define DEC_NaNs

  /* flags which are normally for information only (finite results)   */
  #if DECSUBSET
  #define DEC_Information
  #else
  #define DEC_Information
  #endif

  /* IEEE 854 names (for compatibility with older decNumber versions) */
  #define DEC_IEEE_854_Division_by_zero
  #define DEC_IEEE_854_Inexact
  #define DEC_IEEE_854_Invalid_operation
  #define DEC_IEEE_854_Overflow
  #define DEC_IEEE_854_Underflow

  /* Name strings for the exceptional conditions                      */
  #define DEC_Condition_CS
  #define DEC_Condition_DZ
  #define DEC_Condition_DI
  #define DEC_Condition_DU
  #define DEC_Condition_IE
  #define DEC_Condition_IS
  #define DEC_Condition_IC
  #define DEC_Condition_IO
  #if DECSUBSET
  #define DEC_Condition_LD
  #endif
  #define DEC_Condition_OV
  #define DEC_Condition_PA
  #define DEC_Condition_RO
  #define DEC_Condition_SU
  #define DEC_Condition_UN
  #define DEC_Condition_ZE
  #define DEC_Condition_MU
  #define DEC_Condition_Length
                                   /* including terminator            */

  /* Initialization descriptors, used by decContextDefault            */
  #define DEC_INIT_BASE
  #define DEC_INIT_DECIMAL32
  #define DEC_INIT_DECIMAL64
  #define DEC_INIT_DECIMAL128
  /* Synonyms */
  #define DEC_INIT_DECSINGLE
  #define DEC_INIT_DECDOUBLE
  #define DEC_INIT_DECQUAD

  /* decContext routines                                              */
  U_CAPI decContext  * U_EXPORT2 uprv_decContextClearStatus(decContext *, uint32_t);
  U_CAPI decContext  * U_EXPORT2 uprv_decContextDefault(decContext *, int32_t);
  U_CAPI enum rounding U_EXPORT2 uprv_decContextGetRounding(decContext *);
  U_CAPI uint32_t      U_EXPORT2 uprv_decContextGetStatus(decContext *);
  U_CAPI decContext  * U_EXPORT2 uprv_decContextRestoreStatus(decContext *, uint32_t, uint32_t);
  U_CAPI uint32_t      U_EXPORT2 uprv_decContextSaveStatus(decContext *, uint32_t);
  U_CAPI decContext  * U_EXPORT2 uprv_decContextSetRounding(decContext *, enum rounding);
  U_CAPI decContext  * U_EXPORT2 uprv_decContextSetStatus(decContext *, uint32_t);
  U_CAPI decContext  * U_EXPORT2 uprv_decContextSetStatusFromString(decContext *, const char *);
  U_CAPI decContext  * U_EXPORT2 uprv_decContextSetStatusFromStringQuiet(decContext *, const char *);
  U_CAPI decContext  * U_EXPORT2 uprv_decContextSetStatusQuiet(decContext *, uint32_t);
  U_CAPI const char  * U_EXPORT2 uprv_decContextStatusToString(const decContext *);
  U_CAPI uint32_t      U_EXPORT2 uprv_decContextTestSavedStatus(uint32_t, uint32_t);
  U_CAPI uint32_t      U_EXPORT2 uprv_decContextTestStatus(decContext *, uint32_t);
  U_CAPI decContext  * U_EXPORT2 uprv_decContextZeroStatus(decContext *);

#endif