Gets the median from the list

   
 

/*
Copyright (c) 2010 <a href="http://www.gutgames.com">James Craig</a>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/


namespace Utilities.Math
{
    /// <summary>
    /// Various math related functions
    /// </summary>
    public static class MathHelper
    {

        /// <summary>
        /// Gets the median from the list
        /// </summary>
        /// <typeparam name="T">The data type of the list</typeparam>
        /// <param name="Values">The list of values</param>
        /// <returns>The median value</returns>
        public static T Median<T>(System.Collections.Generic.List<T> Values)
        {
            if (Values.Count == 0)
                return default(T);
            Values.Sort();
            return Values[(Values.Count / 2)];
        }
   }
}

   
     


Gets the mean value from a list

/*
Copyright (c) 2010 James Craig

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the “Software”), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.*/

namespace Utilities.Math
{
///

/// Various math related functions
///

public static class MathHelper
{

///

/// Gets the mean value from a list
///

/// The list of values /// The mean/average of the list
public static double Mean(System.Collections.Generic.List Values)
{
if (Values.Count == 0)
return 0.0;
double ReturnValue = 0.0;
for (int x = 0; x < Values.Count; ++x) { ReturnValue += Values[x]; } return ReturnValue / (double)Values.Count; } ///

/// Gets the mean value from a list
///

/// The list of values /// The mean/average of the list
public static double Mean(System.Collections.Generic.List Values)
{
if (Values.Count == 0)
return 0.0;
double ReturnValue = 0.0;
for (int x = 0; x < Values.Count; ++x) { ReturnValue += Values[x]; } return ReturnValue / (double)Values.Count; } } } [/csharp]

Converts degrees to radians.

   
 
/*
 *  Copyright (C) 2002 Urban Science Applications, Inc. 
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


#region Using
using System;
#endregion

namespace Geotools.Utilities
{
  /// <summary>
  /// Converts degrees to radians.
  /// </summary>
  public class Degrees
  {
    /// <summary>
    /// Converts degrees to radians.
    /// </summary>
    /// <param name="degrees">The angle in degrees.</param>
    /// <returns>The angle in radians.</returns>
    public static double ToRadians(double degrees)
    {
      return degrees * 0.0174532925199432958;
    }
  }
}

   
     


Converts a radians angle into a degrees angle.

   
 

    public static class MathUtility
    {
        //-------------------------------------------------------------------------------------
        /// <summary>
        /// Converts a radians angle into a degrees angle.
        /// </summary>
        /// <param name="angle">Angle to convert.</param>
        /// <returns>Angle in degrees.</returns>
        //-------------------------------------------------------------------------------------

        public static float RadiansToDegrees(float angle)
        {
            return angle * (180.0f / (float) System.Math.PI);
        }
    }

   
     


Converts a degrees angle into a radians angle.

   
 

    public static class MathUtility
    {

        //-------------------------------------------------------------------------------------
        /// <summary>
        /// Converts a degrees angle into a radians angle.
        /// </summary>
        /// <param name="angle">Angle to convert.</param>
        /// <returns>Angle in radians.</returns>
        //-------------------------------------------------------------------------------------

        public static float DegreesToRadians(float angle)
        {
            return angle * ((float) System.Math.PI / 180.0f);
        }

     }

   
     


Math.Abs

   
  
using System;

public class MainClass {
    public static void Main() {

        Console.WriteLine("Math.Abs(5) = {0}", Math.Abs(5));
        Console.WriteLine("Math.Abs(-5) = {0}", Math.Abs(-5));
        Console.WriteLine("Math.Abs(0) = {0}", Math.Abs(0));
    }
}