mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08: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:
parent
1caef9a7f1
commit
ffeca2a254
|
@ -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);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user