Home | History | Annotate | Download | only in source
      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 			:	n (0)
     41 			,	d (0)
     42 			{
     43 			}
     44 
     45 		dng_srational (int32 nn, int32 dd)
     46 			:	n (nn)
     47 			,	d (dd)
     48 			{
     49 			}
     50 
     51 		void Clear ()
     52 			{
     53 			n = 0;
     54 			d = 0;
     55 			}
     56 
     57 		bool IsValid () const
     58 			{
     59 			return d != 0;
     60 			}
     61 
     62 		bool NotValid () const
     63 			{
     64 			return !IsValid ();
     65 			}
     66 
     67 		bool operator== (const dng_srational &r) const
     68 			{
     69 			return (n == r.n) &&
     70 				   (d == r.d);
     71 			}
     72 
     73 		bool operator!= (const dng_srational &r) const
     74 			{
     75 			return !(*this == r);
     76 			}
     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 			:	n (0)
    100 			,	d (0)
    101 			{
    102 			}
    103 
    104 		dng_urational (uint32 nn, uint32 dd)
    105 			:	n (nn)
    106 			,	d (dd)
    107 			{
    108 			}
    109 
    110 		void Clear ()
    111 			{
    112 			n = 0;
    113 			d = 0;
    114 			}
    115 
    116 		bool IsValid () const
    117 			{
    118 			return d != 0;
    119 			}
    120 
    121 		bool NotValid () const
    122 			{
    123 			return !IsValid ();
    124 			}
    125 
    126 		bool operator== (const dng_urational &r) const
    127 			{
    128 			return (n == r.n) &&
    129 				   (d == r.d);
    130 			}
    131 
    132 		bool operator!= (const dng_urational &r) const
    133 			{
    134 			return !(*this == r);
    135 			}
    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 /*****************************************************************************/
    150