[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);
- [lmi-commits] [lmi] master updated (ae22927 -> 83d8eb3), Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master 6cfeca5 02/10: Drop support for an ancient non-free compiler, Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master dc47d4a 04/10: Improve documentation,
Greg Chicares <=
- [lmi-commits] [lmi] master fa18f82 01/10: Remove references to nonexistent html documentation, Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master bdd39b7 08/10: Fix defect introduced 20050526T1235Z: precision loss, Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master 83d8eb3 10/10: Experimentally rely on optimization of pow(long double, int), Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master eff3c7f 09/10: Rename a member datum for concinnity, Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master 0f3563c 05/10: Simplify conditionals using certain object-like macros, Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master 46d02c5 03/10: Expunge inline replacements for std::fabs() and std::floor() [425], Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master 54d2503 06/10: Presume std::rint() is available [424], Greg Chicares, 2016/12/19
- [lmi-commits] [lmi] master 84ed793 07/10: Simplify preprocessor conditionals, Greg Chicares, 2016/12/19