lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master dc47d4a 04/10: Improve documentation


From: Greg Chicares
Subject: [lmi-commits] [lmi] master dc47d4a 04/10: Improve documentation
Date: Tue, 20 Dec 2016 01:31:04 +0000 (UTC)

branch: master
commit dc47d4a0dae49107eeddb2e2b4ae8a1dccadc7ab
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Improve documentation
    
    This expression
      (0 < r) ? std::floor(r + 0.5) : std::ceil(r -0.5)
    and this one
      std::rint(r)
    may return different values. Explain why either may be used in a
    particular context.
---
 round_to.hpp |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/round_to.hpp b/round_to.hpp
index 5a2217d..4e9b1b9 100644
--- a/round_to.hpp
+++ b/round_to.hpp
@@ -265,7 +265,7 @@ RealType round_near(RealType r)
 #ifndef LMI_LACKING_RINT_OR_EQUIVALENT
     RealType i_part = perform_rint(r);
 #else // defined LMI_LACKING_RINT_OR_EQUIVALENT
-//  This
+//  To return immediately with this value:
 //    return (RealType(0) < r) ? std::floor(r + 0.5) : std::ceil(r -0.5);
 //  would be incorrect, because halfway cases must be rounded to even.
     RealType i_part =
@@ -273,6 +273,9 @@ RealType round_near(RealType r)
             ? std::floor(r + 0.5)
             : std::ceil (r - 0.5)
             ;
+    // This 'i_part' needn't equal the value that std::rint() would
+    // return, as long as both produce the same correct result after
+    // adjustment below.
 #endif // defined LMI_LACKING_RINT_OR_EQUIVALENT
     RealType f_part = r - i_part;
     RealType abs_f_part = std::fabs(f_part);



reply via email to

[Prev in Thread] Current Thread [Next in Thread]