-
-
Notifications
You must be signed in to change notification settings - Fork 904
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
Changes from 2 commits
4757742
52ae09a
ef73843
909a027
7926ec6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,84 @@ | ||
# sin(x) - Your Chill Math Buddy | ||
|
||
{{alias}}( x ) | ||
Computes the sine of a number. | ||
|
||
Parameters | ||
---------- | ||
x: number | ||
Input value (in radians). | ||
|
||
Returns | ||
------- | ||
y: number | ||
Sine. | ||
|
||
Examples | ||
-------- | ||
> var y = {{alias}}( 0.0 ) | ||
~0.0 | ||
> y = {{alias}}( {{alias:@stdlib/constants/float64/pi}}/2.0 ) | ||
~1.0 | ||
> y = {{alias}}( -{{alias:@stdlib/constants/float64/pi}}/6.0 ) | ||
~-0.5 | ||
> y = {{alias}}( NaN ) | ||
NaN | ||
|
||
See Also | ||
-------- | ||
Hey! Sine takes an angle and gives you a number—like a height on a circle. Great for coding, music, or math fun. Let’s check it out! | ||
|
||
--- | ||
|
||
## What You Give It | ||
|
||
- **x**: a number | ||
Angle in radians (not degrees—a full spin’s about 6.28). Works with any number, even `NaN` or infinity. | ||
|
||
## What You Get Back | ||
|
||
- **y**: a number | ||
Between -1 and 1. `NaN` if `x` is weird. | ||
|
||
## What It’s Good For | ||
|
||
- Smooth game moves | ||
- Sound tweaks | ||
- Shape math | ||
|
||
--- | ||
__________________________________________________________________________ | ||
## Give These a Go | ||
|
||
- `sin(0.0)` → `0.0` (no turn) | ||
- `sin( {{alias:@stdlib/constants/float64/pi}} / 2 )` → `1.0` (90°—top!) | ||
- `sin( -{{alias:@stdlib/constants/float64/pi}} / 6 )` → `-0.5` (-30° dip) | ||
- `sin( 0.785 )` → ~`0.707` (45°—even) | ||
- `sin( {{alias:@stdlib/constants/float64/pi}} )` → `0.0` (half spin) | ||
- `sin( Infinity )` → `NaN` (too big!) | ||
|
||
--- | ||
__________________________________________________________________________ | ||
## Fun Code to Try | ||
|
||
### For C Folks | ||
code-> | ||
- **Add**: `#include <math.h>` | ||
- **Bounce a Ball**: | ||
```c | ||
#include <math.h> | ||
#include <stdio.h> | ||
int main() { | ||
for (int step = 0; step < 5; step++) { | ||
printf("Height %d: %.2f\n", step, sin(step * 0.5)); | ||
} | ||
return 0; | ||
} | ||
|
||
gcc file.c -lm—prints 0.00, 0.48, 0.91... | ||
______________________________________________________________________ | ||
### For JavaScript Folks | ||
Use: Math.sin() | ||
Fade a Light: | ||
code-> | ||
for (let time = 0; time < 5; time += 0.5) { | ||
let glow = (Math.sin(time) + 1) / 2; | ||
console.log(`Glow ${time}: ${glow.toFixed(2)}`); | ||
} | ||
output-> | ||
Shows 0.50, 0.73, 0.91—smooth! | ||
__________________________________________________________________ | ||
Extra: Mix Waves | ||
code-> | ||
let mix = Math.sin(1.5) + Math.sin(2.5); | ||
console.log("Wave mix:", mix.toFixed(3)); // ~ -0.589 | ||
__________________________________________________________________ | ||
Quick Bits | ||
Loops: Repeats every 6.28. sin(100) = sin(100 % 6.28). | ||
Flips: sin(-x) = -sin(x). | ||
Stays Simple: -1 to 1 only. | ||
Spot-On: sin(π/2) = 1, sin(0) = 0. | ||
___________________________________________________________________ | ||
Easy Tips | ||
Degrees?: Multiply by 3.14 / 180. sin(60 * 3.14 / 180) ≈ 0.866. | ||
Save It: Store repeats—like let h = sin(1.5). | ||
Handy: sin(3.14 / 3) ≈ 0.866 (60°). | ||
___________________________________________________________________ | ||
Other Pals | ||
cos(x): Wave teammate. | ||
tan(x): Slope helper. | ||
{{alias:@stdlib/constants/float64/pi}}: 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.
Why was this change made?
Uh oh!
There was an error while loading. Please reload this page.
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.