Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

New Truncate function including tests.

  • Loading branch information...
commit 4958cdfaa663de600d4844ea2f918997d1d169ff 1 parent b5d5e47
@polyethene authored
Showing with 17 additions and 0 deletions.
  1. +10 −0 Rusty/Core/Math.cs
  2. +7 −0 Tests/Rusty/Math.cs
View
10 Rusty/Core/Math.cs
@@ -291,5 +291,15 @@ public static double Tanh(double n)
{
return Math.Tanh(n);
}
+
+ /// <summary>
+ /// Calculates the integral part of a specified number.
+ /// </summary>
+ /// <param name="n">A number to truncate.</param>
+ /// <returns>The integral part of <paramref name="n"/>; that is, the number that remains after any fractional digits have been discarded.</returns>
+ public static decimal Truncate(decimal n)
+ {
+ return Math.Truncate(n);
+ }
}
}
View
7 Tests/Rusty/Math.cs
@@ -250,5 +250,12 @@ public void Tanh()
Assert.AreEqual(Math.Tanh(v), Core.Tanh(v));
}
}
+
+ [Test, Category("Math")]
+ public void Truncate()
+ {
+ foreach (var n in new[] { -1m, -4.5m, 0m, 2.5m, 1m, 8.675m })
+ Assert.AreEqual(Math.Truncate(n), Core.Truncate(n));
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.