<commit_before>﻿// Accord Math Library
// The Accord.NET Framework
// http://accord-framework.net
//
// Copyright © <NAME>, 2009-2016
// cesarsouza at gmail.com
//
//    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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//

namespace Accord.Math
{
    using Accord.Math.Random;
    using System;
    using System.Runtime.CompilerServices;

    /// <summary>
    ///   Set of mathematical tools.
    /// </summary>
    /// 
    public static partial class Tools
    {

        /// <summary>
        ///   Gets a reference to the random number generator used
        ///   internally by the Accord.NET classes and methods.
        /// </summary>
        /// 
        [Obsolete("Please use Generator.Random instead.")]
        public static System.Random Random { get { return Generator.Random; } }

        /// <summary>
        ///   Sets a random seed for the framework's main 
        ///   <see cref="Random">internal number generator</see>.
        /// </summary>
        ///
        [Obsolete("Please set the Seed property of Accord.Math.Random.Generator instead.")]
        public static void SetupGenerator(int? seed)
        {
            Generator.Seed = seed;
        }


        /// <summary>
        ///   Gets the angle formed by the vector [x,y].
        /// </summary>
        /// 
        public static float Angle(float x, float y)
        {
            if (y >= 0)
            {
                if (x >= 0)
                    return (float)Math.Atan(y / x);
                return (float)(Math.PI - Math.Atan(-y / x));
            }
            else
            {
                if (x >= 0)
                    return (float)(2 * Math.PI - Math.Atan(-y / x));
                return (float)(Math.PI + Math.Atan(y / x));
            }
        }

        /// <summary>
        ///   Gets the angle formed by the vector [x,y].
        /// </summary>
        /// 
        public static double Angle(double x, double y)
        {
            if (y >= 0)
            {
                if (x >= 0)
                    return Math.Atan2(y, x);
                return Math.PI - Math.Atan(-y / x);
            }
            else
            {
                if (x >= 0)
                    return 2.0 * Math.PI - Math.Atan2(-y, x);
                return Math.PI + Math.Atan(y / x);
            }
        }

        /// <summary>
        ///   Gets the displacement angle between two points.
        /// </summary>
        /// 
        public static double Angle(IntPoint previous, IntPoint next)
        {
            double dx = next.X - previous.X;
            double dy = next.Y - previous.Y;

            return Accord.Math.Tools.Angle(dx, dy);
        }

        /// <summary>
        ///   Gets the displacement angle between two points, coded
        ///   as an integer varying from 0 to 20.
        /// </summary>
        /// 
        public static int Direction(IntPoint previous, IntPoint next)
        {
            double dx = next.X - previous.X;
            double dy = next.Y - previous.Y;

            double radians = Accord.Math.Tools.Angle(dx, dy);

            // code = Floor(20 / (2*System.Math.PI))
            int code = (int)System.Math.Floor(radians * 3.183098861837907);

            return code;
        }

        /// <summary>
        ///   Gets the greatest common divisor between two integers.
        /// </summary>
        /// 
        /// <param name="a">First value.</param>
        /// <param name="b">Second value.</param>
        /// 
        /// <returns>The greatest common divisor.</returns>
        /// 
        public static int GreatestCommonDivisor(int a, int b)
        {
            int x = a - b * (int)Math.Floor((double)(a / b));
            while (x != 0)
            {
                a = b;
                b = x;
                x = a - b * (int)Math.Floor((double)(a / b));
            }
            return b;
        }

