Title: Arithmetic that differs from Python: % with negatives, ** grouping, round halves, bool as int, e · Issue #224 · vpython/glowscript · GitHub
Open Graph Title: Arithmetic that differs from Python: % with negatives, ** grouping, round halves, bool as int, e · Issue #224 · vpython/glowscript
X Title: Arithmetic that differs from Python: % with negatives, ** grouping, round halves, bool as int, e · Issue #224 · vpython/glowscript
Description: While fixing #170 I ran a 122-expression arithmetic program through Web VPython 3.2 and compared every result with CPython. 107 match. The rest differ. All of these differences are older than #170: the release before it has every one of ...
Open Graph Description: While fixing #170 I ran a 122-expression arithmetic program through Web VPython 3.2 and compared every result with CPython. 107 match. The rest differ. All of these differences are older than #170:...
X Description: While fixing #170 I ran a 122-expression arithmetic program through Web VPython 3.2 and compared every result with CPython. 107 match. The rest differ. All of these differences are older than #170:...
Opengraph URL: https://github.com/vpython/glowscript/issues/224
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Arithmetic that differs from Python: % with negatives, ** grouping, round halves, bool as int, e","articleBody":"While fixing #170 I ran a 122-expression arithmetic program through Web VPython 3.2 and compared every result with CPython. 107 match. The rest differ. All of these differences are older than #170: the release before it has every one of them.\n\n| Expression | Web VPython | Python | Cause |\n|---|---|---|---|\n| `7 % -3` | 1 | -2 | `%` is JavaScript's remainder, which takes the sign of the left operand. Python's takes the sign of the right one. |\n| `-7 % 3` | -1 | 2 | same |\n| `-7.5 % 2` | -1.5 | 0.5 | same |\n| `a = 7; a %= -3` | 1 | -2 | same |\n| `2**3**2` | 64 | 512 | `**` groups left to right (RapydScript emits `Math.pow(Math.pow(2, 3), 2)`). Python groups it right to left. |\n| `2**-1**2` | 0.25 | 0.5 | same |\n| `round(2.5)`, `round(-2.5)` | 3, -3 | 2, -2 | Halves round away from zero. Python rounds them to the even neighbour. |\n| `int(True)`, `True + 1` | error | 1, 2 | Booleans aren't treated as the integers 0 and 1. |\n| `log(e)` | error | 1 | `e` isn't defined (`pi` is). |\n| `a **= 2` | compile error | | \"Unexpected token: operator «=»\" |\n\nThe division-by-a-negative cases from #170, true and floor division, chained comparisons, `abs`/`min`/`max`/`sum`/`pow`/`sqrt`/`divmod`, `range` with negative steps, the trig and log functions, and integers up to 2\\*\\*52 all match Python.\n\nI also found a regression introduced by #170. Fixed with a test in #225. Before #170, the `\"-\" → \"-1*\"` rewrite hid a RapydScript bug: it printed `- -x` as `--x`, which in JavaScript is a decrement (wrong answer, and `x` changes). `- -3` didn't compile at all.\n\nRelated: #217 (refreshing the embedded RapydScript). I haven't checked which of these upstream RapydScript-NG has fixed; the `**` grouping is still the same at upstream `3e69ba8`.\n\nThe Trinket deploy suite pins these as known differences (PICUP-Physics/trinket-oss#369, `vpython-arithmetic.spec.js`), so a fix here will show up there.\n\n🤖 Generated with [Claude Code](https://claude.com/claude-code)\n","author":{"url":"https://github.com/sspickle","@type":"Person","name":"sspickle"},"datePublished":"2026-11-03T09:18:08Z","url":"https://github.com/vpython/glowscript/issues/224"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:c052ecef-e9bd-4446-18f9-5098f4b19616 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EE30:2642C6:350F55:4A76B1:6B006E90 |
| html-safe-nonce | b1be046c096db116671508e56bfb0c455a78e8b78c569eb812ea81b208ef2d2a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRTMwOjI2NDJDNjozNTBGNTU6NEE3NkIxOjZCMDA2RTkwIiwidmlzaXRvcl9pZCI6IjQ3NTQ4NTYyNjI5MzA1NTEyMCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | ff938e96b490d5f3debb5f097daa6e3b7e1a1e5d268ba2143ddc111b7c1e6c92 |
| hovercard-subject-tag | issue:6179654635 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/vpython/glowscript/224/issue_layout |
| twitter:image | https://opengraph.githubassets.com/24b7e2ca5f46cf40d418e67b8d9e909c9dd34287b461f8e1befd045702995b2d/vpython/glowscript/issues/224 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/24b7e2ca5f46cf40d418e67b8d9e909c9dd34287b461f8e1befd045702995b2d/vpython/glowscript/issues/224 |
| og:image:alt | While fixing #170 I ran a 122-expression arithmetic program through Web VPython 3.2 and compared every result with CPython. 107 match. The rest differ. All of these differences are older than #170:... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sspickle |
| hostname | github.com |
| expected-hostname | github.com |
| None | 6527e91c60c0b29d16606ff32ac5df8ecdc37a2a62205ea057a14d7762c870fa |
| turbo-cache-control | no-preview |
| go-import | github.com/vpython/glowscript git https://github.com/vpython/glowscript.git |
| octolytics-dimension-user_id | 1280757 |
| octolytics-dimension-user_login | vpython |
| octolytics-dimension-repository_id | 187905631 |
| octolytics-dimension-repository_nwo | vpython/glowscript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 187905631 |
| octolytics-dimension-repository_network_root_nwo | vpython/glowscript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 46f1cd2ae3cd8ae1a81019b5d619742e76f13bbd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width