Show / Hide Table of Contents

Struct Fraction

Represents a small fraction. The numerator can range from -16 to 15, and the denominator can range from 1 to 8

Implements
IEquatable<Fraction>
IFormattable
Inherited Members
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
Namespace: SpiceSharp.Simulations.Variables
Assembly: SpiceSharp.dll
Syntax
public struct Fraction : IEquatable<Fraction>, IFormattable

Constructors

Fraction(int, int)

Initializes a new instance of the Fraction struct.

Declaration
public Fraction(int numerator, int denominator)
Parameters
Type Name Description
int numerator

The numerator.

int denominator

The denominator.

Exceptions
Type Condition
DivideByZeroException

Thrown if the denominator is zero.

ArgumentException

Thrown if the numerator is not in the range -16 to +15, or if the denominator is not in the range 1 to 8.

Fraction(sbyte)

Initializes a new instance of the Fraction struct.

Declaration
public Fraction(sbyte code)
Parameters
Type Name Description
sbyte code

The code.

Fields

One

One in a byte.

Declaration
public const sbyte One = 8
Field Value
Type Description
sbyte

Properties

Denominator

Gets the denominator.

Declaration
public readonly sbyte Denominator { get; }
Property Value
Type Description
sbyte

The denominator.

Remarks

The denominator can have a value ranging from 1 to 8.

Numerator

Gets the numerator.

Declaration
public readonly sbyte Numerator { get; }
Property Value
Type Description
sbyte

The numerator.

Remarks

The numerator can have a value ranging from -16 to +15.

Methods

Equals(Fraction)

Indicates whether the current object is equal to another object of the same type.

Declaration
public readonly bool Equals(Fraction other)
Parameters
Type Name Description
Fraction other

An object to compare with this object.

Returns
Type Description
bool

true if the current object is equal to the other parameter; otherwise, false.

Equals(object)

Determines whether the specified object, is equal to this instance.

Declaration
public override readonly bool Equals(object obj)
Parameters
Type Name Description
object obj

The object to compare with this instance.

Returns
Type Description
bool

true if the specified object is equal to this instance; otherwise, false.

Overrides
ValueType.Equals(object)

GetHashCode()

Returns a hash code for this instance.

Declaration
public override readonly int GetHashCode()
Returns
Type Description
int

A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

Overrides
ValueType.GetHashCode()

ToString()

Converts to string.

Declaration
public override readonly string ToString()
Returns
Type Description
string

A string that represents this instance.

Overrides
ValueType.ToString()

ToString(string, IFormatProvider)

Converts to string.

Declaration
public readonly string ToString(string format, IFormatProvider formatProvider)
Parameters
Type Name Description
string format

The format.

IFormatProvider formatProvider

The format provider.

Returns
Type Description
string

A string that represents this instance.

Operators

operator +(Fraction, Fraction)

Implements the operator +.

Declaration
public static Fraction operator +(Fraction left, Fraction right)
Parameters
Type Name Description
Fraction left

The left argument.

Fraction right

The right argument.

Returns
Type Description
Fraction

The result of the operator.

operator /(Fraction, Fraction)

Implements the operator /.

Declaration
public static Fraction operator /(Fraction left, Fraction right)
Parameters
Type Name Description
Fraction left

The left.

Fraction right

The right.

Returns
Type Description
Fraction

The result of the operator.

operator ==(Fraction, Fraction)

Implements the operator ==.

Declaration
public static bool operator ==(Fraction left, Fraction right)
Parameters
Type Name Description
Fraction left

The left argument.

Fraction right

The right argument.

Returns
Type Description
bool

The result of the operator.

explicit operator sbyte(Fraction)

Performs an implicit conversion from Fraction to sbyte.

Declaration
public static explicit operator sbyte(Fraction fraction)
Parameters
Type Name Description
Fraction fraction

The fraction.

Returns
Type Description
sbyte

The result of the conversion.

implicit operator Fraction(int)

Performs an implicit conversion from int to Fraction. The denominator is 1.

Declaration
public static implicit operator Fraction(int numerator)
Parameters
Type Name Description
int numerator

The numerator.

Returns
Type Description
Fraction

The result of the conversion.

operator !=(Fraction, Fraction)

Implements the operator !=.

Declaration
public static bool operator !=(Fraction left, Fraction right)
Parameters
Type Name Description
Fraction left

The left argument.

Fraction right

The right argument.

Returns
Type Description
bool

The result of the operator.

operator *(Fraction, Fraction)

Implements the operator *.

Declaration
public static Fraction operator *(Fraction left, Fraction right)
Parameters
Type Name Description
Fraction left

The left.

Fraction right

The right.

Returns
Type Description
Fraction

The result of the operator.

operator -(Fraction, Fraction)

Implements the operator -.

Declaration
public static Fraction operator -(Fraction left, Fraction right)
Parameters
Type Name Description
Fraction left

The left argument.

Fraction right

The right argument.

Returns
Type Description
Fraction

The result of the operator.

Implements

IEquatable<T>
IFormattable

Extension Methods

Utility.ThrowIfNull<T>(T, string)
In this article
Back to top Generated by DocFX