Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
OpenWalnut
OpenWalnut Core
Commits
dc718335
Commit
dc718335
authored
Feb 13, 2013
by
Mathias Goldau
Browse files
[FIX
#244
] Now the last interval is explicitly queried, resulting in slower but more correct code.
parent
ea6891c3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
5 deletions
+9
-5
src/core/common/WHistogramBasic.cpp
src/core/common/WHistogramBasic.cpp
+6
-2
src/core/common/test/WHistogramBasic_test.h
src/core/common/test/WHistogramBasic_test.h
+3
-3
No files found.
src/core/common/WHistogramBasic.cpp
View file @
dc718335
...
...
@@ -35,7 +35,7 @@
WHistogramBasic
::
WHistogramBasic
(
double
min
,
double
max
,
size_t
buckets
)
:
WHistogram
(
min
,
max
,
buckets
),
m_bins
(
buckets
,
0
),
m_intervalWidth
(
(
m_maximum
-
m_minimum
)
/
static_cast
<
double
>
(
m_nbBuckets
)
)
m_intervalWidth
(
std
::
abs
(
m_maximum
-
m_minimum
)
/
static_cast
<
double
>
(
m_nbBuckets
)
)
{
}
...
...
@@ -91,9 +91,13 @@ void WHistogramBasic::insert( double value )
{
m_bins
.
at
(
m_nbBuckets
-
1
)
++
;
}
else
if
(
value
>=
(
m_maximum
-
m_intervalWidth
)
&&
value
<=
m_maximum
)
// last bucket deserves extra treatment due to possible out of bounds index
{
m_bins
.
at
(
m_nbBuckets
-
1
)
++
;
}
else
{
m_bins
.
at
(
static_cast
<
size_t
>
(
(
value
-
m_minimum
)
/
std
::
abs
(
m_maximum
-
m_minimum
)
*
(
m_nbBuckets
-
1
)
)
)
++
;
m_bins
.
at
(
static_cast
<
size_t
>
(
(
value
-
m_minimum
)
/
std
::
abs
(
m_maximum
-
m_minimum
)
*
(
m_nbBuckets
)
)
)
++
;
}
}
...
...
src/core/common/test/WHistogramBasic_test.h
View file @
dc718335
...
...
@@ -64,7 +64,7 @@ public:
h
.
insert
(
0.7234
);
TS_ASSERT_EQUALS
(
h
.
size
(),
1000
);
TS_ASSERT_EQUALS
(
h
.
valuesSize
(),
1
);
TS_ASSERT_EQUALS
(
h
[
72
2
],
1
);
TS_ASSERT_EQUALS
(
h
[
72
3
],
1
);
}
/**
...
...
@@ -74,11 +74,11 @@ public:
{
WHistogramBasic
h
(
0.0
,
1.0
);
h
.
insert
(
0.001
);
TS_ASSERT_EQUALS
(
h
[
0
],
1
);
TS_ASSERT_EQUALS
(
h
[
1
],
1
);
h
.
insert
(
0.0039999
);
TS_ASSERT_EQUALS
(
h
[
3
],
1
);
h
.
insert
(
0.0070001
);
TS_ASSERT_EQUALS
(
h
[
6
],
1
);
TS_ASSERT_EQUALS
(
h
[
7
],
1
);
}
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment