aboutsummaryrefslogtreecommitdiff
path: root/lib/math
AgeCommit message (Collapse)Author
2026-01-15all: convert license and copyright to use SPDX identifiersShulhan
With help of spdxconv tool [1], we able to bulk update all files license and copyright format to comply with SPDX formats. [1] https://kilabit.info/project/spdxconv/
2025-02-04all: remove the nolint tagsShulhan
The "nolint" tag is used to ignore lines from being processed by golangci-lint. Since we are not using golangci-lint anymore, now and in the future, those lines can be removed.
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.
2024-03-02all: move the repository to "git.sr.ht/~shulhan/pakakeh.go"Shulhan
There are several reasons that why we move from github.com. First, related to the name of package. We accidentally name the package with "share" a common word in English that does not reflect the content of repository. By moving to other repository, we can rename it to better and unique name, in this "pakakeh.go". Pakakeh is Minang word for tools, and ".go" suffix indicate that the repository related to Go programming language. Second, supporting open source. The new repository is hosted under sourcehut.org, the founder is known to support open source, and all their services are licensed under AGPL, unlike GitHub that are closed sources. Third, regarding GitHub CoPilot. The GitHub Terms of Service [1], allow any public content that are hosted there granted them to parse the content. On one side, GitHub helps and flourish the open source, but on another side have an issues regarding scraping the copyleft license [2]. [1]: https://docs.github.com/en/site-policy/github-terms/github-terms-of-service#4-license-grant-to-us [2]: https://githubcopilotinvestigation.com
2023-12-13all: fix linter warnings reported by reviveShulhan
There are some reports that I disagree with revive, in example, code should not declare the type after variables. In my opinion, on some cases, declaring the type make the code more readable and explicit. Since I did not want to add new configuration file, we changes it and follow revive for now.
2023-09-11math/big: fix comment in CreateFloat and ParseFloatShulhan
2022-05-09all: reformat all codes using gofmt 1.19 (the Go tip)Shulhan
2022-04-06math/big: fix example on RoundToZeroShulhan
In latest Go release, calling Rat.SetString("-0") result in 0 instead of -0.
2021-12-03math/big: refactoring AddFloat to accept variadic interface{}Shulhan
Previously, the AddFloat function only accept two interface parameters. This changes make the AddFloat to accept many interface parameters.
2021-12-03math/big: refactor NewFloat to accept interface{} instead of float64 onlyShulhan
The following types is added and can be initialized to Float: []byte, uint, uint16, uint32, uint64, big.Int, *big.Int, big.Rat, and *big.Rat.
2021-11-19math/big: realign struct fields on unit testsShulhan
The following alignment reported and fixed by fieldaligment tool, float_test.go:103:13: struct with 16 pointer bytes could be 8 float_test.go:254:13: struct with 16 pointer bytes could be 8 big/float_test.go:302:13: struct with 32 pointer bytes could be 16
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-11-17math/big: return nil on Quo and QuoRat instead of panicShulhan
Previously, if the first parameter of Quo or the second/next parameters of QuoRat is not convertable to Rat or zero, the method/function will panic. This changes make it less intrunsive, instead of panic we check for zero value and return nil immediately.
2021-09-11math/big: add some examples of Rat.Int64() and RoundToNearestAwayShulhan
2021-04-27big: add method Add, IsLess, IsGreater, and ScanShulhan
The Add method simplify addition of one value to current Int. The IsLess and IsGreater method simplify comparing Int with any value. The Scan method allow the Int to be used on sql Scan().
2021-04-23math/big: add method IsZero on IntShulhan
The IsZero method will return true if the current i value is zero.
2021-04-23math/big: use consistent receiver name for Int methodsShulhan
2021-04-23math/big: extend Int to support marshal/unmarshal JSONShulhan
2021-04-21big: extends the standard big.IntShulhan
The standard big.Int does not implement sql/driver.Valuer interface, which make it not usable when querying or doing update/insert with database. This commit extend the big.Int and simplify creating new Int from any values using NewInt().
2021-04-16big: allow creating new Rat from uint64 and *big.IntShulhan
2021-03-14all: refactoring the test.Assert and test.AssertBench signatureShulhan
Previously, the test.Assert and test.AssertBench functions has the boolean parameter to print the stack trace of test in case its not equal. Since this parameter is not mandatory and its usually always set to "true", we remove them from function signature to simplify the call to Assert and AssertBench.
2021-03-01big: add method that implement sql/driver.Valuer for type RatShulhan
The Rat.Value() return the value as []byte.
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.
2021-01-06big: fix test due to changes on tip of json packageShulhan
To prevent the test error when running with different Go version, we use the strings.Contains to compare the error instead of using test.Assert directly.
2020-11-23test: refactoring Assert with better error messageShulhan
The new Assert function use the reflect.DoEqual that return an error which describe which field have unmatched value. This changes affect other test that use "false" as the last parameter.
2020-11-10big: update the latest expected error message with Go tipShulhan
The Go tip add prefix "json:" when there is an error on UnmarshalJSON.
2020-10-08big: add method RoundToNearestAway and RoundToZeroShulhan
RoundToNearestAway round r to n digit precision using nearest away mode, where mantissa is accumulated by the last digit after precision. For example, using 2 digit precision, 0.555 would become 0.56. RoundToZero round r to n digit precision using to zero mode. For example, using 2 digit precision, 0.555 would become 0.55.
2020-07-06big: add global flag MarshalJSONAsStringShulhan
MarshalJSONAsString define the default return behaviour of MarshalJSON(). If its true (the default) the returned JSON format will encapsulated in double quote, as string instead of as numeric.
2020-06-10all: update email addressShulhan
2020-06-06all: use default linter optionsShulhan
2020-05-12big: add method wrapper for AbsShulhan
2020-04-29big: check for zero length slice of byte or string on toRatShulhan
If the slice of byte or string is zero the returned Rat value will be 0.
2020-04-29big: return false if Rat is nil on IsGreaterThanZeroShulhan
2020-04-23reflect: remove checking for method IsEqual on type reflect.PtrShulhan
The check for method IsEqual only happened if type is struct. This changes affect the test on package math/big.
2020-04-23big: add more test cases for QuoRat and Int64Shulhan
2020-04-08big: return "0" instead of "<nil>" on Rat.String()Shulhan
2020-04-03big: update the test file from stashShulhan
2020-04-01big: round the float value using rounding mode ToZeroShulhan
2020-03-30big: add more test cases for RatShulhan
2020-03-26big: fix the Int64() method conversionShulhan
Turn out strconv.ParseInt will return an error when passing string with decimal separator, for example "1.1".
2020-03-26all: fix and suppress linter warningsShulhan
2020-03-23big: fix Rat conversion to int64Shulhan
Using Rat.Float64() and converting it to int64 cause some rounding issue on some number, for example result of multiply "4011144900.02438879" with 100000000.
2020-03-20big: new package that extends the capabilities of "math/big"Shulhan
The "big" package add custom global precision, rounding mode, and number of digit precision after decimal point for all instance of Float that use the package.
2020-03-12mining/math: move the package from "lib/mining/" to "lib/" directoryShulhan