Skip to content

Commit

Permalink
fix davidedc#144: bug in rational powers of -1
Browse files Browse the repository at this point in the history
  • Loading branch information
ksthicke committed Jun 23, 2023
1 parent 4a91ef4 commit 3b8607d
Showing 1 changed file with 3 additions and 19 deletions.
22 changes: 3 additions & 19 deletions sources/power.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,27 +160,11 @@ function yypower(base: U, exponent: U): U {
) {
if (DEBUG_POWER) {
console.log(' power: -1 ^ rational');
console.log(
` trick: exponent.q.a , exponent.q.b ${exponent.q.a} , ${exponent.q.b}`
);
}
if (exponent.q.a < exponent.q.b) {
tmp = makeList(symbol(POWER), base, exponent);
} else {
tmp = makeList(
symbol(MULTIPLY),
base,
makeList(
symbol(POWER),
base,
rational(exponent.q.a.mod(exponent.q.b), exponent.q.b)
)
);
if (DEBUG_POWER) {
console.log(` trick applied : ${tmp}`);
}
}

const aModded = exponent.q.a.mod(exponent.q.b.multiply(2));
tmp = makeList(symbol(POWER), base, rational(aModded, exponent.q.b));

// evaluates clock form into
// rectangular form. This seems to give
// slightly better form to some test results.
Expand Down

0 comments on commit 3b8607d

Please sign in to comment.