home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 6 / 06.iso / a / a610 / 4.ddi / INCL / DECIMAL.H next >
Encoding:
C/C++ Source or Header  |  1989-12-08  |  2.7 KB  |  93 lines

  1. /***************************************************************************
  2.  *
  3.  *                    RELATIONAL DATABASE SYSTEMS, INC.
  4.  *
  5.  *  COPYRIGHT (c) 1981-1986 RELATIONAL DATABASE SYSTEMS, INC., MENLO PARK, 
  6.  *  CALIFORNIA.  All rights reserved.  No part of this work covered by the 
  7.  *  copyright hereon may be reproduced or used in any form or by any means 
  8.  *  -- graphic, electronic, or mechanical, including photocopying, 
  9.  *  recording, taping, or information storage and retrieval systems --
  10.  *  without permission of RDS.
  11.  *
  12.  *  Title:    decimal.h
  13.  *  Sccsid:    @(#)decimal.h    4.6    1/31/86  06:09:08
  14.  *  Description:
  15.  *        Header file for decimal data type.
  16.  *
  17.  ***************************************************************************
  18.  */
  19.  
  20.  
  21. /*
  22.  * Unpacked Format (format for program usage)
  23.  *
  24.  *    Signed exponent "dec_exp" ranging from  -64 to +63
  25.  *    Separate sign of mantissa "dec_pos"
  26.  *    Base 100 digits (range 0 - 99) with decimal point
  27.  *    immediately to the left of first digit.
  28.  */
  29.  
  30. #ifndef DECSIZE
  31. #define DECSIZE 16
  32. #define DECUNKNOWN -2
  33.  
  34. struct decimal
  35.     {
  36.     short dec_exp;        /* exponent base 100        */
  37.     short dec_pos;        /* sign: 1=pos, 0=neg, -1=null    */
  38.     short dec_ndgts;        /* number of significant digits    */
  39.     char  dec_dgts[DECSIZE];    /* actual digits base 100    */
  40.     };
  41. typedef struct decimal dec_t;
  42.  
  43. /*
  44.  *  A decimal null will be represented internally by setting dec_pos
  45.  *  equal to DECPOSNULL
  46.  */
  47.  
  48. #define DECPOSNULL    (-1)
  49.  
  50. /*
  51.  * DECLEN calculates minimum number of bytes
  52.  * necessary to hold a decimal(m,n)
  53.  * where m = total # significant digits and
  54.  *     n = significant digits to right of decimal
  55.  */
  56.  
  57. #define DECLEN(m,n)    (((m)+((n)&1)+3)/2)
  58. #define DECLENGTH(len)    DECLEN(PRECTOT(len),PRECDEC(len))
  59.  
  60. /*
  61.  * DECPREC calculates a default precision given
  62.  * number of bytes used to store number
  63.  */
  64.  
  65. #define DECPREC(size)    (((size-1)<<9)+2)
  66.  
  67. /* macros to look at and make encoded decimal precision
  68.  *
  69.  *  PRECTOT(x)        return total precision (digits total)
  70.  *  PRECDEC(x)         return decimal precision (digits to right)
  71.  *  PRECMAKE(x,y)    make precision from total and decimal
  72.  */
  73.  
  74. #define PRECTOT(x)    (((x)>>8) & 0xff)
  75. #define PRECDEC(x)    ((x) & 0xff)
  76. #define PRECMAKE(x,y)    (((x)<<8) + (y))
  77.  
  78. /*
  79.  * Packed Format  (format in records in files)
  80.  *
  81.  *    First byte =
  82.  *      top 1 bit = sign 0=neg, 1=pos
  83.  *      low 7 bits = Exponent in excess 64 format
  84.  *    Rest of bytes = base 100 digits in 100 complement format
  85.  *    Notes --    This format sorts numerically with just a
  86.  *        simple byte by byte unsigned comparison.
  87.  *        Zero is represented as 80,00,00,... (hex).
  88.  *        Negative numbers have the exponent complemented
  89.  *        and the base 100 digits in 100's complement
  90.  */
  91.  
  92. #endif /* DECSIZE */
  93.