System.Math.Abs(sbyte)

Here are the examples of the csharp api System.Math.Abs(sbyte) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

16 Examples 7

19 Source : SecureRandom.cs
with MIT License
from Aiko-IT-Systems

public sbyte GetInt8(sbyte min = 0, sbyte max = sbyte.MaxValue)
        {
            if (max <= min)
                throw new ArgumentException("Maximum needs to be greater than minimum.", nameof(max));

            var offset = (sbyte)(min < 0 ? -min : 0);
            min += offset;
            max += offset;

            return (sbyte)(Math.Abs(this.Generate<sbyte>()) % (max - min) + min - offset);
        }

19 Source : SByteExtensions.cs
with MIT License
from dotnet-toolbelt

public static sbyte Abs(this sbyte value)
        {
            return Math.Abs(value);
        }

19 Source : Math.cs
with MIT License
from dotnetGame

public static double IEEERemainder(double x, double y)
        {
            if (double.IsNaN(x))
            {
                return x; // IEEE 754-2008: NaN payload must be preserved
            }

            if (double.IsNaN(y))
            {
                return y; // IEEE 754-2008: NaN payload must be preserved
            }

            var regularMod = x % y;

            if (double.IsNaN(regularMod))
            {
                return double.NaN;
            }

            if ((regularMod == 0) && double.IsNegative(x))
            {
                return double.NegativeZero;
            }

            var alternativeResult = (regularMod - (Abs(y) * Sign(x)));

            if (Abs(alternativeResult) == Abs(regularMod))
            {
                var divisionResult = x / y;
                var roundedResult = Round(divisionResult);

                if (Abs(roundedResult) > Abs(divisionResult))
                {
                    return alternativeResult;
                }
                else
                {
                    return regularMod;
                }
            }

            if (Abs(alternativeResult) < Abs(regularMod))
            {
                return alternativeResult;
            }
            else
            {
                return regularMod;
            }
        }

19 Source : Math.cs
with MIT License
from dotnetGame

public static unsafe double Round(double value, int digits, MidpointRounding mode)
        {
            if ((digits < 0) || (digits > maxRoundingDigits))
            {
                throw new ArgumentOutOfRangeException(nameof(digits), SR.ArgumentOutOfRange_RoundingDigits);
            }

            if (mode < MidpointRounding.ToEven || mode > MidpointRounding.AwayFromZero)
            {
                throw new ArgumentException(SR.Format(SR.Argument_InvalidEnumValue, mode, nameof(MidpointRounding)), nameof(mode));
            }

            if (Abs(value) < doubleRoundLimit)
            {
                var power10 = roundPower10Double[digits];

                value *= power10;

                if (mode == MidpointRounding.AwayFromZero)
                {
                    var fraction = ModF(value, &value);

                    if (Abs(fraction) >= 0.5)
                    {
                        value += Sign(fraction);
                    }
                }
                else
                {
                    value = Round(value);
                }

                value /= power10;
            }

            return value;
        }

19 Source : Extensions.cs
with GNU General Public License v3.0
from mch2112

public static string ToHexString(this sbyte Input) => (Input < 0 ? "-" : "") + ToHexString((byte)(Math.Abs(Input)));

19 Source : Assembler.Operand.cs
with GNU General Public License v3.0
from mch2112

public override string ToString()
            {
                string text = RawText;

                string index = String.Empty;

                if (IndexDisplacement.HasValue)
                {
                    if ((IndexDisplacement.Value & 0x80) > 0)
                        index = " - " + Math.Abs((sbyte)(IndexDisplacement.Value)).ToHexString();
                    else
                        index = " + " + IndexDisplacement.Value.ToHexString();
                    text = text.Replace("+D", index);
                }
                else if (IsNumeric)
                {
                    if (LineInfo.Operand0 == this && IsSingleDigitArg(LineInfo.Mnemonic))
                    {
                        text = NumericValue.Value.ToHexChar();
                    }
                    else
                    {
                        switch (LineInfo.DataSize)
                        {
                            case 1:
                                text = ((byte)NumericValue.Value).ToHexString();
                                break;
                            case 0: // meta instructions
                            case 2:
                                text = NumericValue.Value.ToHexString();
                                break;
                        }
                    }
                }

                if (IsIndirect)
                    text = Parenthesize(text);

                return text;
            }

19 Source : Math.cs
with BSD 3-Clause "New" or "Revised" License
from nifanfa

public static double IEEERemainder(double x, double y)
		{
			if (double.IsNaN(x))
			{
				return x; // IEEE 754-2008: NaN payload must be preserved
			}

			if (double.IsNaN(y))
			{
				return y; // IEEE 754-2008: NaN payload must be preserved
			}

			var regularMod = x % y;

			if (double.IsNaN(regularMod))
			{
				return double.NaN;
			}

			if ((regularMod == 0) && double.IsNegative(x))
			{
				return double.NegativeZero;
			}

			var alternativeResult = (regularMod - (Abs(y) * Sign(x)));

			if (Abs(alternativeResult) == Abs(regularMod))
			{
				var divisionResult = x / y;
				var roundedResult = Round(divisionResult);

				if (Abs(roundedResult) > Abs(divisionResult))
				{
					return alternativeResult;
				}
				else
				{
					return regularMod;
				}
			}

			if (Abs(alternativeResult) < Abs(regularMod))
			{
				return alternativeResult;
			}
			else
			{
				return regularMod;
			}
		}

19 Source : Math.cs
with BSD 3-Clause "New" or "Revised" License
from nifanfa

public static double MaxMagnitude(double x, double y)
		{
			// When x and y are both finite or infinite, return the larger magnitude
			//  * We count +0.0 as larger than -0.0 to match MSVC
			// When x or y, but not both, are NaN return the opposite
			//  * We return the opposite if either is NaN to match MSVC

			if (double.IsNaN(x))
			{
				return y;
			}

			if (double.IsNaN(y))
			{
				return x;
			}

			// We do this comparison first and separately to handle the -0.0 to +0.0 comparision
			// * Doing (ax < ay) first could get transformed into (ay >= ax) by the JIT which would
			//   then return an incorrect value

			double ax = Abs(x);
			double ay = Abs(y);

			if (ax == ay)
			{
				return double.IsNegative(x) ? y : x;
			}

			return (ax < ay) ? y : x;
		}

19 Source : Math.cs
with BSD 3-Clause "New" or "Revised" License
from nifanfa

public static double MinMagnitude(double x, double y)
		{
			// When x and y are both finite or infinite, return the smaller magnitude
			//  * We count -0.0 as smaller than -0.0 to match MSVC
			// When x or y, but not both, are NaN return the opposite
			//  * We return the opposite if either is NaN to match MSVC

			if (double.IsNaN(x))
			{
				return y;
			}

			if (double.IsNaN(y))
			{
				return x;
			}

			// We do this comparison first and separately to handle the -0.0 to +0.0 comparision
			// * Doing (ax < ay) first could get transformed into (ay >= ax) by the JIT which would
			//   then return an incorrect value

			double ax = Abs(x);
			double ay = Abs(y);

			if (ax == ay)
			{
				return double.IsNegative(x) ? x : y;
			}

			return (ax < ay) ? x : y;
		}

19 Source : Math.cs
with BSD 3-Clause "New" or "Revised" License
from nifanfa

public static unsafe double Round(double value, int digits, MidpointRounding mode)
		{
			if ((digits < 0) || (digits > maxRoundingDigits))
			{
				throw new ArgumentOutOfRangeException(nameof(digits), "SR.ArgumentOutOfRange_RoundingDigits");
			}

			if (mode < MidpointRounding.ToEven || mode > MidpointRounding.ToPositiveInfinity)
			{
				throw new ArgumentException("SR.Format(SR.Argument_InvalidEnumValue, mode, nameof(MidpointRounding)), nameof(mode)");
			}

			if (Abs(value) < doubleRoundLimit)
			{
				var power10 = roundPower10Double[digits];

				value *= power10;

				switch (mode)
				{
					// Rounds to the nearest value; if the number falls midway,
					// it is rounded to the nearest value with an even least significant digit
					case MidpointRounding.ToEven:
						{
							value = Round(value);
							break;
						}

					// Rounds to the nearest value; if the number falls midway,
					// it is rounded to the nearest value above (for positive numbers) or below (for negative numbers)
					case MidpointRounding.AwayFromZero:
						{
							double fraction = ModF(value, &value);

							if (Abs(fraction) >= 0.5)
							{
								value += Sign(fraction);
							}

							break;
						}

					// Directed rounding: Round to the nearest value, toward to zero
					case MidpointRounding.ToZero:
						{
							value = Truncate(value);
							break;
						}

					// Directed Rounding: Round down to the next value, toward negative infinity
					case MidpointRounding.ToNegativeInfinity:
						{
							value = Floor(value);
							break;
						}

					// Directed rounding: Round up to the next value, toward positive infinity
					case MidpointRounding.ToPositiveInfinity:
						{
							value = Ceiling(value);
							break;
						}
					default:
						{
							throw new ArgumentException("SR.Format(SR.Argument_InvalidEnumValue, mode, nameof(MidpointRounding)), nameof(mode)");
						}
				}

				value /= power10;
			}

			return value;
		}

19 Source : MidiRelativeTimeBase.cs
with GNU Lesser General Public License v2.1
from obiwanjacobi

protected virtual void OnValueChanged(int? newTimeDivision, int? newPpqn, SmpteTimeBase newSmpte)
        {
            if (newTimeDivision.HasValue)
            {
                this.timeDivision = newTimeDivision.Value;

                // test for smpte time
                if (((short)this.timeDivision) < 0)
                {
                    var fps = SmpteTime.ToFrameRate(Math.Abs((sbyte)((this.timeDivision & 0xFF00) >> 8)));
                    var subsPerFrame = this.timeDivision & 0x00FF;

                    this.smpte = new SmpteTimeBase(fps, subsPerFrame);
                    this.ppqn = 0;
                }
                else
                {
                    ThrowIfNotAMultipleOf24(newTimeDivision.Value, "TimeDivision");

                    this.ppqn = this.timeDivision;
                    this.smpte = null;
                }
            }

            if (newPpqn.HasValue)
            {
                Check.IfArgumentOutOfRange(newPpqn.Value, 0, ushort.MaxValue, "PulsesPerQuarterNote");
                ThrowIfNotAMultipleOf24(newPpqn.Value, "PulsesPerQuarterNote");

                this.ppqn = newPpqn.Value;
                this.timeDivision = this.ppqn;
                this.smpte = null;
            }

            if (newSmpte != null)
            {
                this.timeDivision = (-(SmpteTime.FromFrameRate(newSmpte.FramesPerSecond) << 8)) | (newSmpte.SubFramesPerFrame & 0xFF);
                this.ppqn = 0;
                this.smpte = newSmpte;
            }
        }

19 Source : MidiTimeBase.cs
with GNU Lesser General Public License v2.1
from obiwanjacobi

public static MidiTimeBase Create(int timeDivision, int tempo)
        {
            Check.IfArgumentOutOfRange(timeDivision, short.MinValue, ushort.MaxValue, "timeDivision");
            if (timeDivision == 0)
            {
                throw new ArgumentException("The timeDivision value can not be zero.", "timeDivision");
            }

            var midiTimeBase = new MidiTimeBase();

            if (((short)timeDivision) < 0)
            {
                var fps = SmpteTime.ToFrameRate(Math.Abs((sbyte)((timeDivision & 0xFF00) >> 8)));
                var frames = timeDivision & 0x00FF;

                midiTimeBase.SmpteTime = new SmpteTime(0, 0, 0, frames, fps);
            }
            else
            {
                midiTimeBase.MillisecondResolution = tempo / timeDivision;
            }

            return midiTimeBase;
        }

19 Source : MidiTimeBase.cs
with GNU Lesser General Public License v2.1
from obiwanjacobi

public static MidiTimeBase Create(int timeDivision, int tempo)
        {
            Check.IfArgumentOutOfRange(timeDivision, short.MinValue, ushort.MaxValue, nameof(timeDivision));
            if (timeDivision == 0)
            {
                throw new ArgumentException("The timeDivision value can not be zero.", nameof(timeDivision));
            }

            var midiTimeBase = new MidiTimeBase();

            if (((short)timeDivision) < 0)
            {
                var fps = SmpteTime.ToFrameRate(Math.Abs((sbyte)((timeDivision & 0xFF00) >> 8)));
                var frames = timeDivision & 0x00FF;

                midiTimeBase.SmpteTime = new SmpteTime(0, 0, 0, frames, fps);
            }
            else
            {
                midiTimeBase.MillisecondResolution = tempo / timeDivision;
            }

            return midiTimeBase;
        }

19 Source : MidiRelativeTimeBase.cs
with GNU Lesser General Public License v2.1
from obiwanjacobi

protected virtual void OnValueChanged(int? newTimeDivision, int? newPpqn, SmpteTimeBase newSmpte)
        {
            if (newTimeDivision.HasValue)
            {
                _timeDivision = newTimeDivision.Value;

                // test for smpte time
                if (((short)_timeDivision) < 0)
                {
                    var fps = SmpteTime.ToFrameRate(Math.Abs((sbyte)((_timeDivision & 0xFF00) >> 8)));
                    var subsPerFrame = _timeDivision & 0x00FF;

                    _smpte = new SmpteTimeBase(fps, subsPerFrame);
                    _ppqn = 0;
                }
                else
                {
                    ThrowIfNotAMultipleOf24(newTimeDivision.Value, "TimeDivision");

                    _ppqn = _timeDivision;
                    _smpte = null;
                }
            }

            if (newPpqn.HasValue)
            {
                Check.IfArgumentOutOfRange(newPpqn.Value, 0, ushort.MaxValue, "PulsesPerQuarterNote");
                ThrowIfNotAMultipleOf24(newPpqn.Value, "PulsesPerQuarterNote");

                _ppqn = newPpqn.Value;
                _timeDivision = _ppqn;
                _smpte = null;
            }

            if (newSmpte != null)
            {
                _timeDivision = (-(SmpteTime.FromFrameRate(newSmpte.FramesPerSecond) << 8)) | (newSmpte.SubFramesPerFrame & 0xFF);
                _ppqn = 0;
                _smpte = newSmpte;
            }
        }

19 Source : FMath_GenericPlatformMathT.cs
with MIT License
from pixeltris

public static sbyte Abs(sbyte value)
        {
            return Math.Abs(value);
        }

19 Source : 080-TestSystemMath.cs
with MIT License
from ToadsworthLP

[TestCompiler(DataRange.Standard)]
        public static sbyte TestAbsSByte(sbyte value)
        {
            return Math.Abs(value);
        }