public static SObject IsFinite(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters) { if (parameters.Length == 0) { return(processor.Undefined); } var parameterAsNumber = parameters[0] as SNumber; var dbl = parameterAsNumber?.Value ?? parameters[0].ToNumber(processor).Value; return(processor.CreateBool(!(double.IsNaN(dbl) || double.IsInfinity(dbl)))); }
public static SObject ToPrimitive(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters) { if (parameters.Length == 0) { return(processor.Undefined); } if (parameters[0] is SString) { return(processor.CreateString(((SString)parameters[0]).Value)); } if (parameters[0] is SNumber) { return(processor.CreateNumber(((SNumber)parameters[0]).Value)); } if (parameters[0] is SBool) { return(processor.CreateBool(((SBool)parameters[0]).Value)); } return(parameters[0]); // returns the input object, if no conversion was conducted. }
public static SObject IsNaN(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters) { if (parameters.Length == 0) { return(processor.Undefined); } double dbl; if (parameters[0] is SNumber) { dbl = ((SNumber)parameters[0]).Value; } else { dbl = parameters[0].ToNumber(processor).Value; } return(processor.CreateBool(double.IsNaN(dbl))); }