Fraction

Description

struct Tinman.Core.Math.Fraction

This struct represents a fraction with 32-bit integer numerator and denominator.

Public / Constants

One


public static readonly attribute One → (Fraction)

The fraction 1 / 1.

One​Half


public static readonly attribute OneHalf → (Fraction)

The fraction 1 / 2.

One​Percent


public static readonly attribute OnePercent → (Fraction)

The fraction 1 / 100.

One​Quarter


public static readonly attribute OneQuarter → (Fraction)

The fraction 1 / 4.

Zero


public static readonly attribute Zero → (Fraction)

The fraction 0 / 1.

Public / Constructors

Fraction

2 overloads


public constructor Fraction1 → (1)

numerator in : int32

The numerator of the fraction.

Creates a new instance of Fraction.

The denominator will be set to 1.


public constructor Fraction2 → (2)

numerator in : int32

The numerator of the fraction.

denominator in : int32

The denominator of the fraction.

Creates a new instance of Fraction.

Public / Methods

Add

2 overloads


[Pure]
public method Add1 → (1)

value in : int32

The value.

returns → Fraction

The resulting fraction.

Adds the given value to this fraction.


[Pure]
public method Add2 → (1)

fraction in : Fraction

The fraction.

returns → Fraction

The resulting fraction.

Adds the given fraction to this fraction.

Div

2 overloads


[Pure]
public method Div1 → (1)

value in : int32

The scale value.

returns → Fraction

The resulting fraction.

Divides this fraction by the given scalar value.


[Pure]
public method Div2 → (1)

fraction in : Fraction

The fraction.

returns → Fraction

The resulting fraction.

Divides this fraction by the given fraction.

Div​By​This


[Pure]
public method DivByThis → (1)

value in : int32

The value.

returns → int32

The result.

Divides the given value by this fraction.

From​D


[Pure]
public static method FromD → (1)

value in : float64

The floating point value.

returns → Fraction

The fraction value.

Returns a Fraction value that represents the given floating point value.

From​F


[Pure]
public static method FromF → (1)

value in : float32

The floating point value.

returns → Fraction

The fraction value.

Returns a Fraction value that represents the given floating point value.

From​L


[Pure]
public static method FromL → (2)

numerator in : int64

The 64-bit integer numerator.

denominator in : int64

The 64-bit integer denominator.

returns → Fraction

The resulting fraction.

Returns a Fraction value that represents the given 64-bit integer fraction.

Mul

2 overloads


[Pure]
public method Mul1 → (1)

value in : int32

The scale value.

returns → Fraction

The resulting fraction.

Multiplies this fraction with the given scalar value.


[Pure]
public method Mul2 → (1)

fraction in : Fraction

The fraction.

returns → Fraction

The resulting fraction.

Multiplies this fraction with the given fraction.

Mul​By​This


[Pure]
public method MulByThis → (1)

value in : int32

The value.

returns → int32

The result.

Multiplies the given value with this fraction.

Neg


[Pure]
public method Neg → ()

returns → Fraction

The resulting fraction.

Negates this fraction.

Percent


[Pure]
public static method Percent → (1)

percent in : int32

The percentage.

returns → Fraction

The fraction value.

Returns a fraction value that represents a numeric percentage: percent / 100.

Percent​Add


[Pure]
public static method PercentAdd → (1)

percent in : int32

The percentage to add.

returns → Fraction

The fraction value.

Returns a fraction value that adds a numeric percentage: (100 + percent) / 100.

Percent​Sub


[Pure]
public static method PercentSub → (1)

percent in : int32

The percentage to add.

returns → Fraction

The fraction value.

Returns a fraction value that subtracts a numeric percentage: (100 - percent) / 100.

Reciprocal


[Pure]
public method Reciprocal → ()

returns → Fraction

The resulting fraction.

Returns the reciprocal value of this fraction.

Sub

2 overloads


[Pure]
public method Sub1 → (1)

value in : int32

The value.

returns → Fraction

The resulting fraction.

Subtracts the given value from this fraction.


[Pure]
public method Sub2 → (1)

fraction in : Fraction

The fraction.

returns → Fraction

The resulting fraction.

Subtracts the given fraction from this fraction.

To​D


[Pure]
public method ToD → ()

returns → float64

The floating point value.

Converts this fraction into a 64-bit floating point value.

To​F


[Pure]
public method ToF → ()

returns → float32

The floating point value.

Converts this fraction into a 32-bit floating point value.

Public / Attributes

Denominator


public readonly attribute Denominator → (int32)

The denominator of the fraction.

Is​Negative


public attribute IsNegative → (get)

value : bool

true if this fraction is negative, false if not.

Is this fraction negative?

Is​One


public attribute IsOne → (get)

value : bool

true if this fraction is equal to one, false if it is not.

Does this fraction have the value 1?

Is​Zero


public attribute IsZero → (get)

value : bool

true if this fraction is equal to zero, false if it is not.

Does this fraction have the value 0?

Numerator


public readonly attribute Numerator → (int32)

The numerator of the fraction.

Serialization

Serializer


public static readonly attribute Serializer → (ITypeSerializer<Fraction>)

The serialization helper object for values of Fraction.