home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 275 / DPCS0111DVD.ISO / Toolkit / Audio-Visual / VirtualDub / Source / VirtualDub-1.9.10-src.7z / src / h / vd2 / system / Fraction.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-09-14  |  3.1 KB  |  96 lines

  1. //    VirtualDub - Video processing and capture application
  2. //    System library component
  3. //    Copyright (C) 1998-2004 Avery Lee, All Rights Reserved.
  4. //
  5. //    Beginning with 1.6.0, the VirtualDub system library is licensed
  6. //    differently than the remainder of VirtualDub.  This particular file is
  7. //    thus licensed as follows (the "zlib" license):
  8. //
  9. //    This software is provided 'as-is', without any express or implied
  10. //    warranty.  In no event will the authors be held liable for any
  11. //    damages arising from the use of this software.
  12. //
  13. //    Permission is granted to anyone to use this software for any purpose,
  14. //    including commercial applications, and to alter it and redistribute it
  15. //    freely, subject to the following restrictions:
  16. //
  17. //    1.    The origin of this software must not be misrepresented; you must
  18. //        not claim that you wrote the original software. If you use this
  19. //        software in a product, an acknowledgment in the product
  20. //        documentation would be appreciated but is not required.
  21. //    2.    Altered source versions must be plainly marked as such, and must
  22. //        not be misrepresented as being the original software.
  23. //    3.    This notice may not be removed or altered from any source
  24. //        distribution.
  25.  
  26. #ifndef f_VD2_SYSTEM_FRACTION_H
  27. #define f_VD2_SYSTEM_FRACTION_H
  28.  
  29. #include <vd2/system/vdtypes.h>
  30.  
  31. class VDFraction {
  32. friend VDFraction operator*(unsigned long b, const VDFraction f);
  33. friend VDFraction operator*(int b, const VDFraction f);
  34. private:
  35.     unsigned long    hi, lo;
  36.  
  37.     static VDFraction reduce(uint64 hi, uint64 lo);
  38.  
  39. public:
  40.     VDFraction() {}
  41.     explicit VDFraction(int i) : hi(i), lo(1) {}
  42.     explicit VDFraction(unsigned long i) : hi(i), lo(1) { }
  43.     explicit VDFraction(unsigned long i, unsigned long j) : hi(i), lo(j) {}
  44.     explicit VDFraction(double d);
  45.  
  46.     bool    operator<(VDFraction b) const;
  47.     bool    operator<=(VDFraction b) const;
  48.     bool    operator>(VDFraction b) const;
  49.     bool    operator>=(VDFraction b) const;
  50.     bool    operator==(VDFraction b) const;
  51.     bool    operator!=(VDFraction b) const;
  52.  
  53.     VDFraction operator*(VDFraction b) const;
  54.     VDFraction operator/(VDFraction b) const;
  55.  
  56.     VDFraction operator*(unsigned long b) const;
  57.     VDFraction operator/(unsigned long b) const;
  58.  
  59.     VDFraction& operator*=(VDFraction b);
  60.     VDFraction& operator/=(VDFraction b);
  61.     VDFraction& operator*=(unsigned long b);
  62.     VDFraction& operator/=(unsigned long b);
  63.  
  64.     void    Assign(unsigned long n, unsigned long d) {
  65.         hi = n;
  66.         lo = d;
  67.     }
  68.  
  69.     sint64 scale64t(sint64) const;
  70.     sint64 scale64r(sint64) const;
  71.     sint64 scale64u(sint64) const;
  72.     sint64 scale64it(sint64) const;
  73.     sint64 scale64ir(sint64) const;
  74.     sint64 scale64iu(sint64) const;
  75.  
  76.     double asDouble() const;
  77.     double AsInverseDouble() const;
  78.  
  79.     unsigned long roundup32ul() const;
  80.  
  81.     unsigned long getHi() const { return hi; }
  82.     unsigned long getLo() const { return lo; }
  83.  
  84.     VDFraction reduce() const { return reduce(hi, lo); }
  85.  
  86.     bool Parse(const char *s);
  87.  
  88.     static inline VDFraction reduce64(sint64 hi, sint64 lo) { return reduce(hi, lo); }
  89. };
  90.  
  91. inline VDFraction operator*(unsigned long b, const VDFraction f) { return f*b; }
  92.  
  93. typedef VDFraction Fraction;
  94.  
  95. #endif
  96.