Skip to content

fix(codegen): #142 Math.tan/asin/acos/atan/atan2 silent identity (v0.…#148

Closed
proggeramlug wants to merge 1 commit intomainfrom
fix/issue-142-math-trig
Closed

fix(codegen): #142 Math.tan/asin/acos/atan/atan2 silent identity (v0.…#148
proggeramlug wants to merge 1 commit intomainfrom
fix/issue-142-math-trig

Conversation

@proggeramlug
Copy link
Copy Markdown
Contributor

@proggeramlug proggeramlug commented Apr 23, 2026

…5.165)

The five codegen arms at crates/perry-codegen/src/expr.rs:5417-5424 fell through to lower_expr(ctx, o), returning the argument unchanged. Runtime functions (js_math_tan/asin/acos/atan/atan2 in perry-runtime/src/math.rs) and extern declarations (runtime_decls.rs:1482-1493) were already present — only the codegen wiring was missing.

Replaced the fall-through with calls to the existing runtime symbols, matching the shape of the sinh/cosh/tanh arms three lines above. atan2 evaluates y first then x (JS arg order) and passes both to js_math_atan2.

Verified against node --experimental-strip-types: Math.tan(1) = 1.557… (was 1), Math.atan2(0,-1) = π (was -1) — all within last-digit libm rounding.

Summary

Changes

Related issue

Test plan

  • cargo build --release clean
  • cargo test --workspace --exclude perry-ui-ios --exclude perry-ui-tvos --exclude perry-ui-watchos --exclude perry-ui-gtk4 --exclude perry-ui-android --exclude perry-ui-windows passes
  • (if user-facing) Added or updated a test under test-files/ or a #[test] in the affected crate
  • (if CLI / stdlib / runtime API changed) Updated docs/src/
  • (if touching a platform UI backend) Built -p perry-ui-<backend> locally on that platform

Screenshots / output

Checklist

  • I have NOT bumped the workspace version or edited CLAUDE.md / CHANGELOG.md (maintainer handles these at merge)
  • My commits follow the loose feat: / fix: / docs: / chore: prefix convention used in the log
  • I've read CONTRIBUTING.md and agree to the Code of Conduct

…5.165)

The five codegen arms at crates/perry-codegen/src/expr.rs:5417-5424 fell
through to lower_expr(ctx, o), returning the argument unchanged. Runtime
functions (js_math_tan/asin/acos/atan/atan2 in perry-runtime/src/math.rs)
and extern declarations (runtime_decls.rs:1482-1493) were already present
— only the codegen wiring was missing.

Replaced the fall-through with calls to the existing runtime symbols,
matching the shape of the sinh/cosh/tanh arms three lines above. atan2
evaluates y first then x (JS arg order) and passes both to js_math_atan2.

Verified against node --experimental-strip-types: Math.tan(1) = 1.557…
(was 1), Math.atan2(0,-1) = π (was -1) — all within last-digit libm
rounding.
proggeramlug added a commit that referenced this pull request Apr 23, 2026
…5.177)

Merged via conflict-resolved cherry-pick of PR #148 (original branch cut
at v0.5.164; main had advanced to v0.5.176 so the CLAUDE.md / Cargo.toml
/ Cargo.lock bumps had to be taken from main and reapplied at v0.5.177).

The five codegen arms at crates/perry-codegen/src/expr.rs:5417-5424 fell
through to lower_expr(ctx, o), returning the argument unchanged. Runtime
functions (js_math_tan/asin/acos/atan/atan2 in perry-runtime/src/math.rs)
and extern declarations (runtime_decls.rs:1482-1493) were already present
— only the codegen wiring was missing.

Replaced the fall-through with calls to the existing runtime symbols,
matching the shape of the sinh/cosh/tanh arms three lines above. atan2
evaluates y first then x (JS arg order) and passes both to js_math_atan2.

Verified against node --experimental-strip-types: Math.tan(1) = 1.557…
(was 1), Math.atan2(0,-1) = π (was -1), Math.asin(1) = π/2, Math.acos(1) = 0,
Math.atan(1) = π/4 — all within last-digit libm rounding.

Original author: Ralph Küpper <ralph.kuepper@skelpo.com> (PR #148).
@proggeramlug
Copy link
Copy Markdown
Contributor Author

Merged via conflict-resolved cherry-pick as ce550d9 on main. The PR branch was cut at v0.5.164 and main had moved to v0.5.176, so the CLAUDE.md / Cargo.{toml,lock} bumps had to be reapplied at v0.5.177 on top of the intermediate changes. The actual codegen fix (the five Math.* arms in crates/perry-codegen/src/expr.rs) landed unchanged from this PR. Verified end-to-end against node --experimental-strip-types: Math.tan(1), Math.atan2(0,-1), asin/acos/atan all match to libm-rounding precision.

Thanks for the fix!

@proggeramlug proggeramlug deleted the fix/issue-142-math-trig branch April 23, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant