mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
remove use of == on doubles
could use an epsilon, but that just distracts from the point of the example, so changed double to int instead
This commit is contained in:
parent
7a8cac8dbc
commit
7a4fbef370
|
@ -10211,15 +10211,13 @@ Note that this applies most urgently to library code and least urgently to stand
|
||||||
|
|
||||||
##### Example
|
##### Example
|
||||||
|
|
||||||
double cached_computation(double x)
|
double cached_computation(int x)
|
||||||
{
|
{
|
||||||
static double cached_x = 0.0;
|
static int cached_x = 0;
|
||||||
static double cached_result = COMPUTATION_OF_ZERO;
|
static double cached_result = COMPUTATION_OF_ZERO;
|
||||||
double result;
|
|
||||||
|
|
||||||
if (cached_x == x)
|
if (cached_x == x)
|
||||||
return cached_result;
|
return cached_result;
|
||||||
result = computation(x);
|
double result = computation(x);
|
||||||
cached_x = x;
|
cached_x = x;
|
||||||
cached_result = result;
|
cached_result = result;
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user