Number
Represents a float value.
using System;
namespace AngleSharp.Css.Values
{
public struct Number : IEquatable<Number>, IComparable<Number>, IFormattable
{
public enum Unit : ushort
{
Integer,
Float
}
public static readonly Number Zero = default(Number);
public static readonly Number Infinite = new Number(Infinity, Unit.Float);
public static readonly Number One = new Number(1, Unit.Integer);
private readonly float _value;
private readonly Unit _unit;
public float Value => _value;
public bool IsInteger => _unit == Unit.Integer;
public Number(float value, Unit unit)
{
_value = value;
_unit = unit;
}
public static bool operator ==(Number a, Number b)
{
return a._value == b._value;
}
public static bool operator !=(Number a, Number b)
{
return a._value != b._value;
}
public static bool operator >=(Number a, Number b)
{
return a._value >= b._value;
}
public static bool operator >(Number a, Number b)
{
return a._value > b._value;
}
public static bool operator <=(Number a, Number b)
{
return a._value <= b._value;
}
public static bool operator <(Number a, Number b)
{
return a._value < b._value;
}
public static explicit operator float(Number number)
{
return number._value;
}
public static explicit operator int(Number number)
{
return (int)number._value;
}
public bool Equals(Number other)
{
if (_value == other._value)
return _unit == other._unit;
return false;
}
public int CompareTo(Number other)
{
return _value.CompareTo(other._value);
}
public override bool Equals(object obj)
{
if (obj is Number)
return Equals((Number)obj);
return false;
}
public override int GetHashCode()
{
return _value.GetHashCode();
}
public override string ToString()
{
return _value.ToString();
}
public string ToString(string format, IFormatProvider formatProvider)
{
return _value.ToString(format, formatProvider);
}
}
}