/// <summary> /// Converts an object to float /// </summary> /// <param name="obj">The object to be converted</param> /// <returns>The object converted</returns> /// <exception cref="ArgumentNullException">If <paramref name="obj"/> is null</exception> /// <exception cref="InterpreterException">If <paramref name="obj"/> can't be converted to float</exception> public static KFloat ToFloat(KObject obj) { if (obj == null) { throw new ArgumentNullException(nameof(obj)); } KNumber number = obj as KNumber; if (number != null) { return(new KFloat(number.ToFloat())); } KString str = obj as KString; if (str != null) { float res; if (float.TryParse(str, out res)) { return(new KFloat(res)); } } ThrowHelper.TypeError($"Can't convert {obj.GetType().Name} to float"); return(null); }
public int CompareTo(object obj) { KString ch = obj as KString; if (ch != null) { return(string.Compare(Value, ch.Value, StringComparison.Ordinal)); } ThrowHelper.TypeError("Object is not of type string"); return(0); }
private bool Equals(KString other) { return(Value == other.Value); }