diff --git a/packages/squiggle-lang/__tests__/JS__Test.ts b/packages/squiggle-lang/__tests__/JS__Test.ts index 9ede97ef..641b0b5d 100644 --- a/packages/squiggle-lang/__tests__/JS__Test.ts +++ b/packages/squiggle-lang/__tests__/JS__Test.ts @@ -8,4 +8,8 @@ describe("A simple result", () => { let foo = run("normal(5,2)"); expect(1).toEqual(1); }); + test("log(1) = 0", () => { + let foo = run("log(1)"); + expect(foo).toEqual({ tag: 'Ok', value: { hd: { NAME: 'Float', VAL: 0}, tl: 0}}); + }) }); diff --git a/packages/squiggle-lang/src/rescript/interpreter/typeSystem/HardcodedFunctions.res b/packages/squiggle-lang/src/rescript/interpreter/typeSystem/HardcodedFunctions.res index 3e06ae71..9178d6c2 100644 --- a/packages/squiggle-lang/src/rescript/interpreter/typeSystem/HardcodedFunctions.res +++ b/packages/squiggle-lang/src/rescript/interpreter/typeSystem/HardcodedFunctions.res @@ -186,6 +186,17 @@ let all = [ }, (), ), + Function.T.make( + ~name="log", + ~outputType=#Float, + ~inputTypes=[#Float], + ~run=x => + switch x { + | [#Float(a)] => Ok(#SymbolicDist(#Float(Js.Math.log(a)))) + | e => wrongInputsError(e) + }, + (), + ), makeDistFloat("pdf", (dist, float) => floatFromDist(#Pdf(float), dist)), makeDistFloat("inv", (dist, float) => floatFromDist(#Inv(float), dist)), makeDistFloat("cdf", (dist, float) => floatFromDist(#Cdf(float), dist)),