forked from TheAlgorithms/Go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: bitwise min * fix: bitwise min, change for vararg * fix: change min tests * fix: benchmark for bitwise * fix: rename tests * fix: add value param * fix: change condition * feat: added description to some functions * Updated Documentation in README.md * fix: change descriptions * Updated Documentation in README.md * Updated Documentation in README.md * Updated Documentation in README.md * feat: abs algo * Updated Documentation in README.md * fix: add comment * Updated Documentation in README.md * fix: new comment * Updated Documentation in README.md * fix: rename func and remove package * Updated Documentation in README.md * Update math/abs.go Co-authored-by: Taj <[email protected]> * Updated Documentation in README.md * Update math/binary/abs.go Co-authored-by: Taj <[email protected]> * Updated Documentation in README.md * fix: rename func and move binary test * add package description and add function name to comment * Updated Documentation in README.md * rename Intercept method to YIntercept * Updated Documentation in README.md * fix strings * Updated Documentation in README.md * fix commit * fix name cos tests and rename epsilon to epsilonCos * feat: sin * Updated Documentation in README.md * fix test for sin * fix epsilon * rename package to test * fix afte review Co-authored-by: Rak Laptudirm <[email protected]> Co-authored-by: github-action <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: Taj <[email protected]>
- Loading branch information
1 parent
bd8e6d5
commit 628336b
Showing
4 changed files
with
65 additions
and
9 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
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
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,11 @@ | ||
// author(s) [red_byte](https://github.com/i-redbyte) | ||
// see sin_test.go | ||
|
||
package math | ||
|
||
import "math" | ||
|
||
// Sin returns the sine of the radian argument x. [See more](https://en.wikipedia.org/wiki/Sine_and_cosine) | ||
func Sin(x float64) float64 { | ||
return Cos((math.Pi / 2) - x) | ||
} |
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,43 @@ | ||
package math_test | ||
|
||
import ( | ||
algmath "github.com/TheAlgorithms/Go/math" | ||
stdmath "math" | ||
"testing" | ||
) | ||
|
||
func TestSin(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
n float64 | ||
want float64 | ||
}{ | ||
{"sin(0)", 0, 0}, | ||
{"sin(3π/2)", (3 * stdmath.Pi) / 2, -1}, | ||
{"sin(π/2)", stdmath.Pi / 2, 1}, | ||
{"sin(π/6)", stdmath.Pi / 6, 0.5}, | ||
{"sin(90)", 90, 0.893996663600558}, | ||
} | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
got := algmath.Sin(test.n) | ||
if stdmath.Abs(got-test.want) >= epsilon { | ||
t.Errorf("Sin() = %v, want %v", got, test.want) | ||
t.Errorf("MATH Sin() = %v", stdmath.Sin(test.n)) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func BenchmarkSin(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
algmath.Sin(180) | ||
} | ||
} | ||
|
||
// BenchmarkMathSin is slower because the standard library `math.Sin` calculates a more accurate value. | ||
func BenchmarkMathSin(b *testing.B) { | ||
for i := 0; i < b.N; i++ { | ||
stdmath.Sin(180) | ||
} | ||
} |