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(sdk): adding math module #3114

Merged
merged 24 commits into from
Jul 2, 2023
Merged

feat(sdk): adding math module #3114

merged 24 commits into from
Jul 2, 2023

Conversation

marciocadev
Copy link
Collaborator

@marciocadev marciocadev commented Jun 27, 2023

I had a little trouble with the min and max because JSii didn't accept the methods to receive Set<number>.
When I tried to use number[] and use it in the Wing code, it only accepted arrays.
I ended up using any, but I wasn't very satisfied.

@eladb, I took the liberty of adding a few more functions to the module, such as round and I noticed that you placed random and randomInt in the Util module, but I wonder if they should be part of the Math module instead.

preflight inflight min(arr: Set<num>): num;
preflight inflight max(arr: Set<num>): num;
preflight inflight abs(value: num): num;
preflight inflight floor(value: num): num;
preflight inflight ceil(value: num): num;

// adding to the specs
preflight inflight math.PI; // PI constant
preflight inflight math.E; // Euler's number
preflight inflight isPrimen: num): bool;
preflight inflight round(value: num, decimalPlaces?: num): num;
preflight inflight median(arr: Array<num>): num;
preflight inflight mode(arr: Array<num>): Array<num>;
preflight inflight arithmeticMean(arr: Array<num>): num;
preflight inflight geometricMean(arr: Array<num>): num;
preflight inflight harmonicMean(arr: Array<num>): num;
preflight inflight fibonacci(n: num): num;
preflight inflight factorial(n: num): num;
preflight inflight combinations(n: num, r: num): num;

Checklist

  • Title matches Winglang's style guide
  • Description explains motivation and solution
  • Tests added (always)
  • Docs updated (only required for features)
  • Added pr/e2e-full label if this feature requires end-to-end testing

By submitting this pull request, I confirm that my contribution is made under the terms of the Monada Contribution License.

@marciocadev marciocadev requested a review from a team as a code owner June 27, 2023 23:37
@marciocadev marciocadev requested a review from eladb June 28, 2023 01:57
libs/wingsdk/src/math/math.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/math/math.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/math/math.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/math/math.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/math/math.ts Outdated Show resolved Hide resolved
libs/wingsdk/src/math/math.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

Great job!

@mergify
Copy link
Contributor

mergify bot commented Jul 2, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit c845674 into main Jul 2, 2023
11 checks passed
@mergify mergify bot deleted the marciocadev/math-module branch July 2, 2023 05:42
@monadabot
Copy link
Contributor

Congrats! 🚀 This was released in Wing 0.23.7.

revitalbarletz pushed a commit that referenced this pull request Jul 3, 2023
I had a little trouble with the `min` and `max` because JSii didn't accept the methods to receive `Set<number>`.
When I tried to use `number[]` and use it in the Wing code, it only accepted arrays.
I ended up using `any`, but I wasn't very satisfied.

@eladb, I took the liberty of adding a few more functions to the module, such as `round` and I noticed that you placed `random` and `randomInt` in the `Util` module, but I wonder if they should be part of the `Math` module instead.

```ts
preflight inflight min(arr: Set<num>): num;
preflight inflight max(arr: Set<num>): num;
preflight inflight abs(value: num): num;
preflight inflight floor(value: num): num;
preflight inflight ceil(value: num): num;

// adding to the specs
preflight inflight math.PI; // PI constant
preflight inflight math.E; // Euler's number
preflight inflight isPrimen: num): bool;
preflight inflight round(value: num, decimalPlaces?: num): num;
preflight inflight median(arr: Array<num>): num;
preflight inflight mode(arr: Array<num>): Array<num>;
preflight inflight arithmeticMean(arr: Array<num>): num;
preflight inflight geometricMean(arr: Array<num>): num;
preflight inflight harmonicMean(arr: Array<num>): num;
preflight inflight fibonacci(n: num): num;
preflight inflight factorial(n: num): num;
preflight inflight combinations(n: num, r: num): num;
```

## Checklist

- [x] Title matches [Winglang's style guide](https://docs.winglang.io/contributing/pull_requests#how-are-pull-request-titles-formatted)
- [x] Description explains motivation and solution
- [x] Tests added (always)
- [ ] Docs updated (only required for features)
- [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing

*By submitting this pull request, I confirm that my contribution is made under the terms of the [Monada Contribution License](https://docs.winglang.io/terms-and-policies/contribution-license.html)*.
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