Title: BREAKING CHANGE: Unify Math & Mathf. Make every method in Math polymorphic by MaxGraey · Pull Request #2335 · AssemblyScript/assemblyscript · GitHub
Open Graph Title: BREAKING CHANGE: Unify Math & Mathf. Make every method in Math polymorphic by MaxGraey · Pull Request #2335 · AssemblyScript/assemblyscript
X Title: BREAKING CHANGE: Unify Math & Mathf. Make every method in Math polymorphic by MaxGraey · Pull Request #2335 · AssemblyScript/assemblyscript
Description: In this PR we're doing several breaking changes:
move all detailed implementations to std/util/math
make all Math's methods polymorphic
remove non-standard NativeMath#scalebn
remove non-standard NativeMath#rem
remove non-standard NativeMath#mod (but not tests)
remove NativeMathf completely
for now, we have only single Math.random (for f64 type)
Caveats:
I have observed quite often the script that users from JS for example:
function foo(x: i32, y: i32): i32 {
let res = Math.floor(x / y) as i32;
return res;
}
Before this PR this will create unnecessary cast to f64, Math.floor and downcast to i32. With this PR this code now equivalent to x / y without all this unnecessary work due to Math.floor, Math.trunc and etc accept integers and pass through it "as is".
Now following code will generate a compilation error:
const cos3 = Math.cos(3);
// -> ERROR: Math.cos accept only f32 or f64 types
// Solution: it may be fixed as Math.cos(3.0)
const x: i32 = 123;
const sqr = Math.sqrt(x);
// -> ERROR: Math.sqrt accept only f32 or f64 types
// Solution: Math.sqrt(x as f64)
This is the most painful caveat, which can lead to many breaking changes in some code.
Perhaps we could add new generic builtin helper which forces parameter type to float. Something like:
// builtin will be equivalent to this:
type OnlyFloat
Open Graph Description: In this PR we're doing several breaking changes: move all detailed implementations to std/util/math make all Math's methods polymorphic remove non-standard NativeMath#scalebn remove non-st...
X Description: In this PR we're doing several breaking changes: move all detailed implementations to std/util/math make all Math's methods polymorphic remove non-standard NativeMath#scalebn remov...
Opengraph URL: https://github.com/AssemblyScript/assemblyscript/pull/2335
X: @github
Domain: patch-diff.githubusercontent.com
| route-pattern | /:user_id/:repository/pull/:id/checks(.:format) |
| route-controller | pull_requests |
| route-action | checks |
| fetch-nonce | v2:d93ad266-58be-3529-17f4-68785775bad6 |
| current-catalog-service-hash | 87dc3bc62d9b466312751bfd5f889726f4f1337bdff4e8be7da7c93d6c00a25a |
| request-id | 82FE:2AE61:7C791C5:A5C1398:696DFC8F |
| html-safe-nonce | 509e9c936c858049536fef84bbfa5b894573a06f7273e5f81e7ffc2b01e14334 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MkZFOjJBRTYxOjdDNzkxQzU6QTVDMTM5ODo2OTZERkM4RiIsInZpc2l0b3JfaWQiOiI3NTk5ODI2ODI1MzgyODUzNzc1IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | bb135eb275ea3ca9a50b0e1817b0fc0868890de1cc1d6e664a621b977050e745 |
| hovercard-subject-tag | pull_request:978730091 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,checks,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/AssemblyScript/assemblyscript/pull/2335/checks |
| twitter:image | https://avatars.githubusercontent.com/u/1301959?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/1301959?s=400&v=4 |
| og:image:alt | In this PR we're doing several breaking changes: move all detailed implementations to std/util/math make all Math's methods polymorphic remove non-standard NativeMath#scalebn remove non-st... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4922b452d03cd8dbce479d866a11bc25b59ef6ee2da23aa9b0ddefa6bd4d0064 |
| turbo-cache-control | no-preview |
| go-import | github.com/AssemblyScript/assemblyscript git https://github.com/AssemblyScript/assemblyscript.git |
| octolytics-dimension-user_id | 28916798 |
| octolytics-dimension-user_login | AssemblyScript |
| octolytics-dimension-repository_id | 105138356 |
| octolytics-dimension-repository_nwo | AssemblyScript/assemblyscript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 105138356 |
| octolytics-dimension-repository_network_root_nwo | AssemblyScript/assemblyscript |
| turbo-body-classes | logged-out env-production page-responsive full-width full-width-p-0 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7e5ae23c70136152637ceee8d6faceb35596ec46 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width