private void ExecToNum(Instruction i) { double?v = m_ValueStack.Pop().ToScalar().CastToNumber(); if (v.HasValue) { m_ValueStack.Push(DynValue.NewNumber(v.Value)); } else { throw ScriptRuntimeException.ConvertToNumberFailed(i.NumVal); } }
public static object NumberToByte(DynValue v) { double?n = v.CastToNumber(); if (!n.HasValue) { throw ScriptRuntimeException.ConvertToNumberFailed(0); } if (n.Value < 0 || n.Value > 255) { throw new ScriptRuntimeException(string.Format("number is out of range (0-255)")); } return((byte)n.Value); }