CSharp examples for System:Math Number
Gets the positive modulo of a double
// Copyright (c) Microsoft. All rights reserved. public class Main{ /// <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) {//w w w. j a v a 2 s . com 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; } }