<commit_before>﻿using System;
using System.Runtime.InteropServices;


namespace ManagedX.Display
{

	/// <summary>Represents a rational number (unsigned).
	/// <para>This structure is also used by DXGI.</para>
	/// </summary>
	[System.Diagnostics.DebuggerStepThrough]
	[StructLayout( LayoutKind.Sequential, Pack = 4, Size = 8 )]
	public struct Rational : IEquatable<Rational>, IComparable<Rational>
	{

		private uint numerator;
		private uint denominator;



		#region Constructors

		/// <summary>Initializes a new <see cref="Rational"/> structure.</summary>
		/// <param name="numerator">The numerator.</param>
		/// <param name="denominator">The denominator.</param>
		[CLSCompliant( false )]
		public Rational( uint numerator, uint denominator )
		{
			this.numerator = numerator;
			this.denominator = denominator;
		}


		/// <summary>Initializes a new <see cref="Rational"/> structure.</summary>
		/// <param name="numerator">The numerator; must be greater than or equal to 0.</param>
		/// <param name="denominator">The denominator; must be greater than or equal to 0.</param>
		/// <exception cref="ArgumentOutOfRangeException"/>
		public Rational( int numerator, int denominator )
		{
			if( numerator < 0 )
				throw new ArgumentOutOfRangeException( "numerator" );
			
			if( denominator < 0 )
				throw new ArgumentOutOfRangeException( "denominator" );
			
			this.numerator = (uint)numerator;
			this.denominator = (uint)denominator;
		}

		#endregion Constructors



		/// <summary>Returns a double-precision floating-point value equivalent to this <see cref="Rational"/>.</summary>
		/// <returns>Returns a double-precision floating-point value equivalent to this <see cref="Rational"/>.</returns>
		public double ToDouble()
		{
			if( denominator == 0u )
				return 1.0;
			// this follows the "rule" defined in DXGI.
			
			return (double)numerator / (double)denominator;
		}


		/// <summary>Returns a single-precision floating-point value equivalent to this <see cref="Rational"/>.</summary>
		/// <returns>Returns a single-precision floating-point value equivalent to this <see cref="Rational"/>.</returns>
		public float ToSingle()
		{
			if( denominator == 0u )
				return 1.0f;
			// this follows the "rule" defined in DXGI.

			return (float)numerator / (float)denominator;
		}


		/// <summary>Returns a hash code for this <see cref="Rational"/>.</summary>
		/// <returns>Returns a hash code for this <see cref="Rational"/>.</returns>
		public override int GetHashCode()
		{
			return ( numerator ^ denominator ).GetHashCode();
		}


		/// <summary>Returns a value indicating whether this <see cref="Rational"/> equals another <see cref="Rational"/>.</summary>
		/// <param name="other">A <see cref="Rational"/>.</param>
		/// <returns>Returns true if the rationals are equal, otherwise returns false.</returns>
		public bool Equals( Rational other )
		{
			return
				( numerator == other.numerator ) &&
				( denominator == other.denominator );
		}


		/// <summary>Returns a value indicating whether this <see cref="Rational"/> is equivalent to an object.</summary>
		/// <param name="obj">An object.</param>
		/// <returns>Returns true if the specified object is a <see cref="Rational"/> which equals this <see cref="Rational"/>, otherwise returns false.</returns>
		public override bool Equals( object obj )
		{
			return ( obj is Rational ) && this.Equals( (Rational)obj );
		}


		/// <summary>Returns a value indicating whether this <see cref="Rational"/> is equal to, greater or smaller than another <see cref="Rational"/>.</summary>
		/// <param name="other">A <see cref="Rational"/>.</param>
		/// <returns>Returns -1 if this structure is smaller than the <paramref name="other"/> <see cref="Rational"/>, +1 if it's greater, or 0 if they are equal.</returns>
		public int CompareTo( Rational other )
		{
			return this.ToDouble().CompareTo( other.ToDouble() );
		}


		/// <summary>Returns a string representing this <see cref="Rational"/>, in the form "numerator:denominator".</summary>
		/// <returns>Returns a string representing this <see cref="Rational"/>.</returns>
		public override string ToString()
		{
			return numerator.ToString( System.Globalization.CultureInfo.InvariantCulture ) + ':' + denominator.ToString( System.Globalization.CultureInfo.InvariantCulture );
		}


		
		/// <summary>The empty <see cref="Rational"/>.
		/// <para>While "Zero" would be a better name, it might be confusing to have it convert into 1 (due to the DXGI rule).</para><commit_msg>Better comparison methods (Equals, CompareTo).<commit_after>﻿using System;
using System.Runtime.InteropServices;


namespace ManagedX.Display
{

