/// <summary> /// Average value operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:avg operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence avg(java.util.Collection args) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence avg(ICollection args) { var j = args.GetEnumerator(); j.MoveNext(); ResultSequence arg = (ResultSequence)j.Current; if (arg == null || arg.empty()) { return(ResultSequenceFactory.create_new()); } int elems = 0; MathPlus total = null; TypePromoter tp = new ScalarTypePromoter(); tp.considerSequence(arg); for (var i = arg.iterator(); i.MoveNext();) { ++elems; AnyAtomicType conv = tp.promote((AnyType)i.Current); if (conv != null) { if (conv is XSDouble && ((XSDouble)conv).nan() || conv is XSFloat && ((XSFloat)conv).nan()) { return(ResultSequenceFactory.create_new(tp.promote(new XSFloat(float.NaN)))); } if (total == null) { total = (MathPlus)conv; } else { total = (MathPlus)total.plus(ResultSequenceFactory.create_new(conv)).first(); } } } if (!(total is MathDiv)) { DynamicError.throw_type_error(); } return(((MathDiv)total).div(ResultSequenceFactory.create_new(new XSInteger(new System.Numerics.BigInteger(elems))))); }
/// <summary> /// Sum operation. /// </summary> /// <param name="args"> /// Result from the expressions evaluation. </param> /// <exception cref="DynamicError"> /// Dynamic error. </exception> /// <returns> Result of fn:sum operation. </returns> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public static org.eclipse.wst.xml.xpath2.api.ResultSequence sum(org.eclipse.wst.xml.xpath2.api.ResultSequence arg, org.eclipse.wst.xml.xpath2.processor.internal.types.AnyAtomicType zero) throws org.eclipse.wst.xml.xpath2.processor.DynamicError public static ResultSequence sum(ResultSequence arg, AnyAtomicType zero) { if (arg.empty()) { return(ResultSequenceFactory.create_new(zero)); } MathPlus total = null; TypePromoter tp = new ScalarTypePromoter(); tp.considerSequence(arg); for (var i = arg.iterator(); i.MoveNext();) { AnyAtomicType conv = tp.promote((AnyType)i.Current); if (conv == null) { conv = zero; } if (conv is XSDouble && ((XSDouble)conv).nan() || conv is XSFloat && ((XSFloat)conv).nan()) { return(ResultSequenceFactory.create_new(tp.promote(new XSFloat(float.NaN)))); } if (total == null) { total = (MathPlus)conv; } else { total = (MathPlus)total.plus(ResultSequenceFactory.create_new(conv)).first(); } } return(ResultSequenceFactory.create_new((AnyType)total)); }