HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImfRational.h
Go to the documentation of this file.
1 //
2 // SPDX-License-Identifier: BSD-3-Clause
3 // Copyright (c) Contributors to the OpenEXR Project.
4 //
5 
6 #ifndef INCLUDED_IMF_RATIONAL_H
7 #define INCLUDED_IMF_RATIONAL_H
8 
9 #include "ImfExport.h"
10 #include "ImfNamespace.h"
11 
12 //-----------------------------------------------------------------------------
13 //
14 // Rational numbers
15 //
16 // A rational number is represented as pair of integers, n and d.
17 // The value of of the rational number is
18 //
19 // n/d for d > 0
20 // positive infinity for n > 0, d == 0
21 // negative infinity for n < 0, d == 0
22 // not a number (NaN) for n == 0, d == 0
23 //
24 //-----------------------------------------------------------------------------
25 
27 
28 
30 {
31  public:
32 
33  int n; // numerator
34  unsigned int d; // denominator
35 
36 
37  //----------------------------------------
38  // Default constructor, sets value to zero
39  //----------------------------------------
40 
41  Rational (): n (0), d (1) {}
42 
43 
44  //-------------------------------------
45  // Constructor, explicitly sets n and d
46  //-------------------------------------
47 
48  Rational (int n, int d): n (n), d (d) {}
49 
50 
51  //----------------------------
52  // Constructor, approximates x
53  //----------------------------
54 
56  explicit Rational (double x);
57 
58 
59  //---------------------------------
60  // Approximate conversion to double
61  //---------------------------------
62 
63  operator double () const {return double (n) / double (d);}
64 };
65 
66 
68 
69 #endif
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT
Definition: ImfNamespace.h:80
GLdouble n
Definition: glcorearb.h:2008
#define IMF_EXPORT
Definition: ImfExport.h:54
GLint GLenum GLint x
Definition: glcorearb.h:409
#define OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER
Definition: ImfNamespace.h:79
Rational(int n, int d)
Definition: ImfRational.h:48
#define IMF_EXPORT_TYPE
Definition: ImfExport.h:57
unsigned int d
Definition: ImfRational.h:34