mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2025-12-17 12:44:42 +03:00
Change comparison to use int instead of double (#1758)
This allows the example to remain simple well not misleading a beginner such a comparison is safe. Including an epsilon comparison or something similar would overly complicate this example. Co-authored-by: Martin O'Shea <martin.oshea@native-instruments.com>
This commit is contained in:
@@ -13945,10 +13945,10 @@ Although `cached_computation` works perfectly in a single-threaded environment,
|
|||||||
##### Example, good
|
##### Example, good
|
||||||
|
|
||||||
struct ComputationCache {
|
struct ComputationCache {
|
||||||
double cached_x = 0.0;
|
int cached_x = 0;
|
||||||
double cached_result = COMPUTATION_OF_ZERO;
|
double cached_result = COMPUTATION_OF_ZERO;
|
||||||
|
|
||||||
double compute(double x) {
|
double compute(int x) {
|
||||||
if (cached_x != x) {
|
if (cached_x != x) {
|
||||||
cached_x = x;
|
cached_x = x;
|
||||||
cached_result = computation(x);
|
cached_result = computation(x);
|
||||||
|
|||||||
Reference in New Issue
Block a user