        /// <summary>
        ///   Returns the next power of 2 after the input value x.
        /// </summary>
        /// 
        /// <param name="x">Input value x.</param>
        /// 
        /// <returns>Returns the next power of 2 after the input value x.</returns>
        /// 
        public static int NextPowerOf2(int x)
        {
            --x;
            x |= x >> 1;
            x |= x >> 2;
            x |= x >> 4;
            x |= x >> 8;
            x |= x >> 16;
            return ++x;<commit_msg>GH-264: Integer division instead of double in Math.Tools.<commit_after>﻿// Accord Math Library
// The Accord.NET Framework
// http://accord-framework.net
//
// Copyright © <NAME>, 2009-2016
// cesarsouza at gmail.com
//
//    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., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
//

namespace Accord.Math
{
    using Accord.Math.Random;
    using System;
    using System.Runtime.CompilerServices;

    /// <summary>
    ///   Set of mathematical tools.
    /// </summary>
    /// 
    public static partial class Tools
    {

        /// <summary>
        ///   Gets a reference to the random number generator used
        ///   internally by the Accord.NET classes and methods.
        /// </summary>
        /// 
        [Obsolete("Please use Generator.Random instead.")]
        public static System.Random Random { get { return Generator.Random; } }

        /// <summary>
        ///   Sets a random seed for the framework's main 
        ///   <see cref="Random">internal number generator</see>.
        /// </summary>
        ///
        [Obsolete("Please set the Seed property of Accord.Math.Random.Generator instead.")]
        public static void SetupGenerator(int? seed)
        {
            Generator.Seed = seed;
        }


        /// <summary>
        ///   Gets the angle formed by the vector [x,y].
        /// </summary>
        /// 
        public static float Angle(float x, float y)
        {
            if (y >= 0)
            {
                if (x >= 0)
                    return (float)Math.Atan(y / x);
                return (float)(Math.PI - Math.Atan(-y / x));
            }
            else
            {
                if (x >= 0)
                    return (float)(2 * Math.PI - Math.Atan(-y / x));
                return (float)(Math.PI + Math.Atan(y / x));
            }
        }

        /// <summary>
        ///   Gets the angle formed by the vector [x,y].
        /// </summary>
        /// 
        public static double Angle(double x, double y)
        {
            if (y >= 0)
            {
                if (x >= 0)
                    return Math.Atan2(y, x);
                return Math.PI - Math.Atan(-y / x);
            }
            else
            {
                if (x >= 0)
                    return 2.0 * Math.PI - Math.Atan2(-y, x);
                return Math.PI + Math.Atan(y / x);
            }
        }

        /// <summary>
        ///   Gets the displacement angle between two points.
        /// </summary>
        /// 
        public static double Angle(IntPoint previous, IntPoint next)
        {
            double dx = next.X - previous.X;
            double dy = next.Y - previous.Y;

            return Accord.Math.Tools.Angle(dx, dy);
        }

        /// <summary>
        ///   Gets the displacement angle between two points, coded
        ///   as an integer varying from 0 to 20.
        /// </summary>
        /// 
        public static int Direction(IntPoint previous, IntPoint next)
        {
            double dx = next.X - previous.X;
            double dy = next.Y - previous.Y;

            double radians = Accord.Math.Tools.Angle(dx, dy);

            // code = Floor(20 / (2*System.Math.PI))
            int code = (int)System.Math.Floor(radians * 3.183098861837907);

            return code;
        }

        /// <summary>
        ///   Gets the greatest common divisor between two integers.
        /// </summary>
        /// 
        /// <param name="a">First value.</param>
        /// <param name="b">Second value.</param>
        /// 
        /// <returns>The greatest common divisor.</returns>
        /// 
        public static int GreatestCommonDivisor(int a, int b)
        {
            int x = a - b * (int)Math.Floor(a / (double)b);
            while (x != 0)
            {
                a = b;
                b = x;
                x = a - b * (int)Math.Floor(a / (double)b);
            }
            return b;
        }

        /// <summary>
        ///   Returns the next power of 2 after the input value x.
        /// </summary>
        /// 
        /// <param name="x">Input value x.</param>
        /// 
        /// <returns>Returns the next power of 2 after the input value x.</returns>
        /// 
        public static int NextPowerOf2(int x)
        {
            --x;
            x |= x >> 1;
            x |= x >> 2;
            x |= x >> 4;
            x |= x >> 8;
            x |= x >> 16;
            return ++x;
{'fraction_non_alphanumeric': 0.12366323157690064, 'fraction_numerical': 0.012735757340073886, 'mean_word_length': 1.2824495229642778, 'pattern_counts': {'":': 0, '<': 65, '<?xml version=': 0, '>': 97, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7560701', 'n_tokens_mistral': 2938, 'n_tokens_neox': 2751, 'n_words': 936}