Skip to content

Upgrade exponentiation to unified operator #7153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add a test
  • Loading branch information
cometkim committed Mar 22, 2025
commit 0ef247a5a064325aa72575209e70a63cc56f03cc
23 changes: 14 additions & 9 deletions tests/tests/src/exponentiation_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,27 @@ function eq(loc, x, y) {

let intPow = ((a, b) => Math.pow(a, b) | 0);

eq("File \"exponentiation_test.res\", line 10, characters 5-12", 2 ** 3 ** 2, Math.pow(2, Math.pow(3, 2)));
let four = 4;

eq("File \"exponentiation_test.res\", line 11, characters 5-12", 2 ** (-3) ** 2, Math.pow(2, Math.pow(-3, 2)));
eq("File \"exponentiation_test.res\", line 11, characters 5-12", 2 ** 3 ** 2, Math.pow(2, Math.pow(3, 2)));

eq("File \"exponentiation_test.res\", line 12, characters 5-12", (2 ** 3) ** 2, Math.pow(Math.pow(2, 3), 2));
eq("File \"exponentiation_test.res\", line 12, characters 5-12", 2 ** (-3) ** 2, Math.pow(2, Math.pow(-3, 2)));

eq("File \"exponentiation_test.res\", line 13, characters 5-12", (-2) ** 2, Math.pow(-2, 2));
eq("File \"exponentiation_test.res\", line 13, characters 5-12", (2 ** 3) ** 2, Math.pow(Math.pow(2, 3), 2));

eq("File \"exponentiation_test.res\", line 15, characters 5-12", 512, intPow(2, intPow(3, 2)));
eq("File \"exponentiation_test.res\", line 14, characters 5-12", (-2) ** 2, Math.pow(-2, 2));

eq("File \"exponentiation_test.res\", line 16, characters 5-12", 512, intPow(2, intPow(-3, 2)));
eq("File \"exponentiation_test.res\", line 16, characters 5-12", 512, intPow(2, intPow(3, 2)));

eq("File \"exponentiation_test.res\", line 17, characters 5-12", 64, intPow(intPow(2, 3), 2));
eq("File \"exponentiation_test.res\", line 17, characters 5-12", 512, intPow(2, intPow(-3, 2)));

eq("File \"exponentiation_test.res\", line 18, characters 5-12", -2147483648, intPow(-2, 31));
eq("File \"exponentiation_test.res\", line 18, characters 5-12", 64, intPow(intPow(2, 3), 2));

eq("File \"exponentiation_test.res\", line 19, characters 5-12", 0, intPow(2, 32));
eq("File \"exponentiation_test.res\", line 19, characters 5-12", -2147483648, intPow(-2, 31));

eq("File \"exponentiation_test.res\", line 20, characters 5-12", 0, intPow(2, 32));

eq("File \"exponentiation_test.res\", line 22, characters 5-12", 256, four ** four | 0);

Mt.from_pair_suites("Exponentiation_test", suites.contents);

Expand All @@ -41,5 +45,6 @@ export {
test_id,
eq,
intPow,
four,
}
/* Not a pure module */
3 changes: 3 additions & 0 deletions tests/tests/src/exponentiation_test.res
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ let eq = (loc, x, y) => Mt.eq_suites(~test_id, ~suites, loc, x, y)
external jsPow: (float, float) => float = "Math.pow"

let intPow: (int, int) => int = %raw(`(a, b) => Math.pow(a, b) | 0`)
let four: int = %raw(`4`)

let () = {
eq(__LOC__, 2. ** 3. ** 2., jsPow(2., jsPow(3., 2.)))
Expand All @@ -17,6 +18,8 @@ let () = {
eq(__LOC__, (2 ** 3) ** 2, intPow(intPow(2, 3), 2))
eq(__LOC__, -2 ** 31, intPow(-2, 31))
eq(__LOC__, 2 ** 32, intPow(2, 32))

eq(__LOC__, 4 ** 4, four ** four)
}

let () = Mt.from_pair_suites(__MODULE__, suites.contents)
Loading