Gets modulo of value - 1 - CSharp System

CSharp examples for System:Math Number

Description

Gets modulo of value - 1

Demo Code

// Copyright (c) Microsoft. All rights reserved.

public class Main{
        /// <summary>
        /// Gets modulo of value - 1
        /// </summary>
        /// <param name="value">Value to use</param>
        /// <param name="module">Module to use</param>
        /// <returns>Modulo of value - 1</returns>
        public static int DecMod(this int value, int module)
        {/*  w w  w . jav  a2 s . c  om*/
            return (value - 1).Mod(module);
        }
        /// <summary>
        /// Gets the positive modulo of a double
        /// </summary>
        /// <param name="value">Value to use</param>
        /// <param name="module">Module to use</param>
        /// <returns>Positive modulo</returns>
        public static double Mod(this double value, double module)
        {
            double res = value % module;
            return res >= 0 ? res : (res + module) % module;
        }
        /// <summary>
        /// Gets the positive modulo of an integer
        /// </summary>
        /// <param name="value">Value to use</param>
        /// <param name="module">Module to use</param>
        /// <returns>Positive modulo</returns>
        public static int Mod(this int value, int module)
        {
            int result = value % module;
            return result >= 0 ? result : (result + module) % module;
        }
}

Related Tutorials