root/src/decNumber/decimal128.h

/* [previous][next][first][last][top][bottom][index][help] */
   1 // vim: filetype=c:tabstop=4:ai:expandtab
   2 // SPDX-License-Identifier: ICU
   3 // scspell-id: b69cc81e-f62c-11ec-a05b-80ee73e9b8e7
   4 /* ------------------------------------------------------------------ */
   5 /* Decimal 128-bit format module header                               */
   6 /* ------------------------------------------------------------------ */
   7 /* Copyright (c) IBM Corporation, 2000, 2005.  All rights reserved.   */
   8 /*                                                                    */
   9 /* This software is made available under the terms of the             */
  10 /* ICU License -- ICU 1.8.1 and later.                                */
  11 /*                                                                    */
  12 /* The description and User's Guide ("The decNumber C Library") for   */
  13 /* this software is called decNumber.pdf.  This document is           */
  14 /* available, together with arithmetic and format specifications,     */
  15 /* testcases, and Web links, on the General Decimal Arithmetic page.  */
  16 /*                                                                    */
  17 /* Please send comments, suggestions, and corrections to the author:  */
  18 /*   mfc@uk.ibm.com                                                   */
  19 /*   Mike Cowlishaw, IBM Fellow                                       */
  20 /*   IBM UK, PO Box 31, Birmingham Road, Warwick CV34 5JL, UK         */
  21 /* ------------------------------------------------------------------ */
  22 
  23 #if !defined(DECIMAL128)
  24 # define DECIMAL128
  25 # define DEC128NAME     "decimal128"                  /* Short name   */
  26 # define DEC128FULLNAME "Decimal 128-bit Number"      /* Verbose name */
  27 # define DEC128AUTHOR   "Mike Cowlishaw"              /* Who to blame */
  28 
  29   /* parameters for decimal128s */
  30 # define DECIMAL128_Bytes  16           /* length                     */
  31 # define DECIMAL128_Pmax   34           /* maximum precision (digits) */
  32 # define DECIMAL128_Emax   6144         /* maximum adjusted exponent  */
  33 # define DECIMAL128_Emin  -6143         /* minimum adjusted exponent  */
  34 # define DECIMAL128_Bias   6176         /* bias for the exponent      */
  35 # define DECIMAL128_String 43           /* maximum string length, +1  */
  36 # define DECIMAL128_EconL  12           /* exp. continuation length   */
  37   /* highest biased exponent (Elimit-1)                               */
  38 # define DECIMAL128_Ehigh                                              \
  39     (DECIMAL128_Emax+DECIMAL128_Bias-DECIMAL128_Pmax+1)
  40 
  41   /* check enough digits, if pre-defined                              */
  42 # if defined(DECNUMDIGITS)
  43 #  if (DECNUMDIGITS<DECIMAL128_Pmax)
  44 #   error decimal128.h needs pre-defined DECNUMDIGITS>=34 for safe use
  45 #  endif
  46 # endif
  47 
  48 # ifndef DECNUMDIGITS
  49 #  define DECNUMDIGITS DECIMAL128_Pmax /* size if not already defined */
  50 # endif
  51 # ifndef DECNUMBER
  52 #  include "decNumber.h"                /* context and number library */
  53 # endif
  54 
  55   /* Decimal 128-bit type, accessible by bytes                        */
  56   typedef struct {
  57     uint8_t bytes[DECIMAL128_Bytes]; /* decimal128: 1, 5, 12, 110 bits*/
  58     } decimal128;
  59 
  60   /* special values [top byte excluding sign bit; last two bits are   */
  61   /* don't-care for Infinity on input, last bit don't-care for NaN]   */
  62 # if !defined(DECIMAL_NaN)
  63 #  define DECIMAL_NaN     0x7c          /* 0 11111 00 NaN             */
  64 #  define DECIMAL_sNaN    0x7e          /* 0 11111 10 sNaN            */
  65 #  define DECIMAL_Inf     0x78          /* 0 11110 00 Infinity        */
  66 # endif
  67 
  68   /* ---------------------------------------------------------------- */
  69   /* Routines                                                         */
  70   /* ---------------------------------------------------------------- */
  71   /* String conversions                                               */
  72   decimal128 * decimal128FromString(decimal128 *, const char *,
  73     decContext *);
  74   char * decimal128ToString(const decimal128 *, char *);
  75   char * decimal128ToEngString(const decimal128 *, char *);
  76 
  77   /* decNumber conversions                                            */
  78   decimal128 * decimal128FromNumber(decimal128 *, const decNumber *,
  79                                     decContext *);
  80   decNumber * decimal128ToNumber(const decimal128 *, decNumber *);
  81 
  82   /* Format-dependent utilities                                       */
  83   uint32_t    decimal128IsCanonical(const decimal128 *);
  84   decimal128 * decimal128Canonical(decimal128 *, const decimal128 *);
  85 
  86 #endif

/* [previous][next][first][last][top][bottom][index][help] */