Paradox Game Engine  v1.0.0 beta06
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros Pages
Rational.cs
Go to the documentation of this file.
1 // Copyright (c) 2014 Silicon Studio Corp. (http://siliconstudio.co.jp)
2 // This file is distributed under GPL v3. See LICENSE.md for details.
3 using System;
4 
5 namespace SiliconStudio.Paradox.Graphics
6 {
7  /// <summary>
8  /// <p>Represents a rational number.</p>
9  /// </summary>
10  /// <remarks>
11  /// <p>The <strong><see cref="SharpDX.DXGI.Rational"/></strong> structure operates under the following rules:</p><ul> <li>0/0 is legal and will be interpreted as 0/1.</li> <li>0/anything is interpreted as zero.</li> <li>If you are representing a whole number, the denominator should be 1.</li> </ul>
12  /// </remarks>
13  public partial struct Rational : IEquatable<Rational>
14  {
15  public Rational(int numerator, int denominator)
16  {
17  Numerator = numerator;
18  Denominator = denominator;
19  }
20 
21  /// <summary>
22  /// <dd> <p>An unsigned integer value representing the top of the rational number.</p> </dd>
23  /// </summary>
24  public int Numerator;
25 
26  /// <summary>
27  /// <dd> <p>An unsigned integer value representing the bottom of the rational number.</p> </dd>
28  /// </summary>
29  public int Denominator;
30 
31  public override string ToString()
32  {
33  return string.Format("{0}/{1} = {2}", Numerator, Denominator, (float)Numerator/Denominator);
34  }
35 
36  public bool Equals(Rational other)
37  {
38  return Numerator == other.Numerator && Denominator == other.Denominator;
39  }
40 
41  public override bool Equals(object obj)
42  {
43  if (ReferenceEquals(null, obj)) return false;
44  return obj is Rational && Equals((Rational) obj);
45  }
46 
47  public override int GetHashCode()
48  {
49  unchecked
50  {
51  return (Numerator*397) ^ Denominator;
52  }
53  }
54 
55  public static bool operator ==(Rational left, Rational right)
56  {
57  return left.Equals(right);
58  }
59 
60  public static bool operator !=(Rational left, Rational right)
61  {
62  return !left.Equals(right);
63  }
64  }
65 }
override bool Equals(object obj)
Definition: Rational.cs:41
Rational(int numerator, int denominator)
Definition: Rational.cs:15