"Fossies" - the Fresh Open Source Software Archive

Member "asymptote-2.61/prc/PRCdouble.h" (18 Nov 2019, 3765 Bytes) of package /linux/misc/asymptote-2.61.src.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "PRCdouble.h" see the Fossies "Dox" file reference documentation.

    1 #ifndef __PRC_DOUBLE_H
    2 #define __PRC_DOUBLE_H
    3 
    4 #include <cstdlib>
    5 #include <cmath>
    6 #include <cstring>
    7 
    8 #ifdef HAVE_CONFIG_H
    9 #include "config.h"
   10 #endif
   11 
   12 #ifdef BYTE_ORDER
   13 # undef WORDS_BIG_ENDIAN
   14 # undef WORDS_LITTLE_ENDIAN
   15 # if BYTE_ORDER == BIG_ENDIAN
   16 #  define WORDS_BIG_ENDIAN 1
   17 # endif
   18 # if BYTE_ORDER == LITTLE_ENDIAN
   19 #  define WORDS_LITTLE_ENDIAN 1
   20 # endif
   21 #endif   
   22 
   23 // from Adobe's documentation
   24 
   25 union ieee754_double
   26 {
   27  double d;
   28  /* This is the IEEE 754 double-precision format. */
   29  struct
   30  {
   31 #ifdef WORDS_BIGENDIAN
   32   unsigned int negative:1;
   33   unsigned int exponent:11;
   34   /* Together these comprise the mantissa.  */
   35   unsigned int mantissa0:20;
   36   unsigned int mantissa1:32;
   37 #else
   38   /* Together these comprise the mantissa.  */
   39   unsigned int mantissa1:32;
   40   unsigned int mantissa0:20;
   41   unsigned int exponent:11;
   42   unsigned int negative:1;
   43 #endif
   44  } ieee;
   45 };
   46 
   47 union ieee754_float
   48 {
   49  float f;
   50  /* This is the IEEE 754 float-precision format. */
   51  struct {
   52 #ifdef WORDS_BIGENDIAN
   53  unsigned int negative:1;
   54  unsigned int exponent:8;
   55  unsigned int mantissa:23;
   56 #else
   57  unsigned int mantissa:23;
   58  unsigned int exponent:8;
   59  unsigned int negative:1;
   60 #endif
   61  } ieee;
   62 };
   63 
   64 enum ValueType {VT_double,VT_exponent};
   65 
   66 struct sCodageOfFrequentDoubleOrExponent
   67 {
   68   short Type;
   69   short NumberOfBits;
   70   unsigned Bits;
   71   union {
   72     unsigned ul[2];
   73     double Value;
   74   } u2uod;
   75 };
   76 
   77 #ifdef WORDS_BIGENDIAN
   78 #       define DOUBLEWITHTWODWORD(upper,lower)  upper,lower
   79 #       define UPPERPOWER       (0)
   80 #       define LOWERPOWER       (!UPPERPOWER)
   81 
   82 #       define NEXTBYTE(pbd)                            ((pbd)++)
   83 #       define PREVIOUSBYTE(pbd)                ((pbd)--)
   84 #       define MOREBYTE(pbd,pbend)              ((pbd)<=(pbend))
   85 #       define OFFSETBYTE(pbd,offset)   ((pbd)+=offset)
   86 #       define BEFOREBYTE(pbd)                  ((pbd)-1)
   87 #       define DIFFPOINTERS(p1,p2)              ((p1)-(p2))
   88 #       define SEARCHBYTE(pbstart,b,nb) (unsigned char *)memrchr((pbstart),(b),(nb))
   89 #       define BYTEAT(pb,i)     *((pb)-(i))
   90 #else
   91 #       define DOUBLEWITHTWODWORD(upper,lower)  lower,upper
   92 #       define UPPERPOWER       (1)
   93 #       define LOWERPOWER       (!UPPERPOWER)
   94 
   95 #       define NEXTBYTE(pbd)                            ((pbd)--)
   96 #       define PREVIOUSBYTE(pbd)                ((pbd)++)
   97 #       define MOREBYTE(pbd,pbend)              ((pbd)>=(pbend))
   98 #       define OFFSETBYTE(pbd,offset)   ((pbd)-=offset)
   99 #       define BEFOREBYTE(pbd)                  ((pbd)+1)
  100 #       define DIFFPOINTERS(p1,p2)              ((unsigned)((p2)-(p1)))
  101 #       define SEARCHBYTE(pbstart,b,nb) (unsigned char *)memchr((pbstart),(b),(nb))
  102 #       define BYTEAT(pb,i)     *((pb)+(i))
  103 #endif
  104 
  105 #define MAXLENGTHFORCOMPRESSEDTYPE      ((22+1+1+4+6*(1+8))+7)/8
  106 
  107 #define NEGATIVE(d)     (((union ieee754_double *)&(d))->ieee.negative)
  108 #define EXPONENT(d)     (((union ieee754_double *)&(d))->ieee.exponent)
  109 #define MANTISSA0(d)    (((union ieee754_double *)&(d))->ieee.mantissa0)
  110 #define MANTISSA1(d)    (((union ieee754_double *)&(d))->ieee.mantissa1)
  111 
  112 typedef unsigned char PRCbyte;
  113 typedef unsigned short PRCword;
  114 typedef unsigned PRCdword;
  115 
  116 extern PRCdword stadwZero[2],stadwNegativeZero[2];
  117 
  118 #define NUMBEROFELEMENTINACOFDOE   (2077)
  119 
  120 #ifdef WORDS_BIGENDIAN
  121 #       define DOUBLEWITHTWODWORDINTREE(upper,lower)    {upper,lower} 
  122 #else
  123 #       define DOUBLEWITHTWODWORDINTREE(upper,lower)    {lower,upper}
  124 #endif
  125 extern sCodageOfFrequentDoubleOrExponent acofdoe[NUMBEROFELEMENTINACOFDOE];
  126 
  127 struct sCodageOfFrequentDoubleOrExponent* getcofdoe(unsigned,short);
  128 
  129 #define STAT_V
  130 #define STAT_DOUBLE
  131 
  132 int stCOFDOECompare(const void*,const void*);
  133 
  134 #ifdef WORDS_BIGENDIAN
  135 #ifndef HAVE_MEMRCHR
  136 void *memrchr(const void *,int,size_t);
  137 #endif
  138 #endif
  139 
  140 #endif // __PRC_DOUBLE_H