Skip to content

Commit d2190ce

Browse files
committed
impr
1 parent d9fcd55 commit d2190ce

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

src/PolylineAlgorithm/PolylineEncoding.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public static int Normalize(double value, uint precision = 5) {
106106
/// without division.
107107
/// </para>
108108
/// <para>
109+
/// The calculation is performed inside a <c>checked</c> block to ensure that any arithmetic overflow is detected and an <see cref="OverflowException"/> is thrown.
110+
/// </para>
111+
/// <para>
109112
/// For example, with a precision of 5:
110113
/// <list type="bullet">
111114
/// <item><description>A value of 3778903 becomes 37.78903</description></item>
@@ -125,12 +128,16 @@ public static int Normalize(double value, uint precision = 5) {
125128
/// <returns>
126129
/// The denormalized floating-point coordinate value.
127130
/// </returns>
131+
/// <exception cref="OverflowException">
132+
/// Thrown if the arithmetic operation overflows during conversion.
133+
/// </exception>
128134
public static double Denormalize(int value, uint precision = 5) {
129135
// Return fast if the value is zero, return 0.0 as the denormalized value.
130136
if (value == 0) {
131137
return 0.0;
132138
}
133139

140+
// Using 'checked' to ensure overflow exceptions are thrown if the result exceeds numeric limits.
134141
checked {
135142
return precision == 0 ? value : value / Math.Pow(10, precision);
136143
}

0 commit comments

Comments
 (0)