	/// <summary>Represents a rational number (unsigned).
	/// <para>This structure is also used by DXGI.</para>
	/// </summary>
	[System.Diagnostics.DebuggerStepThrough]
	[StructLayout( LayoutKind.Sequential, Pack = 4, Size = 8 )]
	public struct Rational : IEquatable<Rational>, IComparable<Rational>
	{

		private uint numerator;
		private uint denominator;



		#region Constructors

		/// <summary>Initializes a new <see cref="Rational"/> structure.</summary>
		/// <param name="numerator">The numerator.</param>
		/// <param name="denominator">The denominator.</param>
		[CLSCompliant( false )]
		public Rational( uint numerator, uint denominator )
		{
			this.numerator = numerator;
			this.denominator = denominator;
		}


		/// <summary>Initializes a new <see cref="Rational"/> structure.</summary>
		/// <param name="numerator">The numerator; must be greater than or equal to 0.</param>
		/// <param name="denominator">The denominator; must be greater than or equal to 0.</param>
		/// <exception cref="ArgumentOutOfRangeException"/>
		public Rational( int numerator, int denominator )
		{
			if( numerator < 0 )
				throw new ArgumentOutOfRangeException( "numerator" );
			
			if( denominator < 0 )
				throw new ArgumentOutOfRangeException( "denominator" );
			
			this.numerator = (uint)numerator;
			this.denominator = (uint)denominator;
		}

		#endregion Constructors



		/// <summary>Returns a double-precision floating-point value equivalent to this <see cref="Rational"/>.</summary>
		/// <returns>Returns a double-precision floating-point value equivalent to this <see cref="Rational"/>.</returns>
		public double ToDouble()
		{
			if( denominator == 0u )
				return 1.0;
			// this follows the "rule" defined in DXGI.
			
			return (double)numerator / (double)denominator;
		}


		/// <summary>Returns a single-precision floating-point value equivalent to this <see cref="Rational"/>.</summary>
		/// <returns>Returns a single-precision floating-point value equivalent to this <see cref="Rational"/>.</returns>
		public float ToSingle()
		{
			if( denominator == 0u )
				return 1.0f;
			// this follows the "rule" defined in DXGI.

			return (float)numerator / (float)denominator;
		}


		/// <summary>Returns a hash code for this <see cref="Rational"/>.</summary>
		/// <returns>Returns a hash code for this <see cref="Rational"/>.</returns>
		public override int GetHashCode()
		{
			return ( numerator ^ denominator ).GetHashCode();
		}


		/// <summary>Returns a value indicating whether this <see cref="Rational"/> equals another <see cref="Rational"/>.</summary>
		/// <param name="other">A <see cref="Rational"/>.</param>
		/// <returns>Returns true if the rationals are equal, otherwise returns false.</returns>
		public bool Equals( Rational other )
		{
			return ( numerator * other.denominator == other.numerator * denominator );
		}


		/// <summary>Returns a value indicating whether this <see cref="Rational"/> is equivalent to an object.</summary>
		/// <param name="obj">An object.</param>
		/// <returns>Returns true if the specified object is a <see cref="Rational"/> which equals this <see cref="Rational"/>, otherwise returns false.</returns>
		public override bool Equals( object obj )
		{
			return ( obj is Rational ) && this.Equals( (Rational)obj );
		}


		/// <summary>Returns a value indicating whether this <see cref="Rational"/> is equal to, greater or smaller than another <see cref="Rational"/>.</summary>
		/// <param name="other">A <see cref="Rational"/>.</param>
		/// <returns>Returns -1 if this structure is smaller than the <paramref name="other"/> <see cref="Rational"/>, +1 if it's greater, or 0 if they are equal.</returns>
		public int CompareTo( Rational other )
		{
			var n1 = numerator * other.denominator;
			var n2 = other.numerator * denominator;
			return n1.CompareTo( n2 );
		}


		/// <summary>Returns a string representing this <see cref="Rational"/>, in the form "numerator:denominator".</summary>
		/// <returns>Returns a string representing this <see cref="Rational"/>.</returns>
		public override string ToString()
		{
			return numerator.ToString( System.Globalization.CultureInfo.InvariantCulture ) + ':' + denominator.ToString( System.Globalization.CultureInfo.InvariantCulture );
		}


		
		/// <summary>The empty <see cref="Rational"/>.
		/// <para>While "Zero" would be a better name, it might be confusing to have it convert into 1 (due to the DXGI rule).</para>
{'fraction_non_alphanumeric': 0.13956043956043956, 'fraction_numerical': 0.003956043956043956, 'mean_word_length': 3.75, 'pattern_counts': {'":': 0, '<': 163, '<?xml version=': 0, '>': 159, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7431339', 'n_tokens_mistral': 2938, 'n_tokens_neox': 2588, 'n_words': 825}