aboutsummaryrefslogtreecommitdiff
path: root/lib/math/big/rat_example_test.go
AgeCommit message (Collapse)Author
2025-01-23all: replace "interface{}" with "any"Shulhan
2024-03-06all: conform with linter gosec, ineffasign, and makezeroShulhan
Some of warnings from those linter are false positives, so we just annotated them.
2024-03-05all: comply with linter recommendations #3Shulhan
For HTTP server that use TLS, set the minimum TLS version and ReadHeaderTimeout to mitigate slowloris attack. For HTTP client or server that parameterize the use of InsecureSkipVerify, annotate the line with "nolint:gosec" to allow the code pass the check. Library that still use sha1, in example in DKIM and TOTP, skip the warnings by annotating the line with "nolint:gosec". A pointer variable now allocated their address before assigning its value. Any error that returned now wrapped using "%w". Also, replace error checking using [errors.Is] or [errors.As] instead of using equal or not-equal operators. In "lib/http", replace any usage of "math/rand" with "crypto/rand". Any call of [math/big.Rat.SetString] now annotated with "nolint:gosec" since its false positive, the issue has been fixed in Go >= 1.17.7. Any switch case that does not cover the rest of the possible values now handled by adding the cases or by replacing the "default" case with the rest of values.
2024-03-05all: comply with linter recommendations #2Shulhan
HTTP request now implicitly create request with context. Any false positive related to not closing HTTP response body has been annotated with "nolint:bodyclose". In the example code, use consistent "// Output:" comment format, by prefixing with single space. Any comment on code now also prefixing with single space. An error returned without variables now use [errors.New] instead of [fmt.Errorf]. Any error returned using [fmt.Errorf] now wrapped using "%w" instead of "%s". Also, replace error checking using [errors.Is] or [errors.As], instead of using equal/not-equal operator. Any statement like "x = x OP y" now replaced with "x OP= y". Also, swap statement is simplified using "x, y = y, x". Any switch statement with single case now replaced with if-condition. Any call to defer on function or program that call [os.Exit], now replaced by calling the deferred function directly. Any if-else condition now replaced with switch statement, if possible.
2022-04-06math/big: fix example on RoundToZeroShulhan
In latest Go release, calling Rat.SetString("-0") result in 0 instead of -0.
2021-11-19math/big: refactoring the RatShulhan
The promise of this package is to provide the Rat type with RoundToZero and without panic. In order to do that we remove the MustRat() function and check for nil on pointer receiver before doing operation, and check for zero value when doing quotation. Another breaking changes are, * Humanize() with nil pointer receiver will return string "0" * Any IsXxx() methods with nil pointer receiver will return false * MarshalJSON() will nil pointer receiver will return "null" instead of "0" now
2021-09-11math/big: add some examples of Rat.Int64() and RoundToNearestAwayShulhan
2021-02-05big: add method to round fraction to nearest non-zero valueShulhan
The RoundNearestFraction does not require precision parameter, like in other rounds function, but it figure it out based on the last non-zero value from fraction.
2021-02-05big: move the unit test of RoundtoNearestAway as exampleShulhan
By doing this we got unit test and example in documentation.
2021-02-03big: add method HumanizeShulhan
The Humanize method return the r as string with custom thousand and decimal separator.