示例#1
0
 /// <summary>Computes the min of a sequence of <typeparamref name="TQuantity" /> values.</summary>
 /// <param name="source">A sequence of <typeparamref name="TQuantity" /> values to calculate the min of.</param>
 /// <param name="unitType">The desired unit type for the resulting quantity</param>
 /// <returns>The min of the values in the sequence, represented in the specified unit type.</returns>
 /// <exception cref="T:System.ArgumentNullException">
 ///     <paramref name="source">source</paramref> is null.
 /// </exception>
 /// <exception cref="T:System.InvalidOperationException"><paramref name="source">source</paramref> contains no elements.</exception>
 /// <exception cref="ArgumentException">
 ///     <paramref name="source">source</paramref> contains quantity types different from <paramref name="unitType" />.
 /// </exception>
 public static TQuantity Min <TQuantity>(this IEnumerable <TQuantity> source, Enum unitType)
     where TQuantity : IQuantity
 {
     return((TQuantity)Quantity.From(source.Min(x => x.As(unitType)), unitType));
 }
示例#2
0
 /// <summary>Returns the absolute value of a <typeparamref name="TQuantity" />.</summary>
 /// <param name="value">
 ///     A quantity with a value that is greater than or equal to <see cref="F:System.Double.MinValue" />,
 ///     but less than or equal to <see cref="F:System.Double.MaxValue" />.
 /// </param>
 /// <returns>A quantity with a value, such that 0 ≤ value ≤ <see cref="F:System.Double.MaxValue" />.</returns>
 public static TQuantity Abs <TQuantity>(this TQuantity value) where TQuantity : IQuantity
 {
     return(value.Value >= 0 ? value : (TQuantity)Quantity.From(-value.Value, value.Unit));
 }