-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sdk): adding tau, hypot, angular conversion, sec, csc, cot, asec…
…, acsc, acot to math module (#3227) Fix #3210 ## Checklist - [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [ ] 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://www.winglang.io/terms-and-policies/contribution-license.html)*.
- Loading branch information
1 parent
52a7dcb
commit e963c26
Showing
32 changed files
with
2,501 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
bring math; | ||
// TODO: need to handle NaN https://github.com/winglang/wing/issues/3210 | ||
// assert(math.acos(-2) == NaN); | ||
try { | ||
log("${math.acos(-2)}"); | ||
} catch e { | ||
assert(e == "Input value must be between -1 and 1, inclusive."); | ||
} | ||
assert(math.acos(-1) == math.PI); | ||
assert(math.acos(-0) == 1.5707963267948966); | ||
assert(math.acos(0) == 1.5707963267948966); | ||
assert(math.acos(0.5) == 1.0471975511965979); | ||
assert(math.acos(1) == 0); | ||
// TODO: need to handle NaN https://github.com/winglang/wing/issues/3210 | ||
// assert(math.acos(2) == NaN); | ||
try { | ||
log("${math.acos(2)}"); | ||
} catch e { | ||
assert(e == "Input value must be between -1 and 1, inclusive."); | ||
} | ||
|
||
test "inflight arc cosine" { | ||
// TODO: need to handle NaN | ||
// assert(math.acos(-2) == NaN); | ||
try { | ||
log("${math.acos(-2)}"); | ||
} catch e { | ||
assert(e == "Input value must be between -1 and 1, inclusive."); | ||
} | ||
assert(math.acos(-1) == math.PI); | ||
assert(math.acos(-0) == 1.5707963267948966); | ||
assert(math.acos(0) == 1.5707963267948966); | ||
assert(math.acos(0.5) == 1.0471975511965979); | ||
assert(math.acos(1) == 0); | ||
// TODO: need to handle NaN https://github.com/winglang/wing/issues/3210 | ||
// assert(math.acos(2) == NaN); | ||
try { | ||
log("${math.acos(2)}"); | ||
} catch e { | ||
assert(e == "Input value must be between -1 and 1, inclusive."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
bring math; | ||
|
||
assert(math.acot(0) == 1.5707963267948966); | ||
assert(math.acot(math.PI / 2) == 0.5669115049410094); | ||
assert(math.acot(math.PI) == 0.30816907111598496); | ||
assert(math.acot(math.TAU) == 0.15783119028815887); | ||
assert(math.acot(-0) == -1.5707963267948966); | ||
|
||
test "inflight arc cotgent" { | ||
assert(math.acot(0) == 1.5707963267948966); | ||
assert(math.acot(math.PI / 2) == 0.5669115049410094); | ||
assert(math.acot(math.PI) == 0.30816907111598496); | ||
assert(math.acot(math.TAU) == 0.15783119028815887); | ||
assert(math.acot(-0) == -1.5707963267948966); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
bring math; | ||
|
||
try { | ||
log("${math.acsc(0.5)}"); | ||
} catch e { | ||
assert(e == "Input value must be equal or greater than |1|."); | ||
} | ||
assert(math.acsc(1) == 1.5707963267948966); | ||
assert(math.acsc(math.PI / 2) == 0.69010709137454); | ||
assert(math.acsc(math.PI) == 0.3239461069319807); | ||
assert(math.acsc(math.TAU) == 0.15983462638513704); | ||
assert(math.acsc(-1) == -1.5707963267948966); | ||
|
||
test "inflight arc cosecant" { | ||
try { | ||
log("${math.acsc(0.5)}"); | ||
} catch e { | ||
assert(e == "Input value must be equal or greater than |1|."); | ||
} | ||
assert(math.acsc(1) == 1.5707963267948966); | ||
assert(math.acsc(math.PI / 2) == 0.69010709137454); | ||
assert(math.acsc(math.PI) == 0.3239461069319807); | ||
assert(math.acsc(math.TAU) == 0.15983462638513704); | ||
assert(math.acsc(-1) == -1.5707963267948966); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
bring math; | ||
|
||
assert(math.degreesToRadians(360) == math.TAU); | ||
assert(math.degreesToRadians(180) == math.PI); | ||
assert(math.degreesToRadians(90) == math.PI / 2); | ||
assert(math.degreesToRadians(60) == math.PI / 3); | ||
assert(math.degreesToRadians(45) == math.PI / 4); | ||
assert(math.degreesToRadians(30) == math.PI / 6); | ||
|
||
assert(math.radiansToDegrees(math.TAU) == 360); | ||
assert(math.radiansToDegrees(math.PI) == 180); | ||
assert(math.radiansToDegrees(math.PI / 2) == 90); | ||
assert(math.round(math.radiansToDegrees(math.PI / 3)) == 60); | ||
assert(math.radiansToDegrees(math.PI / 4) == 45); | ||
assert(math.round(math.radiansToDegrees(math.PI / 6)) == 30); | ||
|
||
test "inflight angular conversions" { | ||
assert(math.degreesToRadians(360) == math.TAU); | ||
assert(math.degreesToRadians(180) == math.PI); | ||
assert(math.degreesToRadians(90) == math.PI / 2); | ||
assert(math.degreesToRadians(60) == math.PI / 3); | ||
assert(math.degreesToRadians(45) == math.PI / 4); | ||
assert(math.degreesToRadians(30) == math.PI / 6); | ||
|
||
assert(math.radiansToDegrees(math.TAU) == 360); | ||
assert(math.radiansToDegrees(math.PI) == 180); | ||
assert(math.radiansToDegrees(math.PI / 2) == 90); | ||
assert(math.round(math.radiansToDegrees(math.PI / 3)) == 60); | ||
assert(math.radiansToDegrees(math.PI / 4) == 45); | ||
assert(math.round(math.radiansToDegrees(math.PI / 6)) == 30); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
bring math; | ||
|
||
try { | ||
log("${math.asec(0.5)}"); | ||
} catch e { | ||
assert(e == "Input value must be equal or greater than |1|."); | ||
} | ||
assert(math.asec(2) == 1.0471975511965979); | ||
assert(math.asec(1) == 0); | ||
assert(math.asec(math.PI) == 1.2468502198629159); | ||
assert(math.asec(-math.PI) == 1.8947424337268775); | ||
assert(math.asec(-1) == math.PI); | ||
assert(math.asec(-2) == 2.0943951023931957); | ||
|
||
test "inflight arc cosecant" { | ||
try { | ||
log("${math.asec(0.5)}"); | ||
} catch e { | ||
assert(e == "Input value must be equal or greater than |1|."); | ||
} | ||
assert(math.asec(2) == 1.0471975511965979); | ||
assert(math.asec(1) == 0); | ||
assert(math.asec(math.PI) == 1.2468502198629159); | ||
assert(math.asec(-math.PI) == 1.8947424337268775); | ||
assert(math.asec(-1) == math.PI); | ||
assert(math.asec(-2) == 2.0943951023931957); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,34 @@ | ||
bring math; | ||
// TODO: need to handle NaN https://github.com/winglang/wing/issues/3210 | ||
// assert(math.asin(-2) == NaN); | ||
try { | ||
log("${math.asin(-2)}"); | ||
} catch e { | ||
assert(e == "Input value must be between -1 and 1, inclusive."); | ||
} | ||
assert(math.asin(-1) == -1.5707963267948966); | ||
assert(math.asin(-0) == -0); | ||
assert(math.asin(0) == 0); | ||
assert(math.asin(0.5) == 0.5235987755982989); | ||
assert(math.asin(1) == 1.5707963267948966); | ||
// TODO: need to handle NaN https://github.com/winglang/wing/issues/3210 | ||
// assert(math.asin(2) == NaN); | ||
try { | ||
log("${math.asin(2)}"); | ||
} catch e { | ||
assert(e == "Input value must be between -1 and 1, inclusive."); | ||
} | ||
|
||
test "inflight arc sine" { | ||
// TODO: need to handle NaN | ||
// assert(math.asin(-2) == NaN); | ||
try { | ||
log("${math.asin(-2)}"); | ||
} catch e { | ||
assert(e == "Input value must be between -1 and 1, inclusive."); | ||
} | ||
assert(math.asin(-1) == -1.5707963267948966); | ||
assert(math.asin(-0) == -0); | ||
assert(math.asin(0) == 0); | ||
assert(math.asin(0.5) == 0.5235987755982989); | ||
assert(math.asin(1) == 1.5707963267948966); | ||
// TODO: need to handle NaN https://github.com/winglang/wing/issues/3210 | ||
// assert(math.asin(2) == NaN); | ||
try { | ||
log("${math.asin(2)}"); | ||
} catch e { | ||
assert(e == "Input value must be between -1 and 1, inclusive."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
bring math; | ||
|
||
assert(math.cot(0) == math.INF); | ||
assert(math.round(math.cot(math.PI / 4)) == 1); | ||
assert(math.round(math.cot(math.PI * 3 / 4)) == -1); | ||
assert(math.cot(-0) == -math.INF); | ||
|
||
test "inflight cotangent" { | ||
assert(math.cot(0) == math.INF); | ||
assert(math.round(math.cot(math.PI / 4)) == 1); | ||
assert(math.round(math.cot(math.PI * 3 / 4)) == -1); | ||
assert(math.cot(-0) == -math.INF); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
bring math; | ||
|
||
assert(math.csc(-0) == -math.INF); | ||
assert(math.csc(0) == math.INF); | ||
assert(math.csc(1) == 1.1883951057781212); | ||
assert(math.csc(-5) == 1.0428352127714058); | ||
assert(math.csc(math.PI / 2) == 1); | ||
assert(math.csc(math.TAU / 4) == 1); | ||
assert(math.csc(math.PI * 3 / 2) == -1); | ||
assert(math.csc(math.TAU * 3 / 4) == -1); | ||
|
||
test "inflight cosecant" { | ||
assert(math.csc(-0) == -math.INF); | ||
assert(math.csc(0) == math.INF); | ||
assert(math.csc(1) == 1.1883951057781212); | ||
assert(math.csc(-5) == 1.0428352127714058); | ||
assert(math.csc(math.PI / 2) == 1); | ||
assert(math.csc(math.TAU / 4) == 1); | ||
assert(math.csc(math.PI * 3 / 2) == -1); | ||
assert(math.csc(math.TAU * 3 / 4) == -1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
bring math; | ||
|
||
assert(math.hypot([3, 4]) == 5); | ||
assert(math.hypot([5, 12]) == 13); | ||
assert(math.round(math.hypot([3, 4, 5]), decimalPlaces: 2) == 7.07); | ||
assert(math.hypot([-5]) == 5); | ||
|
||
test "inflight hypot" { | ||
assert(math.hypot([3, 4]) == 5); | ||
assert(math.hypot([5, 12]) == 13); | ||
assert(math.round(math.hypot([3, 4, 5]), decimalPlaces: 2) == 7.07); | ||
assert(math.hypot([-5]) == 5); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
bring math; | ||
|
||
assert(math.sec(-0) == 1); | ||
assert(math.sec(0) == 1); | ||
assert(math.sec(1) == 1.8508157176809255); | ||
assert(math.sec(-5) == 3.5253200858160887); | ||
assert(math.sec(math.PI) == -1); | ||
assert(math.sec(math.TAU) == 1); | ||
|
||
test "inflight secant" { | ||
assert(math.sec(-0) == 1); | ||
assert(math.sec(0) == 1); | ||
assert(math.sec(1) == 1.8508157176809255); | ||
assert(math.sec(-5) == 3.5253200858160887); | ||
assert(math.sec(math.PI) == -1); | ||
assert(math.sec(math.TAU) == 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
bring math; | ||
|
||
assert(math.TAU / 4 == math.PI / 2); | ||
assert(math.TAU / 2 == math.PI); | ||
assert(math.TAU * 3 / 4 == math.PI * 3 / 2); | ||
assert(math.TAU == math.PI * 2); | ||
|
||
test "TAU" { | ||
assert(math.TAU / 4 == math.PI / 2); | ||
assert(math.TAU / 2 == math.PI); | ||
assert(math.TAU * 3 / 4 == math.PI * 3 / 2); | ||
assert(math.TAU == math.PI * 2); | ||
} |
Oops, something went wrong.