-
-
Notifications
You must be signed in to change notification settings - Fork 903
docs: Elevate sin()
docs with refined examples & well-defined constraints
#6347
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
Conversation
This is my very first pull request to stdlib-js/stdlib, and I’m super excited to contribute to such an amazing project! I’ve updated the REPL documentation for the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why you commented out the entire file!?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about that! I'm working on the sin
function in JavaScript, and since I'm a beginner, I accidentally commented out the test.js
file. I'm starting with the documentation updates first and will move on to the implementation next. Thanks for understanding!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is completely not what's desired. You should follow the same coding conventions used in the other repl.txt
files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your feedback! I appreciate it and will update the file to follow the same coding conventions as the other repl.txt
files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was this change made?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change was made as I started updating the documentation present in stdlib\lib\node_modules@stdlib\math\base\special\sin\docs\repl.txt. I updated the examples to use exact values wherever possible to improve accuracy and clarity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I meant the renaming of the files.
I updated the |
… and more features
sin()
docs with refined examples & well-defined constraints
Notes | ||
----- | ||
- The sine function is periodic with a period of 2π (approximately 6.28 radians), so `sin(x) = sin(x % 6.28)`. | ||
- The function satisfies the identity `sin(-x) = -sin(x)`. | ||
- Useful for smooth game movements, sound wave adjustments, and geometric calculations. | ||
- To convert degrees to radians, multiply by π/180 (e.g., `sin(60 * 3.14 / 180) ≈ 0.8660` for 60 degrees). | ||
- For repeated calculations, store the result to avoid recomputing (e.g., `let h = sin(1.5)`). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is just general information about sin
and not anything specific to the implementation. Usually, if there are any notes, they are most likely from the reference implementations followed.
cos( x ): Computes the cosine, a related trigonometric function. | ||
tan( x ): Computes the tangent, useful for slopes. | ||
{{alias:@stdlib/constants/float64/pi}}: The constant π (approximately 3.14159). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary as these are populated automatically.
Just run the REPL using make repl
and type help(base.sin)
.
* // returns 0.0 | ||
* | ||
* @example | ||
* // Sine of π/2 radians (90 degrees), where sine reaches its maximum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these examples are already self-explanatory, so no additional comments are needed.
> y = sin( 3 * {{alias:@stdlib/constants/float64/pi}} / 2.0 ) | ||
-1.0 | ||
|
||
> // Simulate a fading light effect: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, but none of this adheres to the coding conventions.
@ishikajais27 Thanks for your contributions to this! However, I don’t think any of this is necessary. If you're considering introducing a new change or improvement, it's always a good idea to first create an issue and share your thoughts there. Alternatively, you can join the Gitter public channel to get feedback. cc: @kgryte |
@ishikajais27 Please refrain from using generative AI when first contributing to stdlib. None of your proposed changes are desired, nor do they adhere to our conventions. If you are interested in contributing to the project, I suggest you spend a fair amount of time actually studying the codebase and learning our approach to package development. You should also get acquainted with our development guide. |
docs: precision documentation update for sin() function
This PR enhances the documentation for
@stdlib/math/base/special/sin
by providing clearer, more accurate examples and additional features. It updates both the REPL documentation (repl.txt
) and the TypeScript declaration file (index.d.ts
).Key Improvements
REPL Documentation (
repl.txt
)Parameters
,Returns
,Examples
, andSee Also
sections, preserving useful content like code snippets.~0.0
to0.0
forsin(0)
, updatedsin(0.785)
to~0.7071
for precision, and ensured all examples show precise results.sin(2π) → 0.0
(periodicity),sin(π/3) → ~0.8660
(60 degrees), andsin(-π) → 0.0
(symmetry).sin(1e308) → NaN
,sin(-1e308) → NaN
,sin(1e-308) → ~1e-308
,sin(-0.0) → -0.0
, andsin(3π/2) → -1.0
.TypeScript Declaration (
index.d.ts
)~0.0
to0.0
,~1.0
to1.0
, and~-0.5
to-0.5
in examples.sin(π) → 0.0
,sin(π/4) → ~0.7071
,sin(π/3) → ~0.8660
, andsin(3π/2) → -1.0
.sin(-0.0) → -0.0
,sin(1e-308) → ~1e-308
,sin(1e308) → NaN
, andsin(-Infinity) → NaN
.x
should be finite for meaningful results, with potential precision loss for large inputs.Infinity
/NaN
. Included TypeScript snippets for pulsating effects and wave generation, plus comprehensive test cases with clear comments.Test These Examples
REPL Examples
JavaScript