Browse Source

simplify overflow checks somewhat

dds
PaulStoffregen 10 years ago
parent
commit
aa8c6400a3
1 changed files with 2 additions and 14 deletions
  1. +2
    -14
      synth_dc.h

+ 2
- 14
synth_dc.h View File



if (a >= 0) { if (a >= 0) {
if (b >= 0) { if (b >= 0) {
if (a >= b) {
diff = a - b;
negative = 0;
} else {
diff = b - a;
negative = 1;
}
return (a - b) / c; // no overflow if both a & b are positive
} else { } else {
diff = a + (b * -1); // assumes 0x80000000 * -1 == 0x80000000 diff = a + (b * -1); // assumes 0x80000000 * -1 == 0x80000000
negative = 0; negative = 0;
diff = (a * -1) + b; // assumes 0x80000000 * -1 == 0x80000000 diff = (a * -1) + b; // assumes 0x80000000 * -1 == 0x80000000
negative = 1; negative = 1;
} else { } else {
if (a >= b) {
diff = a - b;
negative = 0;
} else {
diff = b - a;
negative = 1;
}
return (a - b) / c; // no overflow if both a & b are negative
} }
} }
if (c >= 0) { if (c >= 0) {

Loading…
Cancel
Save