ImfRational.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. //
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. // Copyright (c) Contributors to the OpenEXR Project.
  4. //
  5. #ifndef INCLUDED_IMF_RATIONAL_H
  6. #define INCLUDED_IMF_RATIONAL_H
  7. #include "ImfExport.h"
  8. #include "ImfNamespace.h"
  9. //-----------------------------------------------------------------------------
  10. //
  11. // Rational numbers
  12. //
  13. // A rational number is represented as pair of integers, n and d.
  14. // The value of of the rational number is
  15. //
  16. // n/d for d > 0
  17. // positive infinity for n > 0, d == 0
  18. // negative infinity for n < 0, d == 0
  19. // not a number (NaN) for n == 0, d == 0
  20. //
  21. //-----------------------------------------------------------------------------
  22. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
  23. class IMF_EXPORT_TYPE Rational
  24. {
  25. public:
  26. int n; // numerator
  27. unsigned int d; // denominator
  28. //----------------------------------------
  29. // Default constructor, sets value to zero
  30. //----------------------------------------
  31. Rational (): n (0), d (1) {}
  32. //-------------------------------------
  33. // Constructor, explicitly sets n and d
  34. //-------------------------------------
  35. Rational (int n, int d): n (n), d (d) {}
  36. //----------------------------
  37. // Constructor, approximates x
  38. //----------------------------
  39. IMF_EXPORT
  40. explicit Rational (double x);
  41. //---------------------------------
  42. // Approximate conversion to double
  43. //---------------------------------
  44. operator double () const {return double (n) / double (d);}
  45. };
  46. OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
  47. #endif