Skip to content
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

feat: add math module for high precision computing #375

Closed
wants to merge 35 commits into from

Conversation

axetroy
Copy link
Contributor

@axetroy axetroy commented May 2, 2019

refs: #347 https://golang.org/pkg/math/big/
porting https://github.com/MikeMcl/big.js

Extra features: support BigInt as input params

This is a draft for high precision computing solution.

If you think this is a viable option, I will continue to complete the rest.

What content including this PR?

  1. Add Big module at Math/big/mod.ts

  2. Add common high-precision calculation methods. Base on Big module in Math/mod.ts.

    • plus(a, b)
    • minus(a, b)
    • mod(a, b)
    • abs(a)
    • round(value, dp, rm)
    • sqrt(value)
    • times(multiplicand, multiplier)
    • toExponential(value, dp)
    • toFixed(value, dp)
    • toPrecision(value, dp)
    • eq(a, b)
    • gt(a, b)
    • gte(a, b)
    • lt(a, b)
    • lte(a, b)
    • sum([ a, b, c, d, ... ])
    • min([ a, b, c, d, ... ])
    • max([ a, b, c, d, ... ])

Plan in the future

add complex sub-module for

  • sin
  • cos
  • tan
  • polar
  • rect
  • phase
  • ...and more

@@ -0,0 +1,864 @@
/************************************** EDITABLE DEFAULTS *****************************************/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please list where you've forked this code from, the license, author, and copyright header

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I add Deno copyright header behind the origin copyright header?

@axetroy axetroy changed the title feat: add math/big module feat: add math module May 3, 2019
@axetroy axetroy changed the title feat: add math module feat: add math module for high precision computing May 3, 2019
* big.js v5.2.2
* A small, fast, easy-to-use library for arbitrary-precision decimal arithmetic.
* Copyright (c) 2018 Michael Mclaughlin <[email protected]>
* https://github.com/MikeMcl/big.js/LICENCE
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This link is 404. Also please state the license "MIT License" in text.

I think this module might be better as an external one (deno.land/x) than in deno_std. The reason is that it's quite large and niche - which is going to slowly down my ability to review it. If you keep the same structure as deno_std, it can potentially be moved here later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, you only need to review the core module. It only has a few hundred lines of code

The test case is basically from big.js

It contains a large number of test cases to ensure the availability and stability of this package.

@axetroy axetroy marked this pull request as ready for review May 3, 2019 15:55
@j-f1
Copy link

j-f1 commented May 3, 2019

Would it make sense to import big.js directly from https://raw.githubusercontent.com/MikeMcl/big.js/master/big.mjs?

@axetroy
Copy link
Contributor Author

axetroy commented May 4, 2019

Would it make sense to import big.js directly from https://raw.githubusercontent.com/MikeMcl/big.js/master/big.mjs?

I have considered this issue too, but it has external dependencies, ie vendor/big.mjs

it seems not to meet the original intention of deno_std.

And we have to write declaration file for this.

Of course, this is also a way to do. Depends on community opinion

@axetroy
Copy link
Contributor Author

axetroy commented May 5, 2019

or we can wait for support d.ts file.
denoland/deno#1432 (comment)

In this case, we only need to introduce big.js and big.d.ts files. no more including test file.

@ry
Copy link
Member

ry commented May 6, 2019

Would it make sense to import big.js directly from https://raw.githubusercontent.com/MikeMcl/big.js/master/big.mjs

Links to external code isn't allowed in deno_std

@ry
Copy link
Member

ry commented May 10, 2019

I'd rather have this as an external module for now.

Please submit it to https://github.com/denoland/registry/blob/master/src/database.json

@ry ry closed this May 10, 2019
@axetroy
Copy link
Contributor Author

axetroy commented May 13, 2019

@axetroy axetroy deleted the math branch May 13, 2019 06:09
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.

3 participants