tlang-interperter-cs/tlanglib/TNumber.cs

66 lines
1.5 KiB
C#
Raw Normal View History

2023-06-08 18:14:35 +00:00
using Newtonsoft.Json.Linq;
2023-03-09 19:40:14 +00:00
namespace tlang
{
public class TNumber : TObject
{
2023-06-08 18:14:35 +00:00
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;
}
2023-03-09 19:40:14 +00:00
public double Value {get;set;}
2023-03-09 23:57:16 +00:00
public override bool AsBoolean => Value != 0;
2023-03-09 19:40:14 +00:00
public TNumber(double number)
{
Value = number;
}
public override string ToString()
{
return Value.ToString();
}
2023-06-08 18:14:35 +00:00
public override JToken AsToken()
{
return new JValue(Value);
}
2023-03-09 19:40:14 +00:00
}
}