Skip to content

Commit

Permalink
Merge cabe9e8 into 658c2a2
Browse files Browse the repository at this point in the history
  • Loading branch information
berekuk committed Aug 20, 2023
2 parents 658c2a2 + cabe9e8 commit 1114d57
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
14 changes: 14 additions & 0 deletions packages/squiggle-lang/__tests__/library/distOperations_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { testEvalToBe } from "../helpers/reducerHelpers.js";

// TODO - it'd be useful to do most of `./sym_test.ts` tests here, without `Sym.` prefix
describe("Dist operations", () => {
describe("Power on negative samples", () => {
// ok when power is integer
testEvalToBe("normal(-100, 1) ^ 2", "Sample Set Distribution");
// fails when power is not an integer
testEvalToBe(
"normal(-100, 1) ^ 2.5",
"Error(Distribution Math Error: Operation returned complex result)"
);
});
});
9 changes: 6 additions & 3 deletions packages/squiggle-lang/src/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@ export const Convolution = {
type OperationFn = (a: number, b: number) => result<number, OperationError>;

const power: OperationFn = (a, b) => {
if (a >= 0) {
return Ok(a ** b);
} else {
const result = a ** b;
if (Number.isNaN(result)) {
if (Number.isNaN(a) || Number.isNaN(b)) {
return Ok(result); // bad, but the issue is upstream of `power` operation
}
return Result.Err(new ComplexNumberError());
}
return Ok(result);
};

const add: OperationFn = (a, b) => Ok(a + b);
Expand Down

0 comments on commit 1114d57

Please sign in to comment.