root/src/decNumber/decimal32.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: ba161c23-f62c-11ec-b4ce-80ee73e9b8e7
   4 /* ------------------------------------------------------------------- */
   5 /* Decimal 32-bit format module header                                 */
   6 /* ------------------------------------------------------------------- */
   7 /*                                                                     */
   8 /* Copyright (c) IBM Corporation, 2000, 2006.  All rights reserved.    */
   9 /*                                                                     */
  10 /* This software is made available under the terms of the ICU License. */
  11 /*                                                                     */
  12 /* The description and User's Guide ("The decNumber C Library") for    */
  13 /* this software is called decNumber.pdf.  This document is available, */
  14 /* together with arithmetic and format specifications, testcases, and  */
  15 /* 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 
  24 #if !defined(DECIMAL32)
  25 # define DECIMAL32
  26 # define DEC32NAME     "decimal32"                    /* Short name   */
  27 # define DEC32FULLNAME "Decimal 32-bit Number"        /* Verbose name */
  28 # define DEC32AUTHOR   "Mike Cowlishaw"               /* Who to blame */
  29 
  30   /* parameters for decimal32s */
  31 # define DECIMAL32_Bytes  4             /* length                     */
  32 # define DECIMAL32_Pmax   7             /* maximum precision (digits) */
  33 # define DECIMAL32_Emax   96            /* maximum adjusted exponent  */
  34 # define DECIMAL32_Emin  -95            /* minimum adjusted exponent  */
  35 # define DECIMAL32_Bias   101           /* bias for the exponent      */
  36 # define DECIMAL32_String 15            /* maximum string length, +1  */
  37 # define DECIMAL32_EconL  6             /* exp. continuation length   */
  38   /* highest biased exponent (Elimit-1)                               */
  39 # define DECIMAL32_Ehigh                                               \
  40     (DECIMAL32_Emax+DECIMAL32_Bias-DECIMAL32_Pmax+1)
  41 
  42   /* check enough digits, if pre-defined                              */
  43 # if defined(DECNUMDIGITS)
  44 #  if (DECNUMDIGITS<DECIMAL32_Pmax)
  45 #   error decimal32.h needs pre-defined DECNUMDIGITS>=7 for safe use
  46 #  endif
  47 # endif
  48 
  49 # if !defined(DECNUMDIGITS)
  50 #  define DECNUMDIGITS DECIMAL32_Pmax  /* size if not already defined */
  51 # endif /* if !defined(DECNUMDIGITS) */
  52 # if !defined(DECNUMBER)
  53 #  include "decNumber.h"               /* context and number library  */
  54 # endif /* if !defined(DECNUMBER) */
  55 
  56   /* Decimal 32-bit type, accessible by bytes */
  57   typedef struct {
  58     uint8_t bytes[DECIMAL32_Bytes];    /* decimal32: 1, 5, 6, 20 bits */
  59     } decimal32;
  60 
  61   /* special values [top byte excluding sign bit; last two bits are   */
  62   /* don't-care for Infinity on input, last bit don't-care for NaN]   */
  63 # if !defined(DECIMAL_NaN)
  64 #  define DECIMAL_NaN     0x7c          /* 0 11111 00 NaN             */
  65 #  define DECIMAL_sNaN    0x7e          /* 0 11111 10 sNaN            */
  66 #  define DECIMAL_Inf     0x78          /* 0 11110 00 Infinity        */
  67 # endif
  68 
  69   /* ---------------------------------------------------------------- */
  70   /* Routines                                                         */
  71   /* ---------------------------------------------------------------- */
  72   /* String conversions                                               */
  73   decimal32 * decimal32FromString(decimal32 *, const char *,
  74     decContext *);
  75   char * decimal32ToString(const decimal32 *, char *);
  76   char * decimal32ToEngString(const decimal32 *, char *);
  77 
  78   /* decNumber conversions                                            */
  79   decimal32 * decimal32FromNumber(decimal32 *, const decNumber *,
  80                                   decContext *);
  81   decNumber * decimal32ToNumber(const decimal32 *, decNumber *);
  82 
  83   /* Format-dependent utilities                                       */
  84   uint32_t    decimal32IsCanonical(const decimal32 *);
  85   decimal32 * decimal32Canonical(decimal32 *, const decimal32 *);
  86 
  87 #endif

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