Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Round() [7/8]

static unsafe double System.Math.Round ( double value,
int digits,
MidpointRounding mode )
inlinestatic

Definition at line 1156 of file Math.cs.

1157 {
1158 if (digits < 0 || digits > 15)
1159 {
1160 throw new ArgumentOutOfRangeException("digits", SR.ArgumentOutOfRange_RoundingDigits);
1161 }
1162 if (mode < MidpointRounding.ToEven || mode > MidpointRounding.ToPositiveInfinity)
1163 {
1164 throw new ArgumentException(SR.Format(SR.Argument_InvalidEnumValue, mode, "MidpointRounding"), "mode");
1165 }
1166 if (Abs(value) < 10000000000000000.0)
1167 {
1168 double num = roundPower10Double[digits];
1169 value *= num;
1170 switch (mode)
1171 {
1172 case MidpointRounding.ToEven:
1173 value = Round(value);
1174 break;
1175 case MidpointRounding.AwayFromZero:
1176 {
1177 double value2 = ModF(value, &value);
1178 if (Abs(value2) >= 0.5)
1179 {
1180 value += (double)Sign(value2);
1181 }
1182 break;
1183 }
1184 case MidpointRounding.ToZero:
1185 value = Truncate(value);
1186 break;
1187 case MidpointRounding.ToNegativeInfinity:
1188 value = Floor(value);
1189 break;
1190 case MidpointRounding.ToPositiveInfinity:
1191 value = Ceiling(value);
1192 break;
1193 default:
1194 throw new ArgumentException(SR.Format(SR.Argument_InvalidEnumValue, mode, "MidpointRounding"), "mode");
1195 }
1196 value /= num;
1197 }
1198 return value;
1199 }
static decimal Truncate(decimal d)
Definition Math.cs:1270
static decimal Round(decimal d)
Definition Math.cs:1096
static double Ceiling(double a)
static readonly double[] roundPower10Double
Definition Math.cs:20
static double Abs(double value)
static double Floor(double d)
static int Sign(decimal value)
Definition Math.cs:1202
static unsafe double ModF(double x, double *intptr)

References System.Math.Abs(), System.SR.Argument_InvalidEnumValue, System.SR.ArgumentOutOfRange_RoundingDigits, System.Math.Ceiling(), System.Math.Floor(), System.SR.Format(), System.Math.ModF(), System.Math.Round(), System.Math.roundPower10Double, System.Math.Sign(), System.Math.Truncate(), and System.value.