home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextLibrary / Frameworks / NEXTIME.framework / Versions / A / Headers / sampleMath.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-30  |  1.6 KB  |  48 lines

  1.  
  2. /*
  3.  * Macros used for performing operations on doubles used to represent time.
  4.  * These functions pay particular attention to errors which can accumulate due
  5.  * to the approximate nature of floating point representations.
  6.  */
  7.  
  8. /*
  9.  * One, two, and three bits of error in relation to a 48 bit significand IEEE
  10.  * representation of the value 1.0.
  11.  */
  12. #define ONE_ULPS    .000000000000003552713678800500929355621337890625
  13. #define TWO_ULPS    .000000000000010658141036401502788066864013671875
  14. #define THREE_ULPS    .000000000000024868995751603506505489349365234375
  15. #define FOUR_ULPS    .000000000000053290705182007513940334320068359375
  16.  
  17. /*
  18.  * When performing many operations, we tend to lose precision, which shows up
  19.  * as truncation towards zero.  We must compensate for this prior to quantizing
  20.  * a double into an integer, to avoid 'off by 1' errors.
  21.  */
  22.  
  23. #define SAMPLE_INDEX( dT, duration )    ((int)(((dT)/(duration)) + 0.5))
  24.  
  25. /*
  26.  * Default tolerance, or error permitted when comparing sample times for
  27.  * equivalence.  This value is a maximum, and media objects may adjust it
  28.  * downward so as to represent no more than (minimum sample duration / 2).
  29.  */
  30. #define DEFAULT_TOLERANCE    (1.0/1200.0) /* half of QuickTime's 1/600 */
  31.                          /* second default resolution */
  32.  
  33. /*
  34.  * Fuzzy value comparison function.  Used in testing sample times for
  35.  * equivalence, where the tolerance represents half the minimum non-zero
  36.  * sample duration. 
  37.  */
  38.  static inline BOOL
  39. isEquivalent( double t1, double t2, double tolerance )
  40. {
  41.     if (    t1 == t2
  42.         ||    ((t1 + tolerance) >= t2 && ((t1 - tolerance) < t2 )) )
  43.             return YES;
  44.         
  45.     return NO;
  46. }
  47.  
  48.