Skip to content

Commit 98ba0a5

Browse files
committed
Modified clip(float,float)
1 parent f33e8a1 commit 98ba0a5

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

LibSource/FloatArray.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,12 @@ void FloatArray::clip(float max){
202202
data[n]=-max;
203203
}
204204
}
205-
void FloatArray::clip(float max, float newMax){
206-
float scale=newMax/max;
205+
void FloatArray::clip(float min, float max){
207206
for(int n=0; n<size; n++){
208207
if(data[n]>max)
209208
data[n]=max;
210-
else if(data[n]<-max)
211-
data[n]=-max;
212-
data[n]*=scale;
209+
else if(data[n]<min)
210+
data[n]=min;
213211
}
214212
}
215213
FloatArray FloatArray::subArray(int offset, int length){

TestPatches/FloatArrayTestPatch.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class FloatArrayTestPatch : public Patch {
148148
float clip=0.5;
149149
tempFa1.clip(clip);
150150
for(int n=0; n<size; n++){
151-
assert(abs(tempFa1[n])<=clip, "clip");
151+
assert(abs(tempFa1[n])<=clip, "clip to value");
152152
}
153153
tempFa1.copyFrom(fa);
154154
tempFa1.scale(3);
@@ -157,9 +157,11 @@ class FloatArrayTestPatch : public Patch {
157157
assert(abs(tempFa1[n])<=1, "clip to 1");
158158
}
159159
fa.scale(3, tempFa1);
160-
tempFa1.clip(0.1, 0.5);
160+
float min=0.1;
161+
float max=0.5;
162+
tempFa1.clip(min, max);
161163
for(int n=0; n<size; n++){
162-
assert(abs(tempFa1[n])<=0.5, "clip and scale");
164+
assert(abs(tempFa1[n])<=max && abs(tempFa1[n])>=min, "clip, asymmetric");
163165
}
164166
}
165167
//test negate

0 commit comments

Comments
 (0)