home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progc / fixed300.arj / CDSS0026.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-14  |  1.8 KB  |  98 lines

  1. #if 0
  2. From: Scott Ladd
  3. Subject: ZTC Bug 35171
  4. Status: Fixed in 3.0b5
  5. #endif
  6.  
  7. //      compile this file with
  8. //
  9. //          ztc -c -o slz3bug8.cpp
  10. //
  11. //      and ZTC2B will crash with a ZTC Bug 35171
  12.  
  13. typedef long Fixed;
  14.  
  15. extern "C"
  16.     {
  17.     Fixed FixedAdd(Fixed f1, Fixed f2);
  18.     Fixed FixedSub(Fixed f1, Fixed f2);
  19.  
  20.     Fixed FixedMul(Fixed f1, Fixed f2);
  21.     Fixed FixedDiv(Fixed f1, Fixed f2);
  22.  
  23.     Fixed FixedAbs(Fixed ff);
  24.  
  25.     void  FixedSet(unsigned char decpos);
  26.  
  27.     int   FixedOut(char * buf, Fixed ff, unsigned char prec);
  28.  
  29.     Fixed FloatToFixed(float f);
  30.     float FixedToFloat(Fixed f);
  31.     }
  32.  
  33. class FixedPoint
  34.     {
  35.     public:
  36.         FixedPoint();
  37.         FixedPoint(const FixedPoint & f);
  38.         FixedPoint(float f);
  39.  
  40.         void operator = (const FixedPoint & f);
  41.  
  42.         friend FixedPoint operator - (FixedPoint f1,FixedPoint f2);
  43.         friend FixedPoint operator / (FixedPoint f1,FixedPoint f2);
  44.  
  45.     protected:
  46.         Fixed Value;
  47.     };
  48.  
  49. inline FixedPoint::FixedPoint()
  50.     {
  51.     Value = 0L;
  52.     }
  53.  
  54. inline FixedPoint::FixedPoint(const FixedPoint & f)
  55.     {
  56.     Value = f.Value;
  57.     }
  58.  
  59. inline FixedPoint::FixedPoint(float f)
  60.     {
  61.     Value = FloatToFixed(f);
  62.     }
  63.  
  64. inline void FixedPoint::operator = (const FixedPoint & f)
  65.     {
  66.     Value = f.Value;
  67.     }
  68.  
  69. inline FixedPoint operator - (FixedPoint f1, FixedPoint f2)
  70.     {
  71.     FixedPoint temp;
  72.  
  73.     temp.Value = FixedSub(f1.Value,f2.Value);
  74.  
  75.     return temp;
  76.     }
  77.  
  78. inline FixedPoint operator / (FixedPoint f1, FixedPoint f2)
  79.     {
  80.     FixedPoint temp;
  81.  
  82.     temp.Value = FixedDiv(f1.Value,f2.Value);
  83.  
  84.     return temp;
  85.     }
  86.  
  87. FixedPoint XMax, XMin, deltaX;
  88.  
  89. int main()
  90.     {
  91.     XMax =  1.2F;
  92.     XMin = -2.0F;
  93.  
  94.     deltaX = (XMax - XMin) / 256.0F;
  95.  
  96.     return 0;
  97.     }
  98.