tlang-interperter-cs/tlanglib/TNumber.cs

66 lines
1.5 KiB
C#

using Newtonsoft.Json.Linq;
namespace tlang
{
public class TNumber : TObject
{
public static implicit operator double(TNumber n)
{
return n.Value;
}
public static explicit operator long(TNumber n)
{
return (long)n.Value;
}
public static explicit operator float(TNumber n)
{
return (float)n.Value;
}
public static explicit operator int(TNumber n)
{
return (int)n.Value;
}
public static explicit operator short(TNumber n)
{
return (short)n.Value;
}
public static explicit operator ushort(TNumber n)
{
return (ushort)n.Value;
}
public static explicit operator uint(TNumber n)
{
return (uint)n.Value;
}
public static explicit operator ulong(TNumber n)
{
return (ulong)n.Value;
}
public static explicit operator byte(TNumber n)
{
return (byte)n.Value;
}
public static explicit operator sbyte(TNumber n)
{
return (sbyte)n.Value;
}
public double Value {get;set;}
public override bool AsBoolean => Value != 0;
public TNumber(double number)
{
Value = number;
}
public override string ToString()
{
return Value.ToString();
}
public override JToken AsToken()
{
return new JValue(Value);
}
}
}