From 11e33c7140173268857b5a4d7978193bc648bda6 Mon Sep 17 00:00:00 2001 From: Alex Dyachenko Date: Fri, 27 Jun 2014 12:41:46 -0400 Subject: [PATCH] Float IsInteger --- mpir.net/mpir.net-tests/HugeFloatTests/Conversions.cs | 11 +++++++++++ mpir.net/mpir.net/HugeFloat.h | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/mpir.net/mpir.net-tests/HugeFloatTests/Conversions.cs b/mpir.net/mpir.net-tests/HugeFloatTests/Conversions.cs index b1ea338e..fff89e65 100644 --- a/mpir.net/mpir.net-tests/HugeFloatTests/Conversions.cs +++ b/mpir.net/mpir.net-tests/HugeFloatTests/Conversions.cs @@ -358,5 +358,16 @@ namespace MPIR.Tests.HugeFloatTests Assert.IsFalse(b.FitsUshort()); } } + + [TestMethod] + public void FloatIsInteger() + { + using (var a = new HugeFloat("-233454059287409285742345.125")) + { + Assert.IsFalse(a.IsInteger()); + a.Value = a * 8; + Assert.IsTrue(a.IsInteger()); + } + } } } diff --git a/mpir.net/mpir.net/HugeFloat.h b/mpir.net/mpir.net/HugeFloat.h index 0611a009..994cab1d 100644 --- a/mpir.net/mpir.net/HugeFloat.h +++ b/mpir.net/mpir.net/HugeFloat.h @@ -1223,6 +1223,12 @@ namespace MPIR /// true if the value will fit in a short bool FitsUshort() { return MP(fits_ushort_p)(_value) != 0; } + /// + /// Returns true if the source number is a whole integer. + /// + /// true if the value is an integer + bool IsInteger() { return MP(integer_p)(_value) != 0; } + #pragma endregion #pragma region IO