FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pineforge-engine/src/math.cpp at main · pineforge-4pass/pineforge-engine · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
pineforge-4pass
/
pineforge-engine
Public
Notifications
You must be signed in to change notification settings
Fork
42
Star
179
Code
Issues
1
Pull requests
1
Discussions
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Discussions
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pineforge-engine
/
src
/
math.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
69 lines (57 loc) · 1.65 KB
Breadcrumbs
pineforge-engine
/
src
/
math.cpp
Copy path
File metadata and controls
69 lines (57 loc) · 1.65 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#
include
<
pineforge/math.hpp
>
namespace
pineforge
{
namespace
math
{
Sum::Sum
(
int
length)
: length_(length), sum_(
0.0
), saved_sum_(
0.0
),
has_saved_state_
(
false
), current_value_added_(
false
),
current_value_evicted_(
false
), current_evicted_value_(
0.0
) {}
double
Sum::apply
(
double
src) {
current_value_added_ =
false
;
current_value_evicted_ =
false
;
if
(
is_na
(src)) {
//
Pine ignores na sources rather than consuming a window slot. Once
//
seeded, the last-N-valid sum is therefore held on na-input bars.
if
(length_ >
0
&&
static_cast
<
int
>(buffer_.
size
()) >= length_) {
return
sum_;
}
return
na<
double
>();
}
buffer_.
push_back
(src);
sum_ += src;
current_value_added_ =
true
;
while
((
int
)buffer_.
size
() > length_) {
current_value_evicted_ =
true
;
current_evicted_value_ = buffer_.
front
();
sum_ -= buffer_.
front
();
buffer_.
pop_front
();
}
if
(
static_cast
<
int
>(buffer_.
size
()) < length_) {
return
na<
double
>();
}
return
sum_;
}
void
Sum::restore
() {
if
(current_value_added_ && length_ >
0
) {
buffer_.
pop_back
();
if
(current_value_evicted_) {
buffer_.
push_front
(current_evicted_value_);
}
}
sum_ = saved_sum_;
current_value_added_ =
false
;
current_value_evicted_ =
false
;
}
double
Sum::compute
(
double
src) {
saved_sum_ = sum_;
has_saved_state_ =
true
;
return
apply
(src);
}
double
Sum::recompute
(
double
src) {
if
(!has_saved_state_) {
return
compute
(src);
}
restore
();
return
apply
(src);
}
}
//
namespace math
}
//
namespace pineforge
Back
|
FazBrowse Home
|
New Git URL