Struct DoubleRange
Represents an inclusive minimum/maximum range of double-precision floating-point values. Useful for designer-authored data where float precision is insufficient, such as idle/clicker game economies that grow to large magnitudes, scientific simulations, or stat systems that benefit from high-precision arithmetic.
Implements
Inherited Members
Namespace: Scylla.Core.Util.Ranges
Assembly: ScyllaCore.dll
Syntax
[Serializable]
public struct DoubleRange : IEquatable<DoubleRange>
Remarks
DoubleRange is a value type (struct) and is fully serializable
by Unity's Inspector via [Serializable] and [SerializeField]. It can
be used as a Unity Inspector field directly, and a custom UI Toolkit drawer renders
a min/max two-field row by default.
The range is inclusive on both ends. Unlike FloatRange, this type
does not provide a parameterless Random() method because
UnityEngine.Random has no built-in double overload. Use
Random(Random) with a supplied Random
instance, or sample externally and use Lerp(double) to map a
normalized factor to the range.
Equality uses approximate floating-point comparison via Approximately(double, double, double).
Constructors
DoubleRange(double, double)
Initializes a new DoubleRange with the supplied min
and max bounds. Non-finite values (NaN, infinity) are rejected.
Declaration
public DoubleRange(double min, double max)
Parameters
| Type | Name | Description |
|---|---|---|
| double | min | The lower bound (inclusive). |
| double | max | The upper bound (inclusive). |
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | Thrown when either argument is NaN or infinite. |
Fields
Zero
A DoubleRange with both Min and Max
set to 0.0. Useful as a sentinel value or default empty range.
Declaration
public static readonly DoubleRange Zero
Field Value
| Type | Description |
|---|---|
| DoubleRange |
ZeroToOne
A DoubleRange spanning 0.0 to 1.0, inclusive. Common
for normalized parameters such as probabilities and weights computed in
double-precision arithmetic.
Declaration
public static readonly DoubleRange ZeroToOne
Field Value
| Type | Description |
|---|---|
| DoubleRange |
Properties
IsEmpty
Returns true when Min equals Max using
Approximately(double, double, double).
Declaration
public bool IsEmpty { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsValid
Declaration
public bool IsValid { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Max
The upper bound of this range (inclusive).
Declaration
public double Max { get; }
Property Value
| Type | Description |
|---|---|
| double |
Min
The lower bound of this range (inclusive).
Declaration
public double Min { get; }
Property Value
| Type | Description |
|---|---|
| double |
Size
The size of the range, equal to Max minus Min. May be negative when the range is invalid (Min > Max).
Declaration
public double Size { get; }
Property Value
| Type | Description |
|---|---|
| double |
Methods
Clamp(double)
Clamps value to the inclusive bounds of this range.
Declaration
public double Clamp(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value to clamp. |
Returns
| Type | Description |
|---|---|
| double | The clamped value. |
Contains(double)
Returns true when value is within the inclusive bounds
of this range.
Declaration
public bool Contains(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value to test. |
Returns
| Type | Description |
|---|---|
| bool |
|
Equals(DoubleRange)
Determines whether two DoubleRange values are approximately equal by comparing both Min and Max via Approximately(double, double, double).
Declaration
public bool Equals(DoubleRange other)
Parameters
| Type | Name | Description |
|---|---|---|
| DoubleRange | other | The other range to compare with. |
Returns
| Type | Description |
|---|---|
| bool |
|
Equals(object)
Determines whether the specified object is a DoubleRange approximately equal to this instance.
Declaration
public override bool Equals(object obj)
Parameters
| Type | Name | Description |
|---|---|---|
| object | obj | The object to compare with. |
Returns
| Type | Description |
|---|---|
| bool |
|
Overrides
GetHashCode()
Declaration
public override int GetHashCode()
Returns
| Type | Description |
|---|---|
| int | A 32-bit signed integer hash code. |
Overrides
InverseLerp(double)
Computes the normalized position of value within the range,
mapping Min to 0 and Max to 1. Returns
0 when the range is empty.
Declaration
public double InverseLerp(double value)
Parameters
| Type | Name | Description |
|---|---|---|
| double | value | The value to project onto the normalized [0, 1] interval. |
Returns
| Type | Description |
|---|---|
| double | The normalized position, clamped to [0, 1]. |
Lerp(double)
Linearly interpolates between Min and Max using
t as the interpolation factor, clamped to [0, 1] before
interpolation.
Declaration
public double Lerp(double t)
Parameters
| Type | Name | Description |
|---|---|---|
| double | t | The interpolation factor; clamped to [0, 1]. |
Returns
| Type | Description |
|---|---|
| double | The interpolated value. |
Random(Random)
Returns a uniformly distributed random value drawn from this range, inclusive on both ends. Uses the supplied Random source for determinism; pass a seeded instance to produce reproducible sequences.
Declaration
public double Random(Random rng)
Parameters
| Type | Name | Description |
|---|---|---|
| Random | rng | The random source. Must not be |
Returns
| Type | Description |
|---|---|
| double | A random |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when |
ToString()
Returns a human-readable string representation of this range using the invariant culture for number formatting.
Declaration
public override string ToString()
Returns
| Type | Description |
|---|---|
| string | A string in the format |
Overrides
Operators
operator ==(DoubleRange, DoubleRange)
Returns true when both operands are approximately equal.
Declaration
public static bool operator ==(DoubleRange left, DoubleRange right)
Parameters
| Type | Name | Description |
|---|---|---|
| DoubleRange | left | The left-hand operand. |
| DoubleRange | right | The right-hand operand. |
Returns
| Type | Description |
|---|---|
| bool |
|
operator !=(DoubleRange, DoubleRange)
Returns true when the operands differ in either bound.
Declaration
public static bool operator !=(DoubleRange left, DoubleRange right)
Parameters
| Type | Name | Description |
|---|---|---|
| DoubleRange | left | The left-hand operand. |
| DoubleRange | right | The right-hand operand. |
Returns
| Type | Description |
|---|---|
| bool |
|