/src/dng_sdk/source/dng_rational.h
Line | Count | Source (jump to first uncovered line) |
1 | | /*****************************************************************************/ |
2 | | // Copyright 2006 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 | | /* $Id: //mondo/dng_sdk_1_4/dng_sdk/source/dng_rational.h#2 $ */ |
10 | | /* $DateTime: 2012/07/31 22:04:34 $ */ |
11 | | /* $Change: 840853 $ */ |
12 | | /* $Author: tknoll $ */ |
13 | | |
14 | | /** \file |
15 | | * Signed and unsigned rational data types. |
16 | | */ |
17 | | |
18 | | /*****************************************************************************/ |
19 | | |
20 | | #ifndef __dng_rational__ |
21 | | #define __dng_rational__ |
22 | | |
23 | | /*****************************************************************************/ |
24 | | |
25 | | #include "dng_types.h" |
26 | | |
27 | | /*****************************************************************************/ |
28 | | |
29 | | class dng_srational |
30 | | { |
31 | | |
32 | | public: |
33 | | |
34 | | int32 n; // Numerator |
35 | | int32 d; // Denominator |
36 | | |
37 | | public: |
38 | | |
39 | | dng_srational () |
40 | 2.90M | : n (0) |
41 | 2.90M | , d (0) |
42 | 2.90M | { |
43 | 2.90M | } |
44 | | |
45 | | dng_srational (int32 nn, int32 dd) |
46 | 8.96M | : n (nn) |
47 | 8.96M | , d (dd) |
48 | 8.96M | { |
49 | 8.96M | } |
50 | | |
51 | | void Clear () |
52 | 24.4k | { |
53 | 24.4k | n = 0; |
54 | 24.4k | d = 0; |
55 | 24.4k | } |
56 | | |
57 | | bool IsValid () const |
58 | 231k | { |
59 | 231k | return d != 0; |
60 | 231k | } |
61 | | |
62 | | bool NotValid () const |
63 | 0 | { |
64 | 0 | return !IsValid (); |
65 | 0 | } |
66 | | |
67 | | bool operator== (const dng_srational &r) const |
68 | 0 | { |
69 | 0 | return (n == r.n) && |
70 | 0 | (d == r.d); |
71 | 0 | } |
72 | | |
73 | | bool operator!= (const dng_srational &r) const |
74 | 0 | { |
75 | 0 | return !(*this == r); |
76 | 0 | } |
77 | | |
78 | | real64 As_real64 () const; |
79 | | |
80 | | void Set_real64 (real64 x, int32 dd = 0); |
81 | | |
82 | | void ReduceByFactor (int32 factor); |
83 | | |
84 | | }; |
85 | | |
86 | | /*****************************************************************************/ |
87 | | |
88 | | class dng_urational |
89 | | { |
90 | | |
91 | | public: |
92 | | |
93 | | uint32 n; // Numerator |
94 | | uint32 d; // Denominator |
95 | | |
96 | | public: |
97 | | |
98 | | dng_urational () |
99 | 17.7M | : n (0) |
100 | 17.7M | , d (0) |
101 | 17.7M | { |
102 | 17.7M | } |
103 | | |
104 | | dng_urational (uint32 nn, uint32 dd) |
105 | 6.93M | : n (nn) |
106 | 6.93M | , d (dd) |
107 | 6.93M | { |
108 | 6.93M | } |
109 | | |
110 | | void Clear () |
111 | 61.5k | { |
112 | 61.5k | n = 0; |
113 | 61.5k | d = 0; |
114 | 61.5k | } |
115 | | |
116 | | bool IsValid () const |
117 | 2.17M | { |
118 | 2.17M | return d != 0; |
119 | 2.17M | } |
120 | | |
121 | | bool NotValid () const |
122 | 511k | { |
123 | 511k | return !IsValid (); |
124 | 511k | } |
125 | | |
126 | | bool operator== (const dng_urational &r) const |
127 | 34.0k | { |
128 | 34.0k | return (n == r.n) && |
129 | 34.0k | (d == r.d); |
130 | 34.0k | } |
131 | | |
132 | | bool operator!= (const dng_urational &r) const |
133 | 34.0k | { |
134 | 34.0k | return !(*this == r); |
135 | 34.0k | } |
136 | | |
137 | | real64 As_real64 () const; |
138 | | |
139 | | void Set_real64 (real64 x, uint32 dd = 0); |
140 | | |
141 | | void ReduceByFactor (uint32 factor); |
142 | | |
143 | | }; |
144 | | |
145 | | /*****************************************************************************/ |
146 | | |
147 | | #endif |
148 | | |
149 | | /*****************************************************************************/ |