/************************************************************************
*                       - INFOFLEX System -
* This source code is CONFIDENTIAL and PROPRIETARY to CUSTOMWARE COMPUTING,
* INC. (CWC). The information contained herein may not be used, copied or
* disclosed in whole or in part except as permitted by written agreement
* signed by an officer of CWC.
*
* COPYRIGHT (c) 1986 CUSTOMWARE COMPUTING, INC., BURLINGAME, CALIFORNIA.
* ALL RIGHTS RESERVED.
*
* Version: %V%  6
* Date: 96/05/05  16:53:50
*************************************************************************/

/*
 * Unpacked Format (format for program usage)
 *
 *    Signed exponent "dec_exp" ranging from  -64 to +63
 *    Separate sign of mantissa "dec_pos"
 *    Base 100 digits (range 0 - 99) with decimal point
 *  immediately to the left of first digit.
 */

#ifndef DECSIZE
#define DECSIZE 16
#define DECUNKNOWN -2

struct decimal
    {
    short dec_exp;    /* exponent base 100    */
    short dec_pos;    /* sign: 1=pos, 0=neg, -1=null  */
    short dec_ndgts;    /* number of significant digits  */
    char  dec_dgts[DECSIZE];  /* actual digits base 100  */
    };
typedef struct decimal dec_t;

/*
 *  A decimal null will be represented internally by setting dec_pos
 *  equal to DECPOSNULL
 */

#define DECPOSNULL  (-1)

/*
 * DECLEN calculates minumum number of bytes
 * necessary to hold a decimal(m,n)
 * where m = total # significant digits and
 *   n = significant digits to right of decimal
 */

#define DECLEN(m,n)  (((m)+((n)&1)+3)/2)
#define DECLENGTH(len)  DECLEN(PRECTOT(len),PRECDEC(len))

/*
 * DECPREC calculates a default precision given
 * number of bytes used to store number
 */

#define DECPREC(size)  (((size-1)<<9)+2)

/* macros to look at and make encoded decimal precision
 *
 *  PRECTOT(x)    return total precision (digits total)
 *  PRECDEC(x)     return decimal precision (digits to right)
 *  PRECMAKE(x,y)  make precision from total and decimal
 */

#define PRECTOT(x)  (((x)>>8) & 0xff)
#define PRECDEC(x)  ((x) & 0xff)
#define PRECMAKE(x,y)  (((x)<<8) + (y))

/*
 * Packed Format  (format in records in files)
 *
 *    First byte =
 *    top 1 bit = sign 0=neg, 1=pos
 *    low 7 bits = Exponent in excess 64 format
 *    Rest of bytes = base 100 digits in 100 complement format
 *    Notes --  This format sorts numerically with just a
 *    simple byte by byte unsigned comparison.
 *    Zero is represented as 80,00,00,... (hex).
 *    Negative numbers have the exponent complemented
 *    and the base 100 digits in 100's complement
 */

#endif
