1 /*****************************************************************************/
2 // Copyright 2006-2019 Adobe Systems Incorporated
3 // All Rights Reserved.
4 //
5 // NOTICE:  Adobe permits you to use, modify, and distribute this file in
6 // accordance with the terms of the Adobe license agreement accompanying it.
7 /*****************************************************************************/
8 
9 /** \file
10  * Signed and unsigned rational data types.
11  */
12 
13 /*****************************************************************************/
14 
15 #ifndef __dng_rational__
16 #define __dng_rational__
17 
18 /*****************************************************************************/
19 
20 #include "dng_types.h"
21 
22 /*****************************************************************************/
23 
24 class dng_srational
25 	{
26 
27 	public:
28 
29 		int32 n;		// Numerator
30 		int32 d;		// Denominator
31 
32 	public:
33 
dng_srational()34 		dng_srational ()
35 			:	n (0)
36 			,	d (0)
37 			{
38 			}
39 
dng_srational(int32 nn,int32 dd)40 		dng_srational (int32 nn, int32 dd)
41 			:	n (nn)
42 			,	d (dd)
43 			{
44 			}
45 
Clear()46 		void Clear ()
47 			{
48 			n = 0;
49 			d = 0;
50 			}
51 
IsValid()52 		bool IsValid () const
53 			{
54 			return d != 0;
55 			}
56 
NotValid()57 		bool NotValid () const
58 			{
59 			return !IsValid ();
60 			}
61 
62 		bool operator== (const dng_srational &r) const
63 			{
64 			return (n == r.n) &&
65 				   (d == r.d);
66 			}
67 
68 		bool operator!= (const dng_srational &r) const
69 			{
70 			return !(*this == r);
71 			}
72 
73 		real64 As_real64 () const;
74 
75 		void Set_real64 (real64 x, int32 dd = 0);
76 
77 		void ReduceByFactor (int32 factor);
78 
79 	};
80 
81 /*****************************************************************************/
82 
83 class dng_urational
84 	{
85 
86 	public:
87 
88 		uint32 n;		// Numerator
89 		uint32 d;		// Denominator
90 
91 	public:
92 
dng_urational()93 		dng_urational ()
94 			:	n (0)
95 			,	d (0)
96 			{
97 			}
98 
dng_urational(uint32 nn,uint32 dd)99 		dng_urational (uint32 nn, uint32 dd)
100 			:	n (nn)
101 			,	d (dd)
102 			{
103 			}
104 
Clear()105 		void Clear ()
106 			{
107 			n = 0;
108 			d = 0;
109 			}
110 
IsValid()111 		bool IsValid () const
112 			{
113 			return d != 0;
114 			}
115 
NotValid()116 		bool NotValid () const
117 			{
118 			return !IsValid ();
119 			}
120 
121 		bool operator== (const dng_urational &r) const
122 			{
123 			return (n == r.n) &&
124 				   (d == r.d);
125 			}
126 
127 		bool operator!= (const dng_urational &r) const
128 			{
129 			return !(*this == r);
130 			}
131 
132 		real64 As_real64 () const;
133 
134 		void Set_real64 (real64 x, uint32 dd = 0);
135 
136 		void ReduceByFactor (uint32 factor);
137 
138 	};
139 
140 /*****************************************************************************/
141 
142 #endif
143 
144 /*****************************************************************************/
145