[
  {
    "path": ".github/workflows/go.yml",
    "content": "on:\n  push:\n    branches: [main]\n  pull_request:\n    branches: [main]\nname: decimal\njobs:\n  test:\n    strategy:\n      matrix:\n        go-version: [oldstable, stable]\n        os: [ubuntu-latest, windows-latest, macos-latest]\n    runs-on: ${{ matrix.os }}\n    steps:\n      - name: Setup Go\n        uses: actions/setup-go@v5\n        with:\n          go-version: ${{ matrix.go-version }}\n          cache: false\n\n      - name: Check out code\n        uses: actions/checkout@v4\n\n      - name: Verify code formatting\n        run: gofmt -s -w . && git diff --exit-code\n\n      - name: Verify dependency consistency\n        run: go get -u -t . && go mod tidy && git diff --exit-code\n\n      - name: Verify generated code\n        run: go generate ./... && git diff --exit-code\n\n      - name: Verify potential issues\n        uses: golangci/golangci-lint-action@v6\n\n      - name: Run tests with coverage\n        run: go test -race -shuffle=on -coverprofile=\"coverage.txt\" -covermode=atomic ./...\n\n      - name: Upload test coverage\n        if: matrix.os == 'ubuntu-latest' && matrix.go-version == 'stable'\n        uses: codecov/codecov-action@v4\n\n  fuzz:\n    needs: test\n    runs-on: ubuntu-latest\n    steps:\n      - name: Setup Go\n        uses: actions/setup-go@v5\n        with:\n          go-version: stable\n          cache: false\n\n      - name: Check out code\n        uses: actions/checkout@v4\n\n      - name: Run fuzzing for string parsing\n        run: go test -fuzztime 20s -fuzz ^FuzzParse$\n\n      - name: Run fuzzing from BSON unmarshaling\n        run: go test -fuzztime 20s -fuzz ^FuzzBSON$\n\n      - name: Run fuzzing for string conversion\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_String_Parse$\n\n      - name: Run fuzzing for IEEE 754-2008 conversion\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_IEEE_ParseIEEE$\n\n      - name: Run fuzzing for binary-text interoperability\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Binary_Text$\n\n      - name: Run fuzzing for text-binary interoperability\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Text_Binary$\n\n      - name: Run fuzzing for float64 conversion\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Float64_NewFromFloat64$\n\n      - name: Run fuzzing for int64 conversion\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Int64_NewFromInt64$\n\n      - name: Run fuzzing for addition\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Add$\n\n      - name: Run fuzzing for multiplication\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Mul$\n\n      - name: Run fuzzing for fused multiply-addition\n        run: go test -fuzztime 60s -fuzz ^FuzzDecimal_AddMul$\n\n      - name: Run fuzzing for fused multiply-addition\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Add_AddMul$\n\n      - name: Run fuzzing for fused multiply-addition\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Mul_AddMul$\n\n      - name: Run fuzzing for summation\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Add_Sum$\n\n      - name: Run fuzzing for product\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Mul_Prod$\n\n      - name: Run fuzzing for division\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Quo$\n\n      - name: Run fuzzing for fused quotient-addition\n        run: go test -fuzztime 60s -fuzz ^FuzzDecimal_AddQuo$\n\n      - name: Run fuzzing for fused quotient-addition\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Add_AddQuo$\n\n      - name: Run fuzzing for fused quotient-addition\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Quo_AddQuo$\n\n      - name: Run fuzzing for integer division and remainder\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_QuoRem$\n\n      - name: Run fuzzing for square root and integer power\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Sqrt_PowInt$\n\n      - name: Run fuzzing for square root and power\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Pow_Sqrt$\n\n      - name: Run fuzzing for power and integer power\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Pow_PowInt$\n\n      - name: Run fuzzing for exponential and power\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Pow_Exp$\n\n      - name: Run fuzzing for exponential and logarithm\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimalp_Log_Exp$\n\n      - name: Run fuzzing for shifted exponential and exponential\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Expm1_Exp$\n\n      - name: Run fuzzing for shifted logarithm and logarithm\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Log1p_Log$\n\n      - name: Run fuzzing for comparison\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Cmp$\n\n      - name: Run fuzzing for comparison and subtraction\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Sub_Cmp$\n\n      - name: Run fuzzing for constructor\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_New$\n\n      - name: Run fuzzing for trimming\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Trim$\n\n      - name: Run fuzzing for padding\n        run: go test -fuzztime 20s -fuzz ^FuzzDecimal_Pad$\n"
  },
  {
    "path": ".gitignore",
    "content": "*.exe\n*.exe~\n*.dll\n*.so\n*.dylib\n*.test\n*.out\ncoverage.txt\n"
  },
  {
    "path": ".golangci.yml",
    "content": "run:\n  timeout: 5m\n\nlinters:\n  enable:\n    - errcheck\n    - gosimple\n    - goimports\n    - govet\n    - ineffassign\n    - godot\n    - gosec\n    - misspell\n    - stylecheck\n    - revive\n    - staticcheck\n    - typecheck\n    - unused\n    - gocyclo\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "# Changelog\n\n## [0.1.36] - 2025-01-19\n\n### Added\n\n- Implemented `Decimal.AppendText`, `Decimal.AppendBinary`, `Decimal.Expm1`, `Decimal.Log1p`.\n\n## [0.1.35] - 2025-01-12\n\n### Added\n\n- Implemented `Decimal.UnmarshalJSON`, `Decimal.MarshalJSON`, `Decimal.UnmarshalBSONValue`, `Decimal.MarshalBSONValue`.\n\n## [0.1.34] - 2024-12-27\n\n### Added\n\n- Implemented `Mean`, `Decimal.Pow`, `Decimal.Log2`, `Decimal.Log10`.\n\n### !!! Breaking Change !!!\n\nDue to wrong behaviour of some database drivers, the following changes were made:\n\n- `Decimal.MarshalBinary` produces the same output as `Decimal.MarshalText`.\n- `Decimal.UnmarshalBinary` expects the same input as `Decimal.UnmarshalText`.\n\nAll BCD encoding related code was removed.\n\n## [0.1.33] - 2024-11-16\n\n### Added\n\n- Implemented `Sum`, `Prod`.\n\n## [0.1.32] - 2024-09-28\n\n### Added\n\n- Implemented `Decimal.Log`.\n\n### Changed\n\n- `Decimal.PowInt` always correctly rounds the result.\n\n## [0.1.31] - 2024-08-30\n\n### Added\n\n- Implemented `Decimal.SubMul`, `Decimal.SubQuo`, `Decimal.Equal`, `Decimal.Less`.\n\n## [0.1.30] - 2024-08-29\n\n### Added\n\n- Implemented `Decimal.AddMul`, `Decimal.AddQuo`, `Decimal.Exp`.\n\n### Changed\n\n- Bumped go version to 1.22.\n- Deprecated `Decimal.FMA`.\n\n## [0.1.29] - 2024-06-29\n\n### Changed\n\n- Improved `Decimal.Sqrt` and `Decimal.QuoRem` performance.\n\n## [0.1.28] - 2024-06-22\n\n### Added\n\n- Implemented `Decimal.Sqrt`.\n\n## [0.1.27] - 2024-05-19\n\n### Changed\n\n- `Decimal.Pad`, `Decimal.Rescale`, and `Descimal.Quantize` do not return errors anymore.\n\n## [0.1.25] - 2024-05-17\n\n### Added\n\n- Implemented binary marshaling.\n\n## [0.1.24] - 2024-05-05\n\n### Changed\n\n- Bumped go version to 1.21.\n- Improved documentation.\n\n## [0.1.23] - 2024-03-04\n\n### Changed\n\n- Improved documentation.\n\n## [0.1.22] - 2024-01-11\n\n### Changed\n\n- Supported MySQL in `Decimal.Scan`.\n- Added examples for XML marshaling.\n\n## [0.1.21] - 2024-01-05\n\n### Changed\n\n- Optimized parsing performance for long strings.\n- Improved documentation.\n\n## [0.1.20] - 2024-01-01\n\n### Changed\n\n- Eliminated heap allocations in big.Int arithmetic.\n- Improved documentation.\n\n## [0.1.19] - 2023-12-18\n\n### Changed\n\n- Improved table formatting in documentation.\n\n## [0.1.18] - 2023-12-18\n\n### Changed\n\n- Improved examples and documentation.\n\n## [0.1.17] - 2023-12-01\n\n### Added\n\n- Implemented `Decimal.SameScale`.\n\n### Changed\n\n- Improved examples and documentation.\n\n## [0.1.16] - 2023-11-21\n\n### Changed\n\n- Improved examples and documentation.\n- Improved test coverage.\n\n## [0.1.15] - 2023-10-31\n\n### Changed\n\n- Improved examples and documentation.\n\n## [0.1.14] - 2023-10-13\n\n### Changed\n\n- Improved examples and documentation.\n\n## [0.1.13] - 2023-10-10\n\n### Added\n\n- Implemented `NullDecimal` type.\n\n## [0.1.12] - 2023-10-01\n\n### Changed\n\n- Improved accuracy of `Decimal.PowInt` for negative powers.\n- Reviewed and improved documentation.\n\n## [0.1.11] - 2023-09-21\n\n### Added\n\n- Implemented `Decimal.Clamp`.\n\n### Changed\n\n- Reviewed and improved documentation.\n\n## [0.1.10] - 2023-09-09\n\n### Added\n\n- Implemented `Decimal.SubAbs`, `Decimal.CmpAbs`, `Decimal.Inv`.\n- Added `Decimal.Pi`, `Decimal.E`, `Decimal.NegOne`, `Decimal.Two`, `Decimal.Thousand`.\n\n### Changed\n\n- Reviewed descriptions of rounding methods.\n\n## [0.1.9] - 2023-08-27\n\n### Changed\n\n- Reviewed error descriptions.\n\n## [0.1.8] - 2023-08-23\n\n### Changed\n\n- Improved accuracy of `Decimal.PowInt`.\n\n## [0.1.7] - 2023-08-20\n\n### Changed\n\n- Enabled `gocyclo` linter.\n\n## [0.1.6] - 2023-08-19\n\n### Added\n\n- Implemented `Decimal.Scan` and `Decimal.Value`.\n\n### Changed\n\n- `Decimal.CopySign` treats 0 as a positive.\n- Enabled `gosec`, `godot`, and `stylecheck` linters.\n\n## [0.1.5] - 2023-08-12\n\n### Added\n\n- Implemented `NewFromFloat64`.\n- Added fuzzing job to continuous integration.\n\n### Changed\n\n- `NewFromInt64` can round to nearest if coefficient is too large.\n\n## [0.1.4] - 2023-08-04\n\n### Changed\n\n- Implemented `NewFromInt64`.\n\n## [0.1.3] - 2023-08-03\n\n### Changed\n\n- Implemented scale argument for `Decimal.Int64`.\n\n## [0.1.2] - 2023-06-17\n\n### Changed\n\n- `Rescale`, `ParseExact`, `MulExact`, `AddExact`, `FMAExact`, and `QuoExact`\n  return error if scale is out of range.\n\n## [0.1.1] - 2023-06-10\n\n### Changed\n\n- `New` returns error if scale is out of range.\n\n## [0.1.0] - 2023-06-03\n\n### Changed\n\n- All methods now return errors, instead of panicking.\n- Implemented `Decimal.Pad`.\n- Renamed `Decimal.Round` to `Decimal.Rescale`.\n- Renamed `Decimal.Reduce` to `Decimal.Trim`.\n\n## [0.0.13] - 2023-04-22\n\n### Fixed\n\n- Testing on Windows.\n\n## [0.0.12] - 2023-04-21\n\n### Changed\n\n- Testing on Windows and macOS.\n- Improved documentation.\n\n## [0.0.11] - 2023-04-15\n\n### Added\n\n- Implemented `Decimal.Int64`, `Decimal.Float64`.\n\n### Changed\n\n- Reviewed and improved documentation.\n\n## [0.0.10] - 2023-04-13\n\n### Changed\n\n- Reviewed and improved documentation.\n- Improved continuous integration.\n\n## [0.0.9] - 2023-04-05\n\n### Added\n\n- Implemented `Decimal.One`, `Decimal.Zero`.\n\n### Changed\n\n- Reduced memory consumption.\n- Renamed `Decimal.LessThanOne` to `Decimal.WithinOne`.\n\n### Deleted\n\n- Removed `Decimal.WithScale`.\n\n## [0.0.8] - 2023-03-25\n\n### Changed\n\n- Simplified `Decimal.Quo`.\n\n## [0.0.7] - 2023-03-22\n\n### Added\n\n- Implemented `Decimal.CopySign`.\n\n## [0.0.6] - 2023-03-21\n\n### Added\n\n- Implemented `Decimal.ULP`.\n\n## [0.0.5] - 2023-03-19\n\n### Added\n\n- Polish notation calculator example.\n- Benchmarks statistics.\n\n## [0.0.4] - 2023-03-19\n\n### Fixed\n\n- Fixed index out of range in `Parse`.\n- Rounding error in `Decimal.Quo`.\n\n## [0.0.3] - 2023-03-18\n\n### Changed\n\n- Removed errors from public API.\n- Renamed `Decimal.Fma` to `Decimal.FMA`.\n\n## [0.0.2] - 2023-03-13\n\n### Added\n\n- Implemented `Decimal.Fma`.\n\n## [0.0.1] - 2023-02-28\n\n### Added\n\n- Initial version.\n"
  },
  {
    "path": "LICENSE",
    "content": "MIT License\n\nCopyright (c) 2023 govalues\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "# decimal\n\n[![githubb]][github]\n[![codecovb]][codecov]\n[![goreportb]][goreport]\n[![godocb]][godoc]\n[![licenseb]][license]\n[![versionb]][version]\n[![awesomeb]][awesome]\n\nPackage decimal implements correctly rounded decimal floating-point numbers for Go.\nThis package is designed specifically for use in transactional financial systems.\n\n## Key Features\n\n- **BSON, JSON, XML, SQL** - Implements the necessary interfaces for direct compatibility\n  with the [mongo-driver/bson], [encoding/json], [encoding/xml], and [database/sql] packages.\n- **No Heap Allocations** - Optimized to avoid heap allocations,\n  preventing garbage collector impact during arithmetic operations.\n- **Correct Rounding** - For all methods, the result is the one that would\n  be obtained if the true mathematical value were rounded to 19 digits of\n  precision using the [half-to-even] rounding (a.k.a. \"banker's rounding\").\n- **No Panics** - All methods are panic-free, returning errors instead of crashing\n  your application in cases such as overflow or division by zero.\n- **Immutability** - Once set, a decimal remains constant,\n  ensuring safe concurrent access across goroutines.\n- **Simple String Representation** - Decimals are represented in a straightforward\n  format avoiding the complexities of scientific or engineering notations.\n- **Rigorous Testing** - All methods are cross-validated against\n  the [cockroachdb/apd] and [shopspring/decimal] packages through extensive [fuzz testing].\n\n## Getting Started\n\n### Installation\n\nTo add the decimal package to your Go workspace:\n\n```bash\ngo get github.com/govalues/decimal\n```\n\n### Basic Usage\n\nCreate decimal values using one of the constructors.\nAfter creating a decimal, you can perform various operations as shown below:\n\n```go\npackage main\n\nimport (\n    \"fmt\"\n    \"github.com/govalues/decimal\"\n)\n\nfunc main() {\n    // Constructors\n    d, _ := decimal.New(8, 0)               // d = 8\n    e, _ := decimal.Parse(\"12.5\")           // e = 12.5\n    f, _ := decimal.NewFromFloat64(2.567)   // f = 2.567\n    g, _ := decimal.NewFromInt64(7, 896, 3) // g = 7.896\n\n    // Arithmetic operations\n    fmt.Println(d.Add(e))              // 8 + 12.5\n    fmt.Println(d.Sub(e))              // 8 - 12.5\n    fmt.Println(d.SubAbs(e))           // abs(8 - 12.5)\n\n    fmt.Println(d.Mul(e))              // 8 * 12.5\n    fmt.Println(d.AddMul(e, f))        // 8 + 12.5 * 2.567\n    fmt.Println(d.SubMul(e, f))        // 8 - 12.5 * 2.567\n    fmt.Println(d.PowInt(2))           // 8²\n\n    fmt.Println(d.Quo(e))              // 8 / 12.5\n    fmt.Println(d.AddQuo(e, f))        // 8 + 12.5 / 2.567\n    fmt.Println(d.SubQuo(e, f))        // 8 - 12.5 / 2.567\n    fmt.Println(d.QuoRem(e))           // 8 div 12.5, 8 mod 12.5\n    fmt.Println(d.Inv())               // 1 / 8\n\n    fmt.Println(decimal.Sum(d, e, f))  // 8 + 12.5 + 2.567\n    fmt.Println(decimal.Mean(d, e, f)) // (8 + 12.5 + 2.567) / 3\n    fmt.Println(decimal.Prod(d, e, f)) // 8 * 12.5 * 2.567\n\n    // Transcendental functions\n    fmt.Println(e.Sqrt())              // √12.5\n    fmt.Println(e.Exp())               // exp(12.5)\n    fmt.Println(e.Expm1())             // exp(12.5) - 1\n    fmt.Println(e.Log())               // ln(12.5)\n    fmt.Println(e.Log1p())             // ln(12.5 + 1)\n    fmt.Println(e.Log2())              // log₂(12.5)\n    fmt.Println(e.Log10())             // log₁₀(12.5)\n    fmt.Println(e.Pow(d))              // 12.5⁸\n\n    // Rounding to 2 decimal places\n    fmt.Println(g.Round(2))            // 7.90\n    fmt.Println(g.Ceil(2))             // 7.90\n    fmt.Println(g.Floor(2))            // 7.89\n    fmt.Println(g.Trunc(2))            // 7.89\n\n    // Conversions\n    fmt.Println(f.Int64(9))            // 2 567000000\n    fmt.Println(f.Float64())           // 2.567\n    fmt.Println(f.String())            // 2.567\n\n    // Formatting\n    fmt.Printf(\"%.2f\", f)              // 2.57\n    fmt.Printf(\"%.2k\", f)              // 256.70%\n}\n```\n\n## Documentation\n\nFor detailed documentation and additional examples, visit the package\n[documentation](https://pkg.go.dev/github.com/govalues/decimal#section-documentation).\nFor examples related to financial calculations, see the `money` package\n[documentation](https://pkg.go.dev/github.com/govalues/money#section-documentation).\n\n## Comparison\n\nComparison with other popular packages:\n\n| Feature              | govalues  | [cockroachdb/apd] v3.2.1 | [shopspring/decimal] v1.4.0 |\n| -------------------- | --------- | ------------------------ | --------------------------- |\n| Correctly Rounded    | Yes       | No                       | No                          |\n| Speed                | High      | Medium                   | Low[^reason]                |\n| Heap Allocations     | No        | Medium                   | High                        |\n| Precision            | 19 digits | Arbitrary                | Arbitrary                   |\n| Panic Free           | Yes       | Yes                      | No[^divzero]                |\n| Mutability           | Immutable | Mutable[^reason]         | Immutable                   |\n| Mathematical Context | Implicit  | Explicit                 | Implicit                    |\n\n[^reason]: decimal package was created simply because [shopspring/decimal] was\ntoo slow and [cockroachdb/apd] was mutable.\n\n[^divzero]: [shopspring/decimal] panics on division by zero.\n\n### Benchmarks\n\n```text\ngoos: linux\ngoarch: amd64\npkg: github.com/govalues/decimal-tests\ncpu: AMD Ryzen 7 3700C  with Radeon Vega Mobile Gfx \n```\n\n| Test Case | Expression            | govalues | [cockroachdb/apd] v3.2.1 | [shopspring/decimal] v1.4.0 | govalues vs cockroachdb | govalues vs shopspring |\n| --------- | --------------------- | -------: | -----------------------: | --------------------------: | ----------------------: | ---------------------: |\n| Add       | 5 + 6                 |   16.06n |                   74.88n |                     140.90n |                +366.22% |               +777.33% |\n| Mul       | 2 * 3                 |   16.93n |                   62.20n |                     146.00n |                +267.40% |               +762.37% |\n| Quo       | 2 / 4 (exact)         |   59.52n |                  176.95n |                     657.40n |                +197.30% |              +1004.50% |\n| Quo       | 2 / 3 (inexact)       |  391.60n |                  976.80n |                    2962.50n |                +149.39% |               +656.42% |\n| PowInt    | 1.1^60                |  950.90n |                 3302.50n |                    4599.50n |                +247.32% |               +383.73% |\n| PowInt    | 1.01^600              |    3.45µ |                   10.67µ |                      18.67µ |                +209.04% |               +440.89% |\n| PowInt    | 1.001^6000            |    5.94µ |                   20.50µ |                     722.22µ |                +244.88% |             +12052.44% |\n| Sqrt      | √2                    |    3.40µ |                    4.96µ |                    2101.86µ |                 +46.00% |             +61755.71% |\n| Exp       | exp(0.5)              |    8.35µ |                   39.28µ |                      20.06µ |                +370.58% |               +140.32% |\n| Log       | ln(0.5)               |   54.89µ |                  129.01µ |                     151.55µ |                +135.03% |               +176.10% |\n| Parse     | 1                     |   16.52n |                   76.30n |                     136.55n |                +362.00% |               +726.82% |\n| Parse     | 123.456               |   47.37n |                  176.90n |                     242.60n |                +273.44% |               +412.14% |\n| Parse     | 123456789.1234567890  |   85.49n |                  224.15n |                     497.95n |                +162.19% |               +482.47% |\n| String    | 1                     |    5.11n |                   19.57n |                     198.25n |                +283.21% |              +3783.07% |\n| String    | 123.456               |   35.78n |                   77.12n |                     228.85n |                +115.52% |               +539.51% |\n| String    | 123456789.1234567890  |   70.72n |                  239.10n |                     337.25n |                +238.12% |               +376.91% |\n| Telco     | (see [specification]) |  137.00n |                  969.40n |                    3981.00n |                +607.33% |              +2804.78% |\n\nThe benchmark results shown in the table are provided for informational purposes only and may vary depending on your specific use case.\n\n[codecov]: https://codecov.io/gh/govalues/decimal\n[codecovb]: https://img.shields.io/codecov/c/github/govalues/decimal/main?color=brightcolor\n[goreport]: https://goreportcard.com/report/github.com/govalues/decimal\n[goreportb]: https://goreportcard.com/badge/github.com/govalues/decimal\n[github]: https://github.com/govalues/decimal/actions/workflows/go.yml\n[githubb]: https://img.shields.io/github/actions/workflow/status/govalues/decimal/go.yml\n[godoc]: https://pkg.go.dev/github.com/govalues/decimal#section-documentation\n[godocb]: https://img.shields.io/badge/go.dev-reference-blue\n[version]: https://go.dev/dl\n[versionb]: https://img.shields.io/github/go-mod/go-version/govalues/decimal?label=go\n[license]: https://en.wikipedia.org/wiki/MIT_License\n[licenseb]: https://img.shields.io/github/license/govalues/decimal?color=blue\n[awesome]: https://github.com/avelino/awesome-go#financial\n[awesomeb]: https://awesome.re/mentioned-badge.svg\n[cockroachdb/apd]: https://pkg.go.dev/github.com/cockroachdb/apd\n[shopspring/decimal]: https://pkg.go.dev/github.com/shopspring/decimal\n[mongo-driver/bson]: https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#ValueUnmarshaler\n[encoding/json]: https://pkg.go.dev/encoding/json#Unmarshaler\n[encoding/xml]: https://pkg.go.dev/encoding#TextUnmarshaler\n[database/sql]: https://pkg.go.dev/database/sql#Scanner\n[specification]: https://speleotrove.com/decimal/telcoSpec.html\n[fuzz testing]: https://github.com/govalues/decimal-tests\n[half-to-even]: https://en.wikipedia.org/wiki/Rounding#Rounding_half_to_even\n"
  },
  {
    "path": "decimal.go",
    "content": "package decimal\n\nimport (\n\t\"database/sql/driver\"\n\t\"errors\"\n\t\"fmt\"\n\t\"math\"\n\t\"strconv\"\n\t\"unsafe\"\n)\n\n// Decimal represents a finite floating-point decimal number.\n// Its zero value corresponds to the numeric value of 0.\n// Decimal is designed to be safe for concurrent use by multiple goroutines.\ntype Decimal struct {\n\tneg   bool // indicates whether the decimal is negative\n\tscale int8 // position of the floating decimal point\n\tcoef  fint // numeric value without decimal point\n}\n\nconst (\n\tMaxPrec  = 19      // MaxPrec is the maximum length of the coefficient in decimal digits.\n\tMinScale = 0       // MinScale is the minimum number of digits after the decimal point.\n\tMaxScale = 19      // MaxScale is the maximum number of digits after the decimal point.\n\tmaxCoef  = maxFint // maxCoef is the maximum absolute value of the coefficient, which is equal to (10^MaxPrec - 1).\n)\n\nvar (\n\tNegOne              = MustNew(-1, 0)                         // NegOne represents the decimal value of -1.\n\tZero                = MustNew(0, 0)                          // Zero represents the decimal value of 0. For comparison purposes, use the IsZero method.\n\tOne                 = MustNew(1, 0)                          // One represents the decimal value of 1.\n\tTwo                 = MustNew(2, 0)                          // Two represents the decimal value of 2.\n\tTen                 = MustNew(10, 0)                         // Ten represents the decimal value of 10.\n\tHundred             = MustNew(100, 0)                        // Hundred represents the decimal value of 100.\n\tThousand            = MustNew(1_000, 0)                      // Thousand represents the decimal value of 1,000.\n\tE                   = MustNew(2_718_281_828_459_045_235, 18) // E represents Euler’s number rounded to 18 digits.\n\tPi                  = MustNew(3_141_592_653_589_793_238, 18) // Pi represents the value of π rounded to 18 digits.\n\terrDecimalOverflow  = errors.New(\"decimal overflow\")\n\terrInvalidDecimal   = errors.New(\"invalid decimal\")\n\terrScaleRange       = errors.New(\"scale out of range\")\n\terrInvalidOperation = errors.New(\"invalid operation\")\n\terrInexactDivision  = errors.New(\"inexact division\")\n\terrDivisionByZero   = errors.New(\"division by zero\")\n)\n\n// newUnsafe creates a new decimal without checking the scale and coefficient.\n// Use it only if you are absolutely sure that the arguments are valid.\nfunc newUnsafe(neg bool, coef fint, scale int) Decimal {\n\tif coef == 0 {\n\t\tneg = false\n\t}\n\t//nolint:gosec\n\treturn Decimal{neg: neg, coef: coef, scale: int8(scale)}\n}\n\n// newSafe creates a new decimal and checks the scale and coefficient.\nfunc newSafe(neg bool, coef fint, scale int) (Decimal, error) {\n\tswitch {\n\tcase scale < MinScale || scale > MaxScale:\n\t\treturn Decimal{}, errScaleRange\n\tcase coef > maxCoef:\n\t\treturn Decimal{}, errDecimalOverflow\n\t}\n\treturn newUnsafe(neg, coef, scale), nil\n}\n\n// newFromFint creates a new decimal from a uint64 coefficient.\n// This method does not use overflowError to return descriptive errors,\n// as it must be as fast as possible.\nfunc newFromFint(neg bool, coef fint, scale, minScale int) (Decimal, error) {\n\tvar ok bool\n\t// Scale normalization\n\tswitch {\n\tcase scale < minScale:\n\t\tcoef, ok = coef.lsh(minScale - scale)\n\t\tif !ok {\n\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t}\n\t\tscale = minScale\n\tcase scale > MaxScale:\n\t\tcoef = coef.rshHalfEven(scale - MaxScale)\n\t\tscale = MaxScale\n\t}\n\treturn newSafe(neg, coef, scale)\n}\n\n// newFromBint creates a new decimal from a *big.Int coefficient.\n// This method uses overflowError to return descriptive errors.\nfunc newFromBint(neg bool, coef *bint, scale, minScale int) (Decimal, error) {\n\t// Overflow validation\n\tprec := coef.prec()\n\tif prec-scale > MaxPrec-minScale {\n\t\treturn Decimal{}, overflowError(prec, scale, minScale)\n\t}\n\t// Scale normalization\n\tswitch {\n\tcase scale < minScale:\n\t\tcoef.lsh(coef, minScale-scale)\n\t\tscale = minScale\n\tcase scale >= prec && scale > MaxScale: // no integer part\n\t\tcoef.rshHalfEven(coef, scale-MaxScale)\n\t\tscale = MaxScale\n\tcase prec > scale && prec > MaxPrec: // there is an integer part\n\t\tcoef.rshHalfEven(coef, prec-MaxPrec)\n\t\tscale = MaxPrec - prec + scale\n\t}\n\t// Handling the rare case when rshHalfEven rounded\n\t// a 19-digit coefficient to a 20-digit coefficient.\n\tif coef.hasPrec(MaxPrec + 1) {\n\t\treturn newFromBint(neg, coef, scale, minScale)\n\t}\n\treturn newSafe(neg, coef.fint(), scale)\n}\n\nfunc overflowError(gotPrec, gotScale, wantScale int) error {\n\tmaxDigits := MaxPrec - wantScale\n\tgotDigits := gotPrec - gotScale\n\tswitch wantScale {\n\tcase 0:\n\t\treturn fmt.Errorf(\"%w: the integer part of a %T can have at most %v digits, but it has %v digits\", errDecimalOverflow, Decimal{}, maxDigits, gotDigits)\n\tdefault:\n\t\treturn fmt.Errorf(\"%w: with %v significant digits after the decimal point, the integer part of a %T can have at most %v digits, but it has %v digits\", errDecimalOverflow, wantScale, Decimal{}, maxDigits, gotDigits)\n\t}\n}\n\nfunc unknownOverflowError() error {\n\treturn fmt.Errorf(\"%w: the integer part of a %T can have at most %v digits, but it has significantly more digits\", errDecimalOverflow, Decimal{}, MaxPrec)\n}\n\n// MustNew is like [New] but panics if the decimal cannot be constructed.\n// It simplifies safe initialization of global variables holding decimals.\nfunc MustNew(value int64, scale int) Decimal {\n\td, err := New(value, scale)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"New(%v, %v) failed: %v\", value, scale, err))\n\t}\n\treturn d\n}\n\n// New returns a decimal equal to value / 10^scale.\n// New keeps trailing zeros in the fractional part to preserve scale.\n//\n// New returns an error if the scale is negative or greater than [MaxScale].\nfunc New(value int64, scale int) (Decimal, error) {\n\tvar coef fint\n\tvar neg bool\n\tif value >= 0 {\n\t\tneg = false\n\t\tcoef = fint(value)\n\t} else {\n\t\tneg = true\n\t\tif value == math.MinInt64 {\n\t\t\tcoef = fint(math.MaxInt64) + 1\n\t\t} else {\n\t\t\tcoef = fint(-value)\n\t\t}\n\t}\n\treturn newSafe(neg, coef, scale)\n}\n\n// NewFromInt64 converts a pair of integers, representing the whole and\n// fractional parts, to a (possibly rounded) decimal equal to whole + frac / 10^scale.\n// NewFromInt64 removes all trailing zeros from the fractional part.\n// This method is useful for converting amounts from [protobuf] format.\n// See also method [Decimal.Int64].\n//\n// NewFromInt64 returns an error if:\n//   - the whole and fractional parts have different signs;\n//   - the scale is negative or greater than [MaxScale];\n//   - frac / 10^scale is not within the range (-1, 1).\n//\n// [protobuf]: https://github.com/googleapis/googleapis/blob/master/google/type/money.proto\nfunc NewFromInt64(whole, frac int64, scale int) (Decimal, error) {\n\t// Whole\n\td, err := New(whole, 0)\n\tif err != nil {\n\t\treturn Decimal{}, fmt.Errorf(\"converting integers: %w\", err) // should never happen\n\t}\n\t// Fraction\n\tf, err := New(frac, scale)\n\tif err != nil {\n\t\treturn Decimal{}, fmt.Errorf(\"converting integers: %w\", err)\n\t}\n\tif !f.IsZero() {\n\t\tif !d.IsZero() && d.Sign() != f.Sign() {\n\t\t\treturn Decimal{}, fmt.Errorf(\"converting integers: inconsistent signs\")\n\t\t}\n\t\tif !f.WithinOne() {\n\t\t\treturn Decimal{}, fmt.Errorf(\"converting integers: inconsistent fraction\")\n\t\t}\n\t\tf = f.Trim(0)\n\t\td, err = d.Add(f)\n\t\tif err != nil {\n\t\t\treturn Decimal{}, fmt.Errorf(\"converting integers: %w\", err) // should never happen\n\t\t}\n\t}\n\treturn d, nil\n}\n\n// Int64 returns a pair of integers representing the whole and\n// (possibly rounded) fractional parts of the decimal.\n// If given scale is greater than the scale of the decimal, then the fractional part\n// is zero-padded to the right.\n// If given scale is smaller than the scale of the decimal, then the fractional part\n// is rounded using [rounding half to even] (banker's rounding).\n// The relationship between the decimal and the returned values can be expressed\n// as d = whole + frac / 10^scale.\n// This method is useful for converting amounts to [protobuf] format.\n// See also constructor [NewFromInt64].\n//\n// If the result cannot be represented as a pair of int64 values,\n// then false is returned.\n//\n// [rounding half to even]: https://en.wikipedia.org/wiki/Rounding#Rounding_half_to_even\n// [protobuf]: https://github.com/googleapis/googleapis/blob/master/google/type/money.proto\nfunc (d Decimal) Int64(scale int) (whole, frac int64, ok bool) {\n\tif scale < MinScale || scale > MaxScale {\n\t\treturn 0, 0, false\n\t}\n\tx := d.coef\n\ty := pow10[d.Scale()]\n\tif scale < d.Scale() {\n\t\tx = x.rshHalfEven(d.Scale() - scale)\n\t\ty = pow10[scale]\n\t}\n\tq, r, ok := x.quoRem(y)\n\tif !ok {\n\t\treturn 0, 0, false // Should never happen\n\t}\n\tif scale > d.Scale() {\n\t\tr, ok = r.lsh(scale - d.Scale())\n\t\tif !ok {\n\t\t\treturn 0, 0, false // Should never happen\n\t\t}\n\t}\n\tif d.IsNeg() {\n\t\tif q > -math.MinInt64 || r > -math.MinInt64 {\n\t\t\treturn 0, 0, false\n\t\t}\n\t\t//nolint:gosec\n\t\treturn -int64(q), -int64(r), true\n\t}\n\tif q > math.MaxInt64 || r > math.MaxInt64 {\n\t\treturn 0, 0, false\n\t}\n\t//nolint:gosec\n\treturn int64(q), int64(r), true\n}\n\n// NewFromFloat64 converts a float to a (possibly rounded) decimal.\n// See also method [Decimal.Float64].\n//\n// NewFromFloat64 returns an error if:\n//   - the float is a special value (NaN or Inf);\n//   - the integer part of the result has more than [MaxPrec] digits.\nfunc NewFromFloat64(f float64) (Decimal, error) {\n\t// Float\n\tif math.IsNaN(f) || math.IsInf(f, 0) {\n\t\treturn Decimal{}, fmt.Errorf(\"converting float: special value %v\", f)\n\t}\n\ttext := make([]byte, 0, 32)\n\ttext = strconv.AppendFloat(text, f, 'f', -1, 64)\n\n\t// Decimal\n\td, err := parse(text)\n\tif err != nil {\n\t\treturn Decimal{}, fmt.Errorf(\"converting float: %w\", err)\n\t}\n\treturn d, nil\n}\n\n// Float64 returns the nearest binary floating-point number rounded\n// using [rounding half to even] (banker's rounding).\n// See also constructor [NewFromFloat64].\n//\n// This conversion may lose data, as float64 has a smaller precision\n// than the decimal type.\n//\n// [rounding half to even]: https://en.wikipedia.org/wiki/Rounding#Rounding_half_to_even\nfunc (d Decimal) Float64() (f float64, ok bool) {\n\ts := d.String()\n\tf, err := strconv.ParseFloat(s, 64)\n\tif err != nil {\n\t\treturn 0, false\n\t}\n\treturn f, true\n}\n\n// MustParse is like [Parse] but panics if the string cannot be parsed.\n// It simplifies safe initialization of global variables holding decimals.\nfunc MustParse(s string) Decimal {\n\td, err := Parse(s)\n\tif err != nil {\n\t\tpanic(fmt.Sprintf(\"Parse(%q) failed: %v\", s, err))\n\t}\n\treturn d\n}\n\n// Parse converts a string to a (possibly rounded) decimal.\n// The input string must be in one of the following formats:\n//\n//\t1.234\n//\t-1234\n//\t+0.000001234\n//\t1.83e5\n//\t0.22e-9\n//\n// The formal EBNF grammar for the supported format is as follows:\n//\n//\tsign           ::= '+' | '-'\n//\tdigits         ::= { '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' }\n//\tsignificand    ::= digits '.' digits | '.' digits | digits '.' | digits\n//\texponent       ::= ('e' | 'E') [sign] digits\n//\tnumeric-string ::= [sign] significand [exponent]\n//\n// Parse removes leading zeros from the integer part of the input string,\n// but tries to maintain trailing zeros in the fractional part to preserve scale.\n//\n// Parse returns an error if:\n//   - the string contains any whitespaces;\n//   - the string is longer than 330 bytes;\n//   - the exponent is less than -330 or greater than 330;\n//   - the string does not represent a valid decimal number;\n//   - the integer part of the result has more than [MaxPrec] digits.\nfunc Parse(s string) (Decimal, error) {\n\ttext := unsafe.Slice(unsafe.StringData(s), len(s))\n\treturn parseExact(text, 0)\n}\n\nfunc parse(text []byte) (Decimal, error) {\n\treturn parseExact(text, 0)\n}\n\n// ParseExact is similar to [Parse], but it allows you to specify how many digits\n// after the decimal point should be considered significant.\n// If any of the significant digits are lost during rounding, the method will return an error.\n// This method is useful for parsing monetary amounts, where the scale should be\n// equal to or greater than the currency's scale.\nfunc ParseExact(s string, scale int) (Decimal, error) {\n\ttext := unsafe.Slice(unsafe.StringData(s), len(s))\n\treturn parseExact(text, scale)\n}\n\nfunc parseExact(text []byte, scale int) (Decimal, error) {\n\tif len(text) > 330 {\n\t\treturn Decimal{}, fmt.Errorf(\"parsing decimal: %w\", errInvalidDecimal)\n\t}\n\tif scale < MinScale || scale > MaxScale {\n\t\treturn Decimal{}, fmt.Errorf(\"parsing decimal: %w\", errScaleRange)\n\t}\n\td, err := parseFint(text, scale)\n\tif err != nil {\n\t\td, err = parseBint(text, scale)\n\t\tif err != nil {\n\t\t\treturn Decimal{}, fmt.Errorf(\"parsing decimal: %w\", err)\n\t\t}\n\t}\n\treturn d, nil\n}\n\n// parseFint parses a decimal string using uint64 arithmetic.\n// parseFint does not support exponential notation to make it as fast as possible.\n//\n//nolint:gocyclo\nfunc parseFint(text []byte, minScale int) (Decimal, error) {\n\tvar pos int\n\twidth := len(text)\n\n\t// Sign\n\tvar neg bool\n\tswitch {\n\tcase pos == width:\n\t\t// skip\n\tcase text[pos] == '-':\n\t\tneg = true\n\t\tpos++\n\tcase text[pos] == '+':\n\t\tpos++\n\t}\n\n\t// Coefficient\n\tvar coef fint\n\tvar scale int\n\tvar hasCoef, ok bool\n\n\t// Integer\n\tfor pos < width && text[pos] >= '0' && text[pos] <= '9' {\n\t\tcoef, ok = coef.fsa(1, text[pos]-'0')\n\t\tif !ok {\n\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t}\n\t\tpos++\n\t\thasCoef = true\n\t}\n\n\t// Fraction\n\tif pos < width && text[pos] == '.' {\n\t\tpos++\n\t\tfor pos < width && text[pos] >= '0' && text[pos] <= '9' {\n\t\t\tcoef, ok = coef.fsa(1, text[pos]-'0')\n\t\t\tif !ok {\n\t\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t\t}\n\t\t\tpos++\n\t\t\tscale++\n\t\t\thasCoef = true\n\t\t}\n\t}\n\n\tif pos != width {\n\t\treturn Decimal{}, fmt.Errorf(\"%w: unexpected character %q\", errInvalidDecimal, text[pos])\n\t}\n\tif !hasCoef {\n\t\treturn Decimal{}, fmt.Errorf(\"%w: no coefficient\", errInvalidDecimal)\n\t}\n\treturn newFromFint(neg, coef, scale, minScale)\n}\n\n// parseBint parses a decimal string using *big.Int arithmetic.\n// parseBint supports exponential notation.\n//\n//nolint:gocyclo\nfunc parseBint(text []byte, minScale int) (Decimal, error) {\n\tvar pos int\n\twidth := len(text)\n\n\t// Sign\n\tvar neg bool\n\tswitch {\n\tcase pos == width:\n\t\t// skip\n\tcase text[pos] == '-':\n\t\tneg = true\n\t\tpos++\n\tcase text[pos] == '+':\n\t\tpos++\n\t}\n\n\t// Coefficient\n\tbcoef := getBint()\n\tdefer putBint(bcoef)\n\tvar fcoef fint\n\tvar shift, scale int\n\tvar hasCoef, ok bool\n\n\tbcoef.setFint(0)\n\n\t// Algorithm:\n\t// \t1. Add as many digits as possible to the uint64 coefficient (fast).\n\t// \t2. Once the uint64 coefficient has reached its maximum value,\n\t//     add it to the *big.Int coefficient (slow).\n\t// \t3. Repeat until all digits are processed.\n\n\t// Integer\n\tfor pos < width && text[pos] >= '0' && text[pos] <= '9' {\n\t\tfcoef, ok = fcoef.fsa(1, text[pos]-'0')\n\t\tif !ok {\n\t\t\treturn Decimal{}, errDecimalOverflow // Should never happen\n\t\t}\n\t\tpos++\n\t\tshift++\n\t\thasCoef = true\n\t\tif fcoef.hasPrec(MaxPrec) {\n\t\t\tbcoef.fsa(bcoef, shift, fcoef)\n\t\t\tfcoef, shift = 0, 0\n\t\t}\n\t}\n\n\t// Fraction\n\tif pos < width && text[pos] == '.' {\n\t\tpos++\n\t\tfor pos < width && text[pos] >= '0' && text[pos] <= '9' {\n\t\t\tfcoef, ok = fcoef.fsa(1, text[pos]-'0')\n\t\t\tif !ok {\n\t\t\t\treturn Decimal{}, errDecimalOverflow // Should never happen\n\t\t\t}\n\t\t\tpos++\n\t\t\tscale++\n\t\t\tshift++\n\t\t\thasCoef = true\n\t\t\tif fcoef.hasPrec(MaxPrec) {\n\t\t\t\tbcoef.fsa(bcoef, shift, fcoef)\n\t\t\t\tfcoef, shift = 0, 0\n\t\t\t}\n\t\t}\n\t}\n\tif shift > 0 {\n\t\tbcoef.fsa(bcoef, shift, fcoef)\n\t}\n\n\t// Exponent\n\tvar exp int\n\tvar eneg, hasExp, hasE bool\n\tif pos < width && (text[pos] == 'e' || text[pos] == 'E') {\n\t\tpos++\n\t\thasE = true\n\t\t// Sign\n\t\tswitch {\n\t\tcase pos == width:\n\t\t\t// skip\n\t\tcase text[pos] == '-':\n\t\t\teneg = true\n\t\t\tpos++\n\t\tcase text[pos] == '+':\n\t\t\tpos++\n\t\t}\n\t\t// Integer\n\t\tfor pos < width && text[pos] >= '0' && text[pos] <= '9' {\n\t\t\texp = exp*10 + int(text[pos]-'0')\n\t\t\tif exp > 330 {\n\t\t\t\treturn Decimal{}, errInvalidDecimal\n\t\t\t}\n\t\t\tpos++\n\t\t\thasExp = true\n\t\t}\n\t}\n\n\tif pos != width {\n\t\treturn Decimal{}, fmt.Errorf(\"%w: unexpected character %q\", errInvalidDecimal, text[pos])\n\t}\n\tif !hasCoef {\n\t\treturn Decimal{}, fmt.Errorf(\"%w: no coefficient\", errInvalidDecimal)\n\t}\n\tif hasE && !hasExp {\n\t\treturn Decimal{}, fmt.Errorf(\"%w: no exponent\", errInvalidDecimal)\n\t}\n\n\tif eneg {\n\t\tscale = scale + exp\n\t} else {\n\t\tscale = scale - exp\n\t}\n\n\treturn newFromBint(neg, bcoef, scale, minScale)\n}\n\n// String implements the [fmt.Stringer] interface and returns\n// a string representation of the decimal.\n// The returned string does not use scientific or engineering notation and is\n// formatted according to the following formal EBNF grammar:\n//\n//\tsign           ::= '-'\n//\tdigits         ::= { '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' }\n//\tsignificand    ::= digits '.' digits | digits\n//\tnumeric-string ::= [sign] significand\n//\n// See also method [Decimal.Format].\n//\n// [fmt.Stringer]: https://pkg.go.dev/fmt#Stringer\nfunc (d Decimal) String() string {\n\treturn string(d.bytes())\n}\n\n// bytes returns a string representation of the decimal as a byte slice.\nfunc (d Decimal) bytes() []byte {\n\ttext := make([]byte, 0, 24)\n\treturn d.append(text)\n}\n\n// append appends a string representation of the decimal to the byte slice.\nfunc (d Decimal) append(text []byte) []byte {\n\tvar buf [24]byte\n\tpos := len(buf) - 1\n\tcoef := d.Coef()\n\tscale := d.Scale()\n\n\t// Coefficient\n\tfor {\n\t\tbuf[pos] = byte(coef%10) + '0'\n\t\tpos--\n\t\tcoef /= 10\n\t\tif scale > 0 {\n\t\t\tscale--\n\t\t\t// Decimal point\n\t\t\tif scale == 0 {\n\t\t\t\tbuf[pos] = '.'\n\t\t\t\tpos--\n\t\t\t\t// Leading 0\n\t\t\t\tif coef == 0 {\n\t\t\t\t\tbuf[pos] = '0'\n\t\t\t\t\tpos--\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif coef == 0 && scale == 0 {\n\t\t\tbreak\n\t\t}\n\t}\n\n\t// Sign\n\tif d.IsNeg() {\n\t\tbuf[pos] = '-'\n\t\tpos--\n\t}\n\n\treturn append(text, buf[pos+1:]...)\n}\n\n// UnmarshalJSON implements the [json.Unmarshaler] interface.\n// UnmarshalJSON supports the following types: [number] and [numeric string].\n// See also constructor [Parse].\n//\n// [number]: https://datatracker.ietf.org/doc/html/rfc8259#section-6\n// [numeric string]: https://datatracker.ietf.org/doc/html/rfc8259#section-7\n// [json.Unmarshaler]: https://pkg.go.dev/encoding/json#Unmarshaler\nfunc (d *Decimal) UnmarshalJSON(data []byte) error {\n\tif string(data) == \"null\" {\n\t\treturn nil\n\t}\n\tif len(data) >= 2 && data[0] == '\"' && data[len(data)-1] == '\"' {\n\t\tdata = data[1 : len(data)-1]\n\t}\n\tvar err error\n\t*d, err = parse(data)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unmarshaling %T: %w\", Decimal{}, err)\n\t}\n\treturn nil\n}\n\n// MarshalJSON implements the [json.Marshaler] interface.\n// MarshalJSON always returns a [numeric string].\n// See also method [Decimal.String].\n//\n// [numeric string]: https://datatracker.ietf.org/doc/html/rfc8259#section-7\n// [json.Marshaler]: https://pkg.go.dev/encoding/json#Marshaler\nfunc (d Decimal) MarshalJSON() ([]byte, error) {\n\ttext := make([]byte, 0, 26)\n\ttext = append(text, '\"')\n\ttext = d.append(text)\n\ttext = append(text, '\"')\n\treturn text, nil\n}\n\n// UnmarshalText implements the [encoding.TextUnmarshaler] interface.\n// UnmarshalText supports only numeric strings.\n// See also constructor [Parse].\n//\n// [encoding.TextUnmarshaler]: https://pkg.go.dev/encoding#TextUnmarshaler\nfunc (d *Decimal) UnmarshalText(text []byte) error {\n\tvar err error\n\t*d, err = parse(text)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unmarshaling %T: %w\", Decimal{}, err)\n\t}\n\treturn nil\n}\n\n// AppendText implements the [encoding.TextAppender] interface.\n// AppendText always appends a numeric string.\n// See also method [Decimal.String].\n//\n// [encoding.TextAppender]: https://pkg.go.dev/encoding#TextAppender\nfunc (d Decimal) AppendText(text []byte) ([]byte, error) {\n\treturn d.append(text), nil\n}\n\n// MarshalText implements the [encoding.TextMarshaler] interface.\n// MarshalText always returns a numeric string.\n// See also method [Decimal.String].\n//\n// [encoding.TextMarshaler]: https://pkg.go.dev/encoding#TextMarshaler\nfunc (d Decimal) MarshalText() ([]byte, error) {\n\treturn d.bytes(), nil\n}\n\n// UnmarshalBinary implements the [encoding.BinaryUnmarshaler] interface.\n// UnmarshalBinary supports only numeric strings.\n// See also constructor [Parse].\n//\n// [encoding.BinaryUnmarshaler]: https://pkg.go.dev/encoding#BinaryUnmarshaler\nfunc (d *Decimal) UnmarshalBinary(data []byte) error {\n\tvar err error\n\t*d, err = parse(data)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"unmarshaling %T: %w\", Decimal{}, err)\n\t}\n\treturn nil\n}\n\n// AppendBinary implements the [encoding.BinaryAppender] interface.\n// AppendBinary always appends a numeric string.\n// See also method [Decimal.String].\n//\n// [encoding.BinaryAppender]: https://pkg.go.dev/encoding#BinaryAppender\nfunc (d Decimal) AppendBinary(data []byte) ([]byte, error) {\n\treturn d.append(data), nil\n}\n\n// MarshalBinary implements the [encoding.BinaryMarshaler] interface.\n// MarshalBinary always returns a numeric string.\n// See also method [Decimal.String].\n//\n// [encoding.BinaryMarshaler]: https://pkg.go.dev/encoding#BinaryMarshaler\nfunc (d Decimal) MarshalBinary() ([]byte, error) {\n\treturn d.bytes(), nil\n}\n\n// UnmarshalBSONValue implements the [v2/bson.ValueUnmarshaler] interface.\n// UnmarshalBSONValue supports the following [types]: Double, String, 32-bit Integer, 64-bit Integer, and [Decimal128].\n//\n// [v2/bson.ValueUnmarshaler]: https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#ValueUnmarshaler\n// [types]: https://bsonspec.org/spec.html\n// [Decimal128]: https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.md\nfunc (d *Decimal) UnmarshalBSONValue(typ byte, data []byte) error {\n\t// constants are from https://bsonspec.org/spec.html\n\tvar err error\n\tswitch typ {\n\tcase 1:\n\t\t*d, err = parseBSONFloat64(data)\n\tcase 2:\n\t\t*d, err = parseBSONString(data)\n\tcase 10:\n\t\t// null, do nothing\n\tcase 16:\n\t\t*d, err = parseBSONInt32(data)\n\tcase 18:\n\t\t*d, err = parseBSONInt64(data)\n\tcase 19:\n\t\t*d, err = parseIEEEDecimal128(data)\n\tdefault:\n\t\terr = fmt.Errorf(\"BSON type %d is not supported\", typ)\n\t}\n\tif err != nil {\n\t\terr = fmt.Errorf(\"converting from BSON type %d to %T: %w\", typ, Decimal{}, err)\n\t}\n\treturn err\n}\n\n// MarshalBSONValue implements the [v2/bson.ValueMarshaler] interface.\n// MarshalBSONValue always returns [Decimal128].\n//\n// [v2/bson.ValueMarshaler]: https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#ValueMarshaler\n// [Decimal128]: https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.md\nfunc (d Decimal) MarshalBSONValue() (typ byte, data []byte, err error) {\n\treturn 19, d.ieeeDecimal128(), nil\n}\n\n// parseBSONInt32 parses a BSON int32 to a decimal.\n// The byte order of the input data must be little-endian.\nfunc parseBSONInt32(data []byte) (Decimal, error) {\n\tif len(data) != 4 {\n\t\treturn Decimal{}, fmt.Errorf(\"%w: invalid data length %v\", errInvalidDecimal, len(data))\n\t}\n\tu := uint32(data[0])\n\tu |= uint32(data[1]) << 8\n\tu |= uint32(data[2]) << 16\n\tu |= uint32(data[3]) << 24\n\ti := int64(int32(u)) //nolint:gosec\n\treturn New(i, 0)\n}\n\n// parseBSONInt64 parses a BSON int64 to a decimal.\n// The byte order of the input data must be little-endian.\nfunc parseBSONInt64(data []byte) (Decimal, error) {\n\tif len(data) != 8 {\n\t\treturn Decimal{}, fmt.Errorf(\"%w: invalid data length %v\", errInvalidDecimal, len(data))\n\t}\n\tu := uint64(data[0])\n\tu |= uint64(data[1]) << 8\n\tu |= uint64(data[2]) << 16\n\tu |= uint64(data[3]) << 24\n\tu |= uint64(data[4]) << 32\n\tu |= uint64(data[5]) << 40\n\tu |= uint64(data[6]) << 48\n\tu |= uint64(data[7]) << 56\n\ti := int64(u) //nolint:gosec\n\treturn New(i, 0)\n}\n\n// parseBSONFloat64 parses a BSON float64 to a (possibly rounded) decimal.\n// The byte order of the input data must be little-endian.\nfunc parseBSONFloat64(data []byte) (Decimal, error) {\n\tif len(data) != 8 {\n\t\treturn Decimal{}, fmt.Errorf(\"%w: invalid data length %v\", errInvalidDecimal, len(data))\n\t}\n\tu := uint64(data[0])\n\tu |= uint64(data[1]) << 8\n\tu |= uint64(data[2]) << 16\n\tu |= uint64(data[3]) << 24\n\tu |= uint64(data[4]) << 32\n\tu |= uint64(data[5]) << 40\n\tu |= uint64(data[6]) << 48\n\tu |= uint64(data[7]) << 56\n\tf := math.Float64frombits(u)\n\treturn NewFromFloat64(f)\n}\n\n// parseBSONString parses a BSON string to a (possibly rounded) decimal.\n// The byte order of the input data must be little-endian.\nfunc parseBSONString(data []byte) (Decimal, error) {\n\tif len(data) < 4 {\n\t\treturn Decimal{}, fmt.Errorf(\"%w: invalid data length %v\", errInvalidDecimal, len(data))\n\t}\n\tu := uint32(data[0])\n\tu |= uint32(data[1]) << 8\n\tu |= uint32(data[2]) << 16\n\tu |= uint32(data[3]) << 24\n\tl := int(int32(u)) //nolint:gosec\n\tif l < 1 || l > 330 || len(data) < l+4 {\n\t\treturn Decimal{}, fmt.Errorf(\"%w: invalid string length %v\", errInvalidDecimal, l)\n\t}\n\tif data[l+4-1] != 0 {\n\t\treturn Decimal{}, fmt.Errorf(\"%w: invalid null terminator %v\", errInvalidDecimal, data[l+4-1])\n\t}\n\ts := string(data[4 : l+4-1])\n\treturn Parse(s)\n}\n\n// parseIEEEDecimal128 converts a 128-bit IEEE 754-2008 decimal\n// floating point with binary integer decimal encoding to\n// a (possibly rounded) decimal.\n// The byte order of the input data must be little-endian.\n//\n// parseIEEEDecimal128 returns an error if:\n//   - the data length is not equal to 16 bytes;\n//   - the decimal a special value (NaN or Inf);\n//   - the integer part of the result has more than [MaxPrec] digits.\nfunc parseIEEEDecimal128(data []byte) (Decimal, error) {\n\tif len(data) != 16 {\n\t\treturn Decimal{}, fmt.Errorf(\"%w: invalid data length %v\", errInvalidDecimal, len(data))\n\t}\n\tif data[15]&0b0111_1100 == 0b0111_1100 {\n\t\treturn Decimal{}, fmt.Errorf(\"%w: special value NaN\", errInvalidDecimal)\n\t}\n\tif data[15]&0b0111_1100 == 0b0111_1000 {\n\t\treturn Decimal{}, fmt.Errorf(\"%w: special value Inf\", errInvalidDecimal)\n\t}\n\tif data[15]&0b0110_0000 == 0b0110_0000 {\n\t\treturn Decimal{}, fmt.Errorf(\"%w: unsupported encoding\", errInvalidDecimal)\n\t}\n\n\t// Sign\n\tneg := data[15]&0b1000_0000 == 0b1000_0000\n\n\t// Scale\n\tvar scale int\n\tscale |= int(data[14]) >> 1\n\tscale |= int(data[15]&0b0111_1111) << 7\n\tscale = 6176 - scale\n\n\t// TODO fint optimization\n\n\t// Coefficient\n\tcoef := getBint()\n\tdefer putBint(coef)\n\n\tbuf := make([]byte, 15)\n\tfor i := range 15 {\n\t\tbuf[i] = data[14-i]\n\t}\n\tbuf[0] &= 0b0000_0001\n\tcoef.setBytes(buf)\n\n\t// Scale normalization\n\tif coef.sign() == 0 {\n\t\tscale = max(scale, MinScale)\n\t}\n\n\treturn newFromBint(neg, coef, scale, 0)\n}\n\n// ieeeDecimal128 returns a 128-bit IEEE 754-2008 decimal\n// floating point with binary integer decimal encoding.\n// The byte order of the result is little-endian.\nfunc (d Decimal) ieeeDecimal128() []byte {\n\tvar buf [16]byte\n\tscale := d.Scale()\n\tcoef := d.Coef()\n\n\t// Sign\n\tif d.IsNeg() {\n\t\tbuf[15] = 0b1000_0000\n\t}\n\n\t// Scale\n\tscale = 6176 - scale\n\tbuf[15] |= byte((scale >> 7) & 0b0111_1111)\n\tbuf[14] |= byte((scale << 1) & 0b1111_1110)\n\n\t// Coefficient\n\tfor i := range 8 {\n\t\tbuf[i] = byte(coef & 0b1111_1111)\n\t\tcoef >>= 8\n\t}\n\n\treturn buf[:]\n}\n\n// Scan implements the [sql.Scanner] interface.\n//\n// [sql.Scanner]: https://pkg.go.dev/database/sql#Scanner\nfunc (d *Decimal) Scan(value any) error {\n\tvar err error\n\tswitch value := value.(type) {\n\tcase string:\n\t\t*d, err = Parse(value)\n\tcase int64:\n\t\t*d, err = New(value, 0)\n\tcase float64:\n\t\t*d, err = NewFromFloat64(value)\n\tcase []byte:\n\t\t// Special case: MySQL driver sends DECIMAL as []byte\n\t\t*d, err = parse(value)\n\tcase float32:\n\t\t// Special case: MySQL driver sends FLOAT as float32\n\t\t*d, err = NewFromFloat64(float64(value))\n\tcase uint64:\n\t\t// Special case: ClickHouse driver sends 0 as uint64\n\t\t*d, err = newSafe(false, fint(value), 0)\n\tcase nil:\n\t\terr = fmt.Errorf(\"%T does not support null values, use %T or *%T\", Decimal{}, NullDecimal{}, Decimal{})\n\tdefault:\n\t\terr = fmt.Errorf(\"type %T is not supported\", value)\n\t}\n\tif err != nil {\n\t\terr = fmt.Errorf(\"converting from %T to %T: %w\", value, Decimal{}, err)\n\t}\n\treturn err\n}\n\n// Value implements the [driver.Valuer] interface.\n//\n// [driver.Valuer]: https://pkg.go.dev/database/sql/driver#Valuer\nfunc (d Decimal) Value() (driver.Value, error) {\n\treturn d.String(), nil\n}\n\n// Format implements the [fmt.Formatter] interface.\n// The following [format verbs] are available:\n//\n//\t| Verb       | Example | Description    |\n//\t| ---------- | ------- | -------------- |\n//\t| %f, %s, %v | 5.67    | Decimal        |\n//\t| %q         | \"5.67\"  | Quoted decimal |\n//\t| %k         | 567%    | Percentage     |\n//\n// The following format flags can be used with all verbs: '+', ' ', '0', '-'.\n//\n// Precision is only supported for %f and %k verbs.\n// For %f verb, the default precision is equal to the actual scale of the decimal,\n// whereas, for verb %k the default precision is the actual scale of the decimal minus 2.\n//\n// [format verbs]: https://pkg.go.dev/fmt#hdr-Printing\n// [fmt.Formatter]: https://pkg.go.dev/fmt#Formatter\n//\n//nolint:gocyclo\nfunc (d Decimal) Format(state fmt.State, verb rune) {\n\tvar err error\n\n\t// Percentage multiplier\n\tif verb == 'k' || verb == 'K' {\n\t\td, err = d.Mul(Hundred)\n\t\tif err != nil {\n\t\t\t// This panic is handled inside the fmt package.\n\t\t\tpanic(fmt.Errorf(\"formatting percent: %w\", err))\n\t\t}\n\t}\n\n\t// Rescaling\n\tvar tzeros int\n\tif verb == 'f' || verb == 'F' || verb == 'k' || verb == 'K' {\n\t\tvar scale int\n\t\tswitch p, ok := state.Precision(); {\n\t\tcase ok:\n\t\t\tscale = p\n\t\tcase verb == 'k' || verb == 'K':\n\t\t\tscale = d.Scale() - 2\n\t\tcase verb == 'f' || verb == 'F':\n\t\t\tscale = d.Scale()\n\t\t}\n\t\tscale = max(scale, MinScale)\n\t\tswitch {\n\t\tcase scale < d.Scale():\n\t\t\td = d.Round(scale)\n\t\tcase scale > d.Scale():\n\t\t\ttzeros = scale - d.Scale()\n\t\t}\n\t}\n\n\t// Integer and fractional digits\n\tvar intdigs int\n\tfracdigs := d.Scale()\n\tif dprec := d.Prec(); dprec > fracdigs {\n\t\tintdigs = dprec - fracdigs\n\t}\n\tif d.WithinOne() {\n\t\tintdigs++ // leading 0\n\t}\n\n\t// Decimal point\n\tvar dpoint int\n\tif fracdigs > 0 || tzeros > 0 {\n\t\tdpoint = 1\n\t}\n\n\t// Arithmetic sign\n\tvar rsign int\n\tif d.IsNeg() || state.Flag('+') || state.Flag(' ') {\n\t\trsign = 1\n\t}\n\n\t// Percentage sign\n\tvar psign int\n\tif verb == 'k' || verb == 'K' {\n\t\tpsign = 1\n\t}\n\n\t// Openning and closing quotes\n\tvar lquote, tquote int\n\tif verb == 'q' || verb == 'Q' {\n\t\tlquote, tquote = 1, 1\n\t}\n\n\t// Calculating padding\n\twidth := lquote + rsign + intdigs + dpoint + fracdigs + tzeros + psign + tquote\n\tvar lspaces, tspaces, lzeros int\n\tif w, ok := state.Width(); ok && w > width {\n\t\tswitch {\n\t\tcase state.Flag('-'):\n\t\t\ttspaces = w - width\n\t\tcase state.Flag('0'):\n\t\t\tlzeros = w - width\n\t\tdefault:\n\t\t\tlspaces = w - width\n\t\t}\n\t\twidth = w\n\t}\n\n\tbuf := make([]byte, width)\n\tpos := width - 1\n\n\t// Trailing spaces\n\tfor range tspaces {\n\t\tbuf[pos] = ' '\n\t\tpos--\n\t}\n\n\t// Closing quote\n\tfor range tquote {\n\t\tbuf[pos] = '\"'\n\t\tpos--\n\t}\n\n\t// Percentage sign\n\tfor range psign {\n\t\tbuf[pos] = '%'\n\t\tpos--\n\t}\n\n\t// Trailing zeros\n\tfor range tzeros {\n\t\tbuf[pos] = '0'\n\t\tpos--\n\t}\n\n\t// Fractional digits\n\tdcoef := d.Coef()\n\tfor range fracdigs {\n\t\tbuf[pos] = byte(dcoef%10) + '0'\n\t\tpos--\n\t\tdcoef /= 10\n\t}\n\n\t// Decimal point\n\tfor range dpoint {\n\t\tbuf[pos] = '.'\n\t\tpos--\n\t}\n\n\t// Integer digits\n\tfor range intdigs {\n\t\tbuf[pos] = byte(dcoef%10) + '0'\n\t\tpos--\n\t\tdcoef /= 10\n\t}\n\n\t// Leading zeros\n\tfor range lzeros {\n\t\tbuf[pos] = '0'\n\t\tpos--\n\t}\n\n\t// Arithmetic sign\n\tfor range rsign {\n\t\tif d.IsNeg() {\n\t\t\tbuf[pos] = '-'\n\t\t} else if state.Flag(' ') {\n\t\t\tbuf[pos] = ' '\n\t\t} else {\n\t\t\tbuf[pos] = '+'\n\t\t}\n\t\tpos--\n\t}\n\n\t// Opening quote\n\tfor range lquote {\n\t\tbuf[pos] = '\"'\n\t\tpos--\n\t}\n\n\t// Leading spaces\n\tfor range lspaces {\n\t\tbuf[pos] = ' '\n\t\tpos--\n\t}\n\n\t// Writing result\n\t//nolint:errcheck\n\tswitch verb {\n\tcase 'q', 'Q', 's', 'S', 'v', 'V', 'f', 'F', 'k', 'K':\n\t\tstate.Write(buf)\n\tdefault:\n\t\tstate.Write([]byte(\"%!\"))\n\t\tstate.Write([]byte{byte(verb)})\n\t\tstate.Write([]byte(\"(decimal.Decimal=\"))\n\t\tstate.Write(buf)\n\t\tstate.Write([]byte(\")\"))\n\t}\n}\n\n// Zero returns a decimal with a value of 0, having the same scale as decimal d.\n// See also methods [Decimal.One], [Decimal.ULP].\nfunc (d Decimal) Zero() Decimal {\n\treturn newUnsafe(false, 0, d.Scale())\n}\n\n// One returns a decimal with a value of 1, having the same scale as decimal d.\n// See also methods [Decimal.Zero], [Decimal.ULP].\nfunc (d Decimal) One() Decimal {\n\treturn newUnsafe(false, pow10[d.Scale()], d.Scale())\n}\n\n// ULP (Unit in the Last Place) returns the smallest representable positive\n// difference between two decimals with the same scale as decimal d.\n// It can be useful for implementing rounding and comparison algorithms.\n// See also methods [Decimal.Zero], [Decimal.One].\nfunc (d Decimal) ULP() Decimal {\n\treturn newUnsafe(false, 1, d.Scale())\n}\n\n// Prec returns the number of digits in the coefficient.\n// See also method [Decimal.Coef].\nfunc (d Decimal) Prec() int {\n\treturn d.coef.prec()\n}\n\n// Coef returns the coefficient of the decimal.\n// See also method [Decimal.Prec].\nfunc (d Decimal) Coef() uint64 {\n\treturn uint64(d.coef)\n}\n\n// Scale returns the number of digits after the decimal point.\n// See also methods [Decimal.Prec], [Decimal.MinScale].\nfunc (d Decimal) Scale() int {\n\treturn int(d.scale)\n}\n\n// MinScale returns the smallest scale that the decimal can be rescaled to\n// without rounding.\n// See also method [Decimal.Trim].\nfunc (d Decimal) MinScale() int {\n\t// Special case: zero\n\tif d.IsZero() {\n\t\treturn MinScale\n\t}\n\t// General case\n\tdcoef := d.coef\n\treturn max(MinScale, d.Scale()-dcoef.ntz())\n}\n\n// IsInt returns true if there are no significant digits after the decimal point.\nfunc (d Decimal) IsInt() bool {\n\treturn d.Scale() == 0 || d.coef%pow10[d.Scale()] == 0\n}\n\n// IsOne returns:\n//\n//\ttrue  if d = -1 or d = 1\n//\tfalse otherwise\nfunc (d Decimal) IsOne() bool {\n\treturn d.coef == pow10[d.Scale()]\n}\n\n// WithinOne returns:\n//\n//\ttrue  if -1 < d < 1\n//\tfalse otherwise\nfunc (d Decimal) WithinOne() bool {\n\treturn d.coef < pow10[d.Scale()]\n}\n\n// Round returns a decimal rounded to the specified number of digits after\n// the decimal point using [rounding half to even] (banker's rounding).\n// If the given scale is negative, it is redefined to zero.\n// For financial calculations, the scale should be equal to or greater than\n// the scale of the currency.\n// See also method [Decimal.Rescale].\n//\n// [rounding half to even]: https://en.wikipedia.org/wiki/Rounding#Rounding_half_to_even\nfunc (d Decimal) Round(scale int) Decimal {\n\tscale = max(scale, MinScale)\n\tif scale >= d.Scale() {\n\t\treturn d\n\t}\n\tcoef := d.coef\n\tcoef = coef.rshHalfEven(d.Scale() - scale)\n\treturn newUnsafe(d.IsNeg(), coef, scale)\n}\n\n// Pad returns a decimal zero-padded to the specified number of digits after\n// the decimal point.\n// The total number of digits in the result is limited by [MaxPrec].\n// See also method [Decimal.Trim].\nfunc (d Decimal) Pad(scale int) Decimal {\n\tscale = min(scale, MaxScale, MaxPrec-d.Prec()+d.Scale())\n\tif scale <= d.Scale() {\n\t\treturn d\n\t}\n\tcoef := d.coef\n\tcoef, ok := coef.lsh(scale - d.Scale())\n\tif !ok {\n\t\treturn d // Should never happen\n\t}\n\treturn newUnsafe(d.IsNeg(), coef, scale)\n}\n\n// Rescale returns a decimal rounded or zero-padded to the given number of digits\n// after the decimal point.\n// If the given scale is negative, it is redefined to zero.\n// For financial calculations, the scale should be equal to or greater than\n// the scale of the currency.\n// See also methods [Decimal.Round], [Decimal.Pad].\nfunc (d Decimal) Rescale(scale int) Decimal {\n\tif scale > d.Scale() {\n\t\treturn d.Pad(scale)\n\t}\n\treturn d.Round(scale)\n}\n\n// Quantize returns a decimal rescaled to the same scale as decimal e.\n// The sign and the coefficient of decimal e are ignored.\n// See also methods [Decimal.SameScale] and [Decimal.Rescale].\nfunc (d Decimal) Quantize(e Decimal) Decimal {\n\treturn d.Rescale(e.Scale())\n}\n\n// SameScale returns true if decimals have the same scale.\n// See also methods [Decimal.Scale], [Decimal.Quantize].\nfunc (d Decimal) SameScale(e Decimal) bool {\n\treturn d.Scale() == e.Scale()\n}\n\n// Trunc returns a decimal truncated to the specified number of digits\n// after the decimal point using [rounding toward zero].\n// If the given scale is negative, it is redefined to zero.\n// For financial calculations, the scale should be equal to or greater than\n// the scale of the currency.\n//\n// [rounding toward zero]: https://en.wikipedia.org/wiki/Rounding#Rounding_toward_zero\nfunc (d Decimal) Trunc(scale int) Decimal {\n\tscale = max(scale, MinScale)\n\tif scale >= d.Scale() {\n\t\treturn d\n\t}\n\tcoef := d.coef\n\tcoef = coef.rshDown(d.Scale() - scale)\n\treturn newUnsafe(d.IsNeg(), coef, scale)\n}\n\n// Trim returns a decimal with trailing zeros removed up to the given number of\n// digits after the decimal point.\n// If the given scale is negative, it is redefined to zero.\n// See also method [Decimal.Pad].\nfunc (d Decimal) Trim(scale int) Decimal {\n\tif d.Scale() <= scale {\n\t\treturn d\n\t}\n\tscale = max(scale, d.MinScale())\n\treturn d.Trunc(scale)\n}\n\n// Ceil returns a decimal rounded up to the given number of digits\n// after the decimal point using [rounding toward positive infinity].\n// If the given scale is negative, it is redefined to zero.\n// For financial calculations, the scale should be equal to or greater than\n// the scale of the currency.\n// See also method [Decimal.Floor].\n//\n// [rounding toward positive infinity]: https://en.wikipedia.org/wiki/Rounding#Rounding_up\nfunc (d Decimal) Ceil(scale int) Decimal {\n\tscale = max(scale, MinScale)\n\tif scale >= d.Scale() {\n\t\treturn d\n\t}\n\tcoef := d.coef\n\tif d.IsNeg() {\n\t\tcoef = coef.rshDown(d.Scale() - scale)\n\t} else {\n\t\tcoef = coef.rshUp(d.Scale() - scale)\n\t}\n\treturn newUnsafe(d.IsNeg(), coef, scale)\n}\n\n// Floor returns a decimal rounded down to the specified number of digits\n// after the decimal point using [rounding toward negative infinity].\n// If the given scale is negative, it is redefined to zero.\n// For financial calculations, the scale should be equal to or greater than\n// the scale of the currency.\n// See also method [Decimal.Ceil].\n//\n// [rounding toward negative infinity]: https://en.wikipedia.org/wiki/Rounding#Rounding_down\nfunc (d Decimal) Floor(scale int) Decimal {\n\tscale = max(scale, MinScale)\n\tif scale >= d.Scale() {\n\t\treturn d\n\t}\n\tcoef := d.coef\n\tif d.IsNeg() {\n\t\tcoef = coef.rshUp(d.Scale() - scale)\n\t} else {\n\t\tcoef = coef.rshDown(d.Scale() - scale)\n\t}\n\treturn newUnsafe(d.IsNeg(), coef, scale)\n}\n\n// Neg returns a decimal with the opposite sign.\nfunc (d Decimal) Neg() Decimal {\n\treturn newUnsafe(!d.IsNeg(), d.coef, d.Scale())\n}\n\n// Abs returns the absolute value of the decimal.\nfunc (d Decimal) Abs() Decimal {\n\treturn newUnsafe(false, d.coef, d.Scale())\n}\n\n// CopySign returns a decimal with the same sign as decimal e.\n// CopySign treates 0 as positive.\n// See also method [Decimal.Sign].\nfunc (d Decimal) CopySign(e Decimal) Decimal {\n\tif d.IsNeg() == e.IsNeg() {\n\t\treturn d\n\t}\n\treturn d.Neg()\n}\n\n// Sign returns:\n//\n//\t-1 if d < 0\n//\t 0 if d = 0\n//\t+1 if d > 0\n//\n// See also methods [Decimal.IsPos], [Decimal.IsNeg], [Decimal.IsZero].\nfunc (d Decimal) Sign() int {\n\tswitch {\n\tcase d.neg:\n\t\treturn -1\n\tcase d.coef == 0:\n\t\treturn 0\n\t}\n\treturn 1\n}\n\n// IsPos returns:\n//\n//\ttrue  if d > 0\n//\tfalse otherwise\nfunc (d Decimal) IsPos() bool {\n\treturn d.coef != 0 && !d.neg\n}\n\n// IsNeg returns:\n//\n//\ttrue  if d < 0\n//\tfalse otherwise\nfunc (d Decimal) IsNeg() bool {\n\treturn d.neg\n}\n\n// IsZero returns:\n//\n//\ttrue  if d = 0\n//\tfalse otherwise\nfunc (d Decimal) IsZero() bool {\n\treturn d.coef == 0\n}\n\n// Prod returns the (possibly rounded) product of decimals.\n// It computes d1 * d2 * ... * dn with at least double precision\n// during the intermediate rounding.\n//\n// Prod returns an error if:\n//   - no arguments are provided;\n//   - the integer part of the result has more than [MaxPrec] digits.\nfunc Prod(d ...Decimal) (Decimal, error) {\n\t// Special cases\n\tswitch len(d) {\n\tcase 0:\n\t\treturn Decimal{}, fmt.Errorf(\"computing [prod([])]: %w\", errInvalidOperation)\n\tcase 1:\n\t\treturn d[0], nil\n\t}\n\n\t// General case\n\te, err := prodFint(d...)\n\tif err != nil {\n\t\te, err = prodBint(d...)\n\t\tif err != nil {\n\t\t\treturn Decimal{}, fmt.Errorf(\"computing [prod(%v)]: %w\", d, err)\n\t\t}\n\t}\n\n\treturn e, nil\n}\n\n// prodFint computes the product of decimals using uint64 arithmetic.\nfunc prodFint(d ...Decimal) (Decimal, error) {\n\tecoef := One.coef\n\tescale := One.Scale()\n\teneg := One.IsNeg()\n\n\tfor _, f := range d {\n\t\tfcoef := f.coef\n\n\t\t// Compute e = e * f\n\t\tvar ok bool\n\t\tecoef, ok = ecoef.mul(fcoef)\n\t\tif !ok {\n\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t}\n\t\teneg = eneg != f.IsNeg()\n\t\tescale = escale + f.Scale()\n\t}\n\n\treturn newFromFint(eneg, ecoef, escale, 0)\n}\n\n// prodBint computes the product of decimals using *big.Int arithmetic.\nfunc prodBint(d ...Decimal) (Decimal, error) {\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tfcoef := getBint()\n\tdefer putBint(fcoef)\n\n\tecoef.setFint(One.coef)\n\tescale := One.Scale()\n\teneg := One.IsNeg()\n\n\tfor _, f := range d {\n\t\tfcoef.setFint(f.coef)\n\n\t\t// Compute e = e * f\n\t\tecoef.mul(ecoef, fcoef)\n\t\teneg = eneg != f.IsNeg()\n\t\tescale = escale + f.Scale()\n\n\t\t// Intermediate truncation\n\t\tif escale > bscale {\n\t\t\tecoef.rshDown(ecoef, escale-bscale)\n\t\t\tescale = bscale\n\t\t}\n\n\t\t// Check if e >= 10^59\n\t\tif ecoef.hasPrec(len(bpow10)) {\n\t\t\treturn Decimal{}, unknownOverflowError()\n\t\t}\n\t}\n\n\treturn newFromBint(eneg, ecoef, escale, 0)\n}\n\n// Mean returns the (possibly rounded) mean of decimals.\n// It computes (d1 + d2 + ... + dn) / n with at least double precision\n// during the intermediate rounding.\n//\n// Mean returns an error if:\n//   - no arguments are provided;\n//   - the integer part of the result has more than [MaxPrec] digits.\nfunc Mean(d ...Decimal) (Decimal, error) {\n\t// Special cases\n\tswitch len(d) {\n\tcase 0:\n\t\treturn Decimal{}, fmt.Errorf(\"computing [mean([])]: %w\", errInvalidOperation)\n\tcase 1:\n\t\treturn d[0], nil\n\t}\n\n\t// General case\n\te, err := meanFint(d...)\n\tif err != nil {\n\t\te, err = meanBint(d...)\n\t\tif err != nil {\n\t\t\treturn Decimal{}, fmt.Errorf(\"computing [mean(%v)]: %w\", d, err)\n\t\t}\n\t}\n\n\t// Preferred scale\n\tscale := 0\n\tfor _, f := range d {\n\t\tscale = max(scale, f.Scale())\n\t}\n\te = e.Trim(scale)\n\n\treturn e, nil\n}\n\n// meanFint computes the mean of decimals using uint64 arithmetic.\nfunc meanFint(d ...Decimal) (Decimal, error) {\n\tecoef := Zero.coef\n\tescale := Zero.Scale()\n\teneg := Zero.IsNeg()\n\n\tncoef := fint(len(d))\n\n\tfor _, f := range d {\n\t\tfcoef := f.coef\n\n\t\t// Alignment\n\t\tvar ok bool\n\t\tswitch {\n\t\tcase escale > f.Scale():\n\t\t\tfcoef, ok = fcoef.lsh(escale - f.Scale())\n\t\t\tif !ok {\n\t\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t\t}\n\t\tcase escale < f.Scale():\n\t\t\tecoef, ok = ecoef.lsh(f.Scale() - escale)\n\t\t\tif !ok {\n\t\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t\t}\n\t\t\tescale = f.Scale()\n\t\t}\n\n\t\t// Compute e = e + f\n\t\tif eneg == f.IsNeg() {\n\t\t\tecoef, ok = ecoef.add(fcoef)\n\t\t\tif !ok {\n\t\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t\t}\n\t\t} else {\n\t\t\tif fcoef > ecoef {\n\t\t\t\teneg = f.IsNeg()\n\t\t\t}\n\t\t\tecoef = ecoef.subAbs(fcoef)\n\t\t}\n\t}\n\n\t// Alignment\n\tvar ok bool\n\tif shift := MaxPrec - ecoef.prec(); shift > 0 {\n\t\tecoef, ok = ecoef.lsh(shift)\n\t\tif !ok {\n\t\t\treturn Decimal{}, errDecimalOverflow // Should never happen\n\t\t}\n\t\tescale = escale + shift\n\t}\n\n\t// Compute e = e / n\n\tecoef, ok = ecoef.quo(ncoef)\n\tif !ok {\n\t\treturn Decimal{}, errInexactDivision\n\t}\n\n\treturn newFromFint(eneg, ecoef, escale, 0)\n}\n\n// meanBint computes the mean of decimals using *big.Int arithmetic.\nfunc meanBint(d ...Decimal) (Decimal, error) {\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tfcoef := getBint()\n\tdefer putBint(fcoef)\n\n\tncoef := getBint()\n\tdefer putBint(ncoef)\n\n\tecoef.setFint(Zero.coef)\n\tescale := Zero.Scale()\n\teneg := Zero.IsNeg()\n\tncoef.setInt64(int64(len(d)))\n\n\tfor _, f := range d {\n\t\tfcoef.setFint(f.coef)\n\n\t\t// Alignment\n\t\tswitch {\n\t\tcase escale > f.Scale():\n\t\t\tfcoef.lsh(fcoef, escale-f.Scale())\n\t\tcase escale < f.Scale():\n\t\t\tecoef.lsh(ecoef, f.Scale()-escale)\n\t\t\tescale = f.Scale()\n\t\t}\n\n\t\t// Compute e = e + f\n\t\tif eneg == f.IsNeg() {\n\t\t\tecoef.add(ecoef, fcoef)\n\t\t} else {\n\t\t\tif fcoef.cmp(ecoef) > 0 {\n\t\t\t\teneg = f.IsNeg()\n\t\t\t}\n\t\t\tecoef.subAbs(ecoef, fcoef)\n\t\t}\n\t}\n\n\t// Alignment\n\tecoef.lsh(ecoef, bscale-escale)\n\n\t// Compute e = e / n\n\tecoef.quo(ecoef, ncoef)\n\n\treturn newFromBint(eneg, ecoef, bscale, 0)\n}\n\n// Mul returns the (possibly rounded) product of decimals d and e.\n//\n// Mul returns an overflow error if the integer part of the result has\n// more than [MaxPrec] digits.\nfunc (d Decimal) Mul(e Decimal) (Decimal, error) {\n\treturn d.MulExact(e, 0)\n}\n\n// MulExact is similar to [Decimal.Mul], but it allows you to specify the number\n// of digits after the decimal point that should be considered significant.\n// If any of the significant digits are lost during rounding, the method will\n// return an overflow error.\n// This method is useful for financial calculations where the scale should be\n// equal to or greater than the currency's scale.\nfunc (d Decimal) MulExact(e Decimal, scale int) (Decimal, error) {\n\tif scale < MinScale || scale > MaxScale {\n\t\treturn Decimal{}, fmt.Errorf(\"computing [%v * %v]: %w\", d, e, errScaleRange)\n\t}\n\n\t// General case\n\tf, err := d.mulFint(e, scale)\n\tif err != nil {\n\t\tf, err = d.mulBint(e, scale)\n\t\tif err != nil {\n\t\t\treturn Decimal{}, fmt.Errorf(\"computing [%v * %v]: %w\", d, e, err)\n\t\t}\n\t}\n\treturn f, nil\n}\n\n// mulFint computes the product of two decimals using uint64 arithmetic.\nfunc (d Decimal) mulFint(e Decimal, minScale int) (Decimal, error) {\n\tdcoef := d.coef\n\tdscale := d.Scale()\n\tdneg := d.IsNeg()\n\n\tecoef := e.coef\n\n\t// Compute d = d * e\n\tdcoef, ok := dcoef.mul(ecoef)\n\tif !ok {\n\t\treturn Decimal{}, errDecimalOverflow\n\t}\n\tdscale = dscale + e.Scale()\n\tdneg = dneg != e.IsNeg()\n\n\treturn newFromFint(dneg, dcoef, dscale, minScale)\n}\n\n// mulBint computes the product of two decimals using *big.Int arithmetic.\nfunc (d Decimal) mulBint(e Decimal, minScale int) (Decimal, error) {\n\tdcoef := getBint()\n\tdefer putBint(dcoef)\n\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tdcoef.setFint(d.coef)\n\tdscale := d.Scale()\n\tdneg := d.IsNeg()\n\tecoef.setFint(e.coef)\n\n\t// Compute d = d * e\n\tdcoef.mul(dcoef, ecoef)\n\tdneg = dneg != e.IsNeg()\n\tdscale = dscale + e.Scale()\n\n\treturn newFromBint(dneg, dcoef, dscale, minScale)\n}\n\n// Pow returns the (possibly rounded) decimal raised to the given decimal power.\n// If zero is raised to zero power then the result is one.\n//\n// Pow returns an error if:\n//   - the integer part of the result has more than [MaxPrec] digits;\n//   - zero is raised to a negative power;\n//   - negative is raised to a fractional power.\nfunc (d Decimal) Pow(e Decimal) (Decimal, error) {\n\t// Special case: zero to a negative power\n\tif e.IsNeg() && d.IsZero() {\n\t\treturn Decimal{}, fmt.Errorf(\"computing [%v^%v]: %w: zero to negative power\", d, e, errInvalidOperation)\n\t}\n\n\t// Special case: integer power\n\tif e.IsInt() {\n\t\tpower := e.Trunc(0).Coef()\n\t\tf, err := d.powIntFint(power, e.IsNeg())\n\t\tif err != nil {\n\t\t\tf, err = d.powIntBint(power, e.IsNeg())\n\t\t\tif err != nil {\n\t\t\t\treturn Decimal{}, fmt.Errorf(\"computing [%v^%v]: %w\", d, e, err)\n\t\t\t}\n\t\t}\n\n\t\t// Preferred scale\n\t\tif e.IsNeg() {\n\t\t\tf = f.Trim(0)\n\t\t}\n\n\t\treturn f, nil\n\t}\n\n\t// Special case: zero to a fractional power\n\tif d.IsZero() {\n\t\treturn newSafe(false, 0, 0)\n\t}\n\n\t// Special case: negative to a fractional power\n\tif d.IsNeg() {\n\t\treturn Decimal{}, fmt.Errorf(\"computing [%v^%v]: %w: negative to fractional power\", d, e, errInvalidOperation)\n\t}\n\n\t// General case\n\tf, err := d.powBint(e)\n\tif err != nil {\n\t\treturn Decimal{}, fmt.Errorf(\"computing [%v^%v]: %w\", d, e, err)\n\t}\n\n\treturn f, nil\n}\n\n// powBint computes the power of a decimal using *big.Int arithmetic.\nfunc (d Decimal) powBint(e Decimal) (Decimal, error) {\n\tdcoef := getBint()\n\tdefer putBint(dcoef)\n\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tfcoef := getBint()\n\tdefer putBint(fcoef)\n\n\tdcoef.setFint(d.coef)\n\tecoef.setFint(e.coef)\n\tinv := false\n\n\t// Alignment\n\tif d.WithinOne() {\n\t\t// Compute d = ⌊1 / d⌋\n\t\tdcoef.quo(bpow10[bscale+d.Scale()], dcoef)\n\t\tinv = true\n\t} else {\n\t\tdcoef.lsh(dcoef, bscale-d.Scale())\n\t}\n\n\t// Compute f = log(d)\n\tfcoef.log(dcoef)\n\n\t// Compute f = ⌊f * e⌋\n\tfcoef.mul(fcoef, ecoef)\n\tfcoef.rshDown(fcoef, e.Scale())\n\tinv = inv != e.IsNeg()\n\n\t// Check if f <= -100 or f >= 100\n\tif fcoef.hasPrec(3 + bscale) {\n\t\tif !inv {\n\t\t\treturn Decimal{}, unknownOverflowError()\n\t\t}\n\t\treturn newSafe(false, 0, MaxScale)\n\t}\n\n\t// Compute f = exp(f)\n\tfcoef.exp(fcoef)\n\n\tif inv {\n\t\t// Compute f = ⌊1 / f⌋\n\t\tfcoef.quo(bpow10[2*bscale], fcoef)\n\t}\n\n\treturn newFromBint(false, fcoef, bscale, 0)\n}\n\n// PowInt returns the (possibly rounded) decimal raised to the given integer power.\n// If zero is raised to zero power then the result is one.\n//\n// PowInt returns an error if:\n//   - the integer part of the result has more than [MaxPrec] digits;\n//   - zero is raised to a negative power.\nfunc (d Decimal) PowInt(power int) (Decimal, error) {\n\tvar pow uint64\n\tvar neg bool\n\tif power >= 0 {\n\t\tneg = false\n\t\tpow = uint64(power)\n\t} else {\n\t\tneg = true\n\t\tif power == math.MinInt {\n\t\t\tpow = uint64(math.MaxInt) + 1\n\t\t} else {\n\t\t\tpow = uint64(-power)\n\t\t}\n\t}\n\n\t// Special case: zero to a negative power\n\tif neg && d.IsZero() {\n\t\treturn Decimal{}, fmt.Errorf(\"computing [%v^%v]: %w: zero to negative power\", d, power, errInvalidOperation)\n\t}\n\n\t// General case\n\te, err := d.powIntFint(pow, neg)\n\tif err != nil {\n\t\te, err = d.powIntBint(pow, neg)\n\t\tif err != nil {\n\t\t\treturn Decimal{}, fmt.Errorf(\"computing [%v^%v]: %w\", d, power, err)\n\t\t}\n\t}\n\n\t// Preferred scale\n\tif neg {\n\t\te = e.Trim(0)\n\t}\n\n\treturn e, nil\n}\n\n// powIntFint computes the integer power of a decimal using uint64 arithmetic.\n// powIntFint does not support negative powers.\nfunc (d Decimal) powIntFint(pow uint64, inv bool) (Decimal, error) {\n\tif inv {\n\t\treturn Decimal{}, errInvalidOperation\n\t}\n\n\tdcoef := d.coef\n\tdneg := d.IsNeg()\n\tdscale := d.Scale()\n\n\tecoef := One.coef\n\teneg := One.IsNeg()\n\tescale := One.Scale()\n\n\t// Exponentiation by squaring\n\tvar ok bool\n\tfor pow > 0 {\n\t\tif pow%2 == 1 {\n\t\t\tpow = pow - 1\n\n\t\t\t// Compute e = e * d\n\t\t\tecoef, ok = ecoef.mul(dcoef)\n\t\t\tif !ok {\n\t\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t\t}\n\t\t\teneg = eneg != dneg\n\t\t\tescale = escale + dscale\n\t\t}\n\t\tif pow > 0 {\n\t\t\tpow = pow / 2\n\n\t\t\t// Compute d = d * d\n\t\t\tdcoef, ok = dcoef.mul(dcoef)\n\t\t\tif !ok {\n\t\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t\t}\n\t\t\tdneg = false\n\t\t\tdscale = dscale * 2\n\t\t}\n\t}\n\n\treturn newFromFint(eneg, ecoef, escale, 0)\n}\n\n// powIntBint computes the integer power of a decimal using *big.Int arithmetic.\n// powIntBint supports negative powers.\nfunc (d Decimal) powIntBint(pow uint64, inv bool) (Decimal, error) {\n\tdcoef := getBint()\n\tdefer putBint(dcoef)\n\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tdcoef.setFint(d.coef)\n\tdneg := d.IsNeg()\n\tdscale := d.Scale()\n\n\tecoef.setFint(One.coef)\n\teneg := One.IsNeg()\n\tescale := One.Scale()\n\n\t// Exponentiation by squaring\n\tfor pow > 0 {\n\t\tif pow%2 == 1 {\n\t\t\tpow = pow - 1\n\n\t\t\t// Compute e = e * d\n\t\t\tecoef.mul(ecoef, dcoef)\n\t\t\teneg = eneg != dneg\n\t\t\tescale = escale + dscale\n\n\t\t\t// Intermediate truncation\n\t\t\tif escale > bscale {\n\t\t\t\tecoef.rshDown(ecoef, escale-bscale)\n\t\t\t\tescale = bscale\n\t\t\t}\n\n\t\t\t// Check if e <= -10^59 or e >= 10^59\n\t\t\tif ecoef.hasPrec(len(bpow10)) {\n\t\t\t\tif !inv {\n\t\t\t\t\treturn Decimal{}, unknownOverflowError()\n\t\t\t\t}\n\t\t\t\treturn newSafe(false, 0, MaxScale)\n\t\t\t}\n\t\t}\n\t\tif pow > 0 {\n\t\t\tpow = pow / 2\n\n\t\t\t// Compute d = d * d\n\t\t\tdcoef.mul(dcoef, dcoef)\n\t\t\tdneg = false\n\t\t\tdscale = dscale * 2\n\n\t\t\t// Intermediate truncation\n\t\t\tif dscale > bscale {\n\t\t\t\tdcoef.rshDown(dcoef, dscale-bscale)\n\t\t\t\tdscale = bscale\n\t\t\t}\n\n\t\t\t// Check if d <= -10^59 or d >= 10^59\n\t\t\tif dcoef.hasPrec(len(bpow10)) {\n\t\t\t\tif !inv {\n\t\t\t\t\treturn Decimal{}, unknownOverflowError()\n\t\t\t\t}\n\t\t\t\treturn newSafe(false, 0, MaxScale)\n\t\t\t}\n\t\t}\n\t}\n\n\tif inv {\n\t\tif ecoef.sign() == 0 {\n\t\t\treturn Decimal{}, unknownOverflowError()\n\t\t}\n\n\t\t// Compute e = ⌊1 / e⌋\n\t\tecoef.quo(bpow10[bscale+escale], ecoef)\n\t\tescale = bscale\n\t}\n\n\treturn newFromBint(eneg, ecoef, escale, 0)\n}\n\n// Sqrt computes the (possibly rounded) square root of a decimal.\n// d.Sqrt() is significantly faster than d.Pow(0.5).\n//\n// Sqrt returns an error if the decimal is negative.\nfunc (d Decimal) Sqrt() (Decimal, error) {\n\t// Special case: negative\n\tif d.IsNeg() {\n\t\treturn Decimal{}, fmt.Errorf(\"computing sqrt(%v): %w: square root of negative\", d, errInvalidOperation)\n\t}\n\n\t// Special case: zero\n\tif d.IsZero() {\n\t\treturn newSafe(false, 0, d.Scale()/2)\n\t}\n\n\t// General case\n\te, err := d.sqrtBint()\n\tif err != nil {\n\t\treturn Decimal{}, fmt.Errorf(\"computing sqrt(%v): %w\", d, err)\n\t}\n\n\t// Preferred scale\n\te = e.Trim(d.Scale() / 2)\n\n\treturn e, nil\n}\n\n// sqrtBint computes the square root of a decimal using *big.Int arithmetic.\nfunc (d Decimal) sqrtBint() (Decimal, error) {\n\tdcoef := getBint()\n\tdefer putBint(dcoef)\n\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tfcoef := getBint()\n\tdefer putBint(fcoef)\n\n\tdcoef.setFint(d.coef)\n\tfcoef.setFint(0)\n\n\t// Alignment\n\tdcoef.lsh(dcoef, 2*bscale-d.Scale())\n\n\t// Initial guess is calculated as 10^(n/2),\n\t// where n is the position of the most significant digit.\n\tn := dcoef.prec() - 2*bscale\n\tecoef.setBint(bpow10[n/2+bscale])\n\n\t// Newton's method\n\tfor range 50 {\n\t\tif ecoef.cmp(fcoef) == 0 {\n\t\t\tbreak\n\t\t}\n\t\tfcoef.setBint(ecoef)\n\t\tecoef.quo(dcoef, ecoef)\n\t\tecoef.add(ecoef, fcoef)\n\t\tecoef.hlf(ecoef)\n\t}\n\n\treturn newFromBint(false, ecoef, bscale, 0)\n}\n\n// Log2 returns the (possibly rounded) binary logarithm of a decimal.\n//\n// Log2 returns an error if the decimal is zero or negative.\nfunc (d Decimal) Log2() (Decimal, error) {\n\t// Special case: zero or negative\n\tif !d.IsPos() {\n\t\treturn Decimal{}, fmt.Errorf(\"computing log2(%v): %w: logarithm of non-positive\", d, errInvalidOperation)\n\t}\n\n\t// Special case: one\n\tif d.IsOne() {\n\t\treturn newSafe(false, 0, 0)\n\t}\n\n\t// General case\n\te, err := d.log2Bint()\n\tif err != nil {\n\t\treturn Decimal{}, fmt.Errorf(\"computing log2(%v): %w\", d, err)\n\t}\n\n\t// Preferred scale\n\tif e.IsInt() {\n\t\t// According to the GDA, only integer powers of 2 should be trimmed to zero scale.\n\t\t// However, such validation is slow, so we will trim all integers.\n\t\te = e.Trunc(0)\n\t}\n\n\treturn e, nil\n}\n\n// log2Bint computes the binary logarithm of a decimal using *big.Int arithmetic.\nfunc (d Decimal) log2Bint() (Decimal, error) {\n\tdcoef := getBint()\n\tdefer putBint(dcoef)\n\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tdcoef.setFint(d.coef)\n\teneg := false\n\n\t// Alignment\n\tif d.WithinOne() {\n\t\t// Compute d = ⌊1 / d⌋\n\t\tdcoef.quo(bpow10[bscale+d.Scale()], dcoef)\n\t\teneg = true\n\t} else {\n\t\tdcoef.lsh(dcoef, bscale-d.Scale())\n\t}\n\n\t// Compute e = log(d)\n\tecoef.log(dcoef)\n\n\t// Compute e = e / log(2)\n\tecoef.lsh(ecoef, bscale)\n\tecoef.quo(ecoef, blog[2])\n\n\treturn newFromBint(eneg, ecoef, bscale, 0)\n}\n\n// Log10 returns the (possibly rounded) decimal logarithm of a decimal.\n//\n// Log10 returns an error if the decimal is zero or negative.\nfunc (d Decimal) Log10() (Decimal, error) {\n\t// Special case: zero or negative\n\tif !d.IsPos() {\n\t\treturn Decimal{}, fmt.Errorf(\"computing log10(%v): %w: logarithm of non-positive\", d, errInvalidOperation)\n\t}\n\n\t// Special case: one\n\tif d.IsOne() {\n\t\treturn newSafe(false, 0, 0)\n\t}\n\n\t// General case\n\te, err := d.log10Bint()\n\tif err != nil {\n\t\treturn Decimal{}, fmt.Errorf(\"computing log10(%v): %w\", d, err)\n\t}\n\n\t// Preferred scale\n\tif e.IsInt() {\n\t\t// According to the GDA, only integer powers of 10 should be trimmed to zero scale.\n\t\t// However, such validation is slow, so we will trim all integers.\n\t\te = e.Trunc(0)\n\t}\n\n\treturn e, nil\n}\n\n// log10Bint computes the decimal logarithm of a decimal using *big.Int arithmetic.\nfunc (d Decimal) log10Bint() (Decimal, error) {\n\tdcoef := getBint()\n\tdefer putBint(dcoef)\n\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tdcoef.setFint(d.coef)\n\teneg := false\n\n\t// Alignment\n\tif d.WithinOne() {\n\t\t// Compute d = ⌊1 / d⌋\n\t\tdcoef.quo(bpow10[bscale+d.Scale()], dcoef)\n\t\teneg = true\n\t} else {\n\t\tdcoef.lsh(dcoef, bscale-d.Scale())\n\t}\n\n\t// Compute e = log(d)\n\tecoef.log(dcoef)\n\n\t// Compute e = ⌊e / log(10)⌋\n\tecoef.lsh(ecoef, bscale)\n\tecoef.quo(ecoef, blog[10])\n\n\treturn newFromBint(eneg, ecoef, bscale, 0)\n}\n\n// Log1p returns the (possibly rounded) shifted natural logarithm of a decimal.\n//\n// Log1p returns an error if the decimal is equal to or less than negative one.\nfunc (d Decimal) Log1p() (Decimal, error) {\n\tif d.IsNeg() && d.Cmp(NegOne) <= 0 {\n\t\treturn Decimal{}, fmt.Errorf(\"computing log1p(%v): %w: logarithm of a decimal less than or equal to -1\", d, errInvalidOperation)\n\t}\n\n\t// Special case: zero\n\tif d.IsZero() {\n\t\treturn newSafe(false, 0, 0)\n\t}\n\n\t// General case\n\te, err := d.log1pBint()\n\tif err != nil {\n\t\treturn Decimal{}, fmt.Errorf(\"computing log1p(%v): %w\", d, err)\n\t}\n\n\treturn e, nil\n}\n\n// log1pBint computes the shifted natural logarithm of a decimal using *big.Int arithmetic.\nfunc (d Decimal) log1pBint() (Decimal, error) {\n\tdcoef := getBint()\n\tdefer putBint(dcoef)\n\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tdcoef.setFint(d.coef)\n\teneg := false\n\n\t// Alignment\n\tif d.IsNeg() {\n\t\t// Compute d = ⌊1 / (d + 1)⌋\n\t\tdcoef.subAbs(dcoef, bpow10[d.Scale()])\n\t\tdcoef.quo(bpow10[bscale+d.Scale()], dcoef)\n\t\teneg = true\n\t} else {\n\t\t// Compute d = d + 1\n\t\tdcoef.add(dcoef, bpow10[d.Scale()])\n\t\tdcoef.lsh(dcoef, bscale-d.Scale())\n\t}\n\n\t// Compute e = log(d)\n\tecoef.log(dcoef)\n\n\treturn newFromBint(eneg, ecoef, bscale, 0)\n}\n\n// Log returns the (possibly rounded) natural logarithm of a decimal.\n//\n// Log returns an error if the decimal is zero or negative.\nfunc (d Decimal) Log() (Decimal, error) {\n\t// Special case: zero or negative\n\tif !d.IsPos() {\n\t\treturn Decimal{}, fmt.Errorf(\"computing log(%v): %w: logarithm of non-positive\", d, errInvalidOperation)\n\t}\n\n\t// Special case: one\n\tif d.IsOne() {\n\t\treturn newSafe(false, 0, 0)\n\t}\n\n\t// General case\n\te, err := d.logBint()\n\tif err != nil {\n\t\treturn Decimal{}, fmt.Errorf(\"computing log(%v): %w\", d, err)\n\t}\n\n\treturn e, nil\n}\n\n// logBint computes the natural logarithm of a decimal using *big.Int arithmetic.\nfunc (d Decimal) logBint() (Decimal, error) {\n\tdcoef := getBint()\n\tdefer putBint(dcoef)\n\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tdcoef.setFint(d.coef)\n\teneg := false\n\n\t// Alignment\n\tif d.WithinOne() {\n\t\t// Compute d = ⌊1 / d⌋\n\t\tdcoef.quo(bpow10[bscale+d.Scale()], dcoef)\n\t\teneg = true\n\t} else {\n\t\tdcoef.lsh(dcoef, bscale-d.Scale())\n\t}\n\n\t// Compute e = log(d)\n\tecoef.log(dcoef)\n\n\treturn newFromBint(eneg, ecoef, bscale, 0)\n}\n\n// log calculates z = log(x) using Halley's method.\n// The argument x must satisfy x >= 1, otherwise the result is undefined.\n// x must be represented as a big integer: round(x * 10^41).\n// The result z is represented as a big integer: round(z * 10^41).\nfunc (z *bint) log(x *bint) {\n\tzcoef := getBint()\n\tdefer putBint(zcoef)\n\n\tfcoef := getBint()\n\tdefer putBint(fcoef)\n\n\tEcoef := getBint()\n\tdefer putBint(Ecoef)\n\n\tncoef := getBint()\n\tdefer putBint(ncoef)\n\n\tmcoef := getBint()\n\tdefer putBint(mcoef)\n\n\tfcoef.setFint(0)\n\n\t// The initial guess is calculated as n*ln(10),\n\t// where n is the position of the most significant digit.\n\tn := x.prec() - bscale\n\tzcoef.setBint(bnlog10[n])\n\n\t// Halley's method\n\tfor range 50 {\n\t\tEcoef.exp(zcoef)\n\t\tncoef.sub(Ecoef, x)\n\t\tncoef.dbl(ncoef)\n\t\tmcoef.add(Ecoef, x)\n\t\tncoef.lsh(ncoef, bscale)\n\t\tncoef.quo(ncoef, mcoef)\n\t\tfcoef.sub(zcoef, ncoef)\n\t\tif zcoef.cmp(fcoef) == 0 {\n\t\t\tbreak\n\t\t}\n\t\tzcoef.setBint(fcoef)\n\t}\n\n\tz.setBint(zcoef)\n}\n\n// Exp returns the (possibly rounded) exponential of a decimal.\n//\n// Exp returns an error if the integer part of the result has more than [MaxPrec] digits.\nfunc (d Decimal) Exp() (Decimal, error) {\n\t// Special case: zero\n\tif d.IsZero() {\n\t\treturn newSafe(false, 1, 0)\n\t}\n\n\t// Special case: overflow\n\tif d.CmpAbs(Hundred) >= 0 {\n\t\tif !d.IsNeg() {\n\t\t\treturn Decimal{}, fmt.Errorf(\"computing exp(%v): %w\", d, unknownOverflowError())\n\t\t}\n\t\treturn newSafe(false, 0, MaxScale)\n\t}\n\n\t// General case\n\te, err := d.expBint()\n\tif err != nil {\n\t\treturn Decimal{}, fmt.Errorf(\"computing exp(%v): %w\", d, err)\n\t}\n\n\treturn e, nil\n}\n\n// expBint computes exponential of a decimal using *big.Int arithmetic.\nfunc (d Decimal) expBint() (Decimal, error) {\n\tdcoef := getBint()\n\tdefer putBint(dcoef)\n\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tdcoef.setFint(d.coef)\n\n\t// Alignment\n\tdcoef.lsh(dcoef, bscale-d.Scale())\n\n\t// Compute e = exp(d)\n\tecoef.exp(dcoef)\n\n\tif d.IsNeg() {\n\t\tif ecoef.sign() == 0 {\n\t\t\treturn Decimal{}, unknownOverflowError()\n\t\t}\n\t\t// Compute e = ⌊1 / e⌋\n\t\tecoef.quo(bpow10[2*bscale], ecoef)\n\t}\n\n\treturn newFromBint(false, ecoef, bscale, 0)\n}\n\n// Expm1 returns the (possibly rounded) shifted exponential of a decimal.\n//\n// Expm1 returns an error if the integer part of the result has more than [MaxPrec] digits.\nfunc (d Decimal) Expm1() (Decimal, error) {\n\t// Special case: zero\n\tif d.IsZero() {\n\t\treturn newSafe(false, 0, 0)\n\t}\n\n\t// Special case: overflow\n\tif d.CmpAbs(Hundred) >= 0 {\n\t\tif !d.IsNeg() {\n\t\t\treturn Decimal{}, fmt.Errorf(\"computing expm1(%v): %w\", d, unknownOverflowError())\n\t\t}\n\t\treturn newSafe(true, pow10[MaxScale-1], MaxScale-1)\n\t}\n\n\t// General case\n\te, err := d.expm1Bint()\n\tif err != nil {\n\t\treturn Decimal{}, fmt.Errorf(\"computing expm1(%v): %w\", d, err)\n\t}\n\n\treturn e, nil\n}\n\n// expm1Bint computes shifted exponential of a decimal using *big.Int arithmetic.\nfunc (d Decimal) expm1Bint() (Decimal, error) {\n\tdcoef := getBint()\n\tdefer putBint(dcoef)\n\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tdcoef.setFint(d.coef)\n\n\t// Alignment\n\tdcoef.lsh(dcoef, bscale-d.Scale())\n\n\t// Compute e = exp(d)\n\tecoef.exp(dcoef)\n\n\tif d.IsNeg() {\n\t\tif ecoef.sign() == 0 {\n\t\t\treturn Decimal{}, unknownOverflowError()\n\t\t}\n\t\t// Compute e = ⌊1 / e⌋\n\t\tecoef.quo(bpow10[2*bscale], ecoef)\n\t}\n\n\t// Compute e = e - 1\n\teneg := false\n\tif ecoef.cmp(bpow10[bscale]) < 0 {\n\t\teneg = true\n\t}\n\tecoef.subAbs(ecoef, bpow10[bscale])\n\n\treturn newFromBint(eneg, ecoef, bscale, 0)\n}\n\n// exp calculates z = exp(x) using Taylor series expansion.\n// The argument x must satisfy 0 <= x < 100, otherwise the result is undefined.\n// The argument x must be represented as a big integer: round(x * 10^41).\n// The result z is represented as a big integer: round(z * 10^41).\nfunc (z *bint) exp(x *bint) {\n\tqcoef := getBint()\n\tdefer putBint(qcoef)\n\n\trcoef := getBint()\n\tdefer putBint(rcoef)\n\n\t// Split x into integer part q and fractional part r\n\tqcoef.quoRem(x, bpow10[bscale], rcoef)\n\n\t// Retrieve z = exp(q) from precomputed cache\n\tz.setBint(bexp[int(qcoef.fint())]) //nolint:gosec\n\n\tif rcoef.sign() == 0 {\n\t\treturn\n\t}\n\n\tzcoef := getBint()\n\tdefer putBint(zcoef)\n\n\tgcoef := getBint()\n\tdefer putBint(gcoef)\n\n\thcoef := getBint()\n\tdefer putBint(hcoef)\n\n\tzcoef.setFint(0)\n\tgcoef.setBint(bpow10[bscale])\n\n\t// Compute exp(r) using Taylor series expansion\n\t// exp(r) = r^0 / 0! + r^1 / 1! + ... + r^n / n!\n\tfor i := range len(bfact) {\n\t\thcoef.quo(gcoef, bfact[i])\n\t\tif hcoef.sign() == 0 {\n\t\t\tbreak\n\t\t}\n\t\tzcoef.add(zcoef, hcoef)\n\t\tgcoef.mul(gcoef, rcoef)\n\t\tgcoef.rshDown(gcoef, bscale)\n\t}\n\n\t// Compute z = z * exp(r)\n\tz.mul(z, zcoef)\n\tz.rshDown(z, bscale)\n}\n\n// Sum returns the (possibly rounded) sum of decimals.\n// It computes d1 + d2 + ... + dn without intermediate rounding.\n//\n// Sum returns an error if:\n//   - no argements are provided;\n//   - the integer part of the result has more than [MaxPrec] digits.\nfunc Sum(d ...Decimal) (Decimal, error) {\n\t// Special cases\n\tswitch len(d) {\n\tcase 0:\n\t\treturn Decimal{}, fmt.Errorf(\"computing [sum([])]: %w\", errInvalidOperation)\n\tcase 1:\n\t\treturn d[0], nil\n\t}\n\n\t// General case\n\te, err := sumFint(d...)\n\tif err != nil {\n\t\te, err = sumBint(d...)\n\t\tif err != nil {\n\t\t\treturn Decimal{}, fmt.Errorf(\"computing [sum(%v)]: %w\", d, err)\n\t\t}\n\t}\n\n\treturn e, nil\n}\n\n// sumFint computes the sum of decimals using uint64 arithmetic.\nfunc sumFint(d ...Decimal) (Decimal, error) {\n\tecoef := Zero.coef\n\tescale := Zero.Scale()\n\teneg := Zero.IsNeg()\n\n\tfor _, f := range d {\n\t\tfcoef := f.coef\n\n\t\t// Alignment\n\t\tvar ok bool\n\t\tswitch {\n\t\tcase escale > f.Scale():\n\t\t\tfcoef, ok = fcoef.lsh(escale - f.Scale())\n\t\t\tif !ok {\n\t\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t\t}\n\t\tcase escale < f.Scale():\n\t\t\tecoef, ok = ecoef.lsh(f.Scale() - escale)\n\t\t\tif !ok {\n\t\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t\t}\n\t\t\tescale = f.Scale()\n\t\t}\n\n\t\t// Compute e = e + f\n\t\tif eneg == f.IsNeg() {\n\t\t\tecoef, ok = ecoef.add(fcoef)\n\t\t\tif !ok {\n\t\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t\t}\n\t\t} else {\n\t\t\tif fcoef > ecoef {\n\t\t\t\teneg = f.IsNeg()\n\t\t\t}\n\t\t\tecoef = ecoef.subAbs(fcoef)\n\t\t}\n\t}\n\n\treturn newFromFint(eneg, ecoef, escale, 0)\n}\n\n// sumBint computes the sum of decimals using *big.Int arithmetic.\nfunc sumBint(d ...Decimal) (Decimal, error) {\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tfcoef := getBint()\n\tdefer putBint(fcoef)\n\n\tecoef.setFint(Zero.coef)\n\tescale := Zero.Scale()\n\teneg := Zero.IsNeg()\n\n\tfor _, f := range d {\n\t\tfcoef.setFint(f.coef)\n\n\t\t// Alignment\n\t\tswitch {\n\t\tcase escale > f.Scale():\n\t\t\tfcoef.lsh(fcoef, escale-f.Scale())\n\t\tcase escale < f.Scale():\n\t\t\tecoef.lsh(ecoef, f.Scale()-escale)\n\t\t\tescale = f.Scale()\n\t\t}\n\n\t\t// Compute e = e + f\n\t\tif eneg == f.IsNeg() {\n\t\t\tecoef.add(ecoef, fcoef)\n\t\t} else {\n\t\t\tif fcoef.cmp(ecoef) > 0 {\n\t\t\t\teneg = f.IsNeg()\n\t\t\t}\n\t\t\tecoef.subAbs(ecoef, fcoef)\n\t\t}\n\t}\n\n\treturn newFromBint(eneg, ecoef, escale, 0)\n}\n\n// SubAbs returns the (possibly rounded) absolute difference between decimals d and e.\n//\n// SubAbs returns an error if the integer part of the result has more than [MaxPrec] digits.\nfunc (d Decimal) SubAbs(e Decimal) (Decimal, error) {\n\tf, err := d.Sub(e)\n\tif err != nil {\n\t\treturn Decimal{}, fmt.Errorf(\"computing [abs(%v - %v)]: %w\", d, e, err)\n\t}\n\treturn f.Abs(), nil\n}\n\n// Sub returns the (possibly rounded) difference between decimals d and e.\n//\n// Sub returns an error if the integer part of the result has more than [MaxPrec] digits.\nfunc (d Decimal) Sub(e Decimal) (Decimal, error) {\n\treturn d.AddExact(e.Neg(), 0)\n}\n\n// SubExact is similar to [Decimal.Sub], but it allows you to specify the number of digits\n// after the decimal point that should be considered significant.\n// If any of the significant digits are lost during rounding, the method will return an error.\n// This method is useful for financial calculations where the scale should be\n// equal to or greater than the currency's scale.\nfunc (d Decimal) SubExact(e Decimal, scale int) (Decimal, error) {\n\treturn d.AddExact(e.Neg(), scale)\n}\n\n// Add returns the (possibly rounded) sum of decimals d and e.\n//\n// Add returns an error if the integer part of the result has more than [MaxPrec] digits.\nfunc (d Decimal) Add(e Decimal) (Decimal, error) {\n\treturn d.AddExact(e, 0)\n}\n\n// AddExact is similar to [Decimal.Add], but it allows you to specify the number of digits\n// after the decimal point that should be considered significant.\n// If any of the significant digits are lost during rounding, the method will return an error.\n// This method is useful for financial calculations where the scale should be\n// equal to or greater than the currency's scale.\nfunc (d Decimal) AddExact(e Decimal, scale int) (Decimal, error) {\n\tif scale < MinScale || scale > MaxScale {\n\t\treturn Decimal{}, fmt.Errorf(\"computing [%v + %v]: %w\", d, e, errScaleRange)\n\t}\n\n\t// General case\n\tf, err := d.addFint(e, scale)\n\tif err != nil {\n\t\tf, err = d.addBint(e, scale)\n\t\tif err != nil {\n\t\t\treturn Decimal{}, fmt.Errorf(\"computing [%v + %v]: %w\", d, e, err)\n\t\t}\n\t}\n\n\treturn f, nil\n}\n\n// addFint computes the sum of two decimals using uint64 arithmetic.\nfunc (d Decimal) addFint(e Decimal, minScale int) (Decimal, error) {\n\tdcoef := d.coef\n\tdscale := d.Scale()\n\tdneg := d.IsNeg()\n\n\tecoef := e.coef\n\n\t// Alignment\n\tvar ok bool\n\tswitch {\n\tcase dscale > e.Scale():\n\t\tecoef, ok = ecoef.lsh(dscale - e.Scale())\n\t\tif !ok {\n\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t}\n\tcase dscale < e.Scale():\n\t\tdcoef, ok = dcoef.lsh(e.Scale() - dscale)\n\t\tif !ok {\n\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t}\n\t\tdscale = e.Scale()\n\t}\n\n\t// Compute d = d + e\n\tif dneg == e.IsNeg() {\n\t\tdcoef, ok = dcoef.add(ecoef)\n\t\tif !ok {\n\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t}\n\t} else {\n\t\tif ecoef > dcoef {\n\t\t\tdneg = e.IsNeg()\n\t\t}\n\t\tdcoef = dcoef.subAbs(ecoef)\n\t}\n\n\treturn newFromFint(dneg, dcoef, dscale, minScale)\n}\n\n// addBint computes the sum of two decimals using *big.Int arithmetic.\nfunc (d Decimal) addBint(e Decimal, minScale int) (Decimal, error) {\n\tdcoef := getBint()\n\tdefer putBint(dcoef)\n\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tdcoef.setFint(d.coef)\n\tdscale := d.Scale()\n\tecoef.setFint(e.coef)\n\tdneg := d.IsNeg()\n\n\t// Alignment\n\tswitch {\n\tcase dscale > e.Scale():\n\t\tecoef.lsh(ecoef, dscale-e.Scale())\n\tcase dscale < e.Scale():\n\t\tdcoef.lsh(dcoef, e.Scale()-dscale)\n\t\tdscale = e.Scale()\n\t}\n\n\t// Compute d = d + e\n\tif dneg == e.IsNeg() {\n\t\tdcoef.add(dcoef, ecoef)\n\t} else {\n\t\tif ecoef.cmp(dcoef) > 0 {\n\t\t\tdneg = e.IsNeg()\n\t\t}\n\t\tdcoef.subAbs(dcoef, ecoef)\n\t}\n\n\treturn newFromBint(dneg, dcoef, dscale, minScale)\n}\n\n// SubMul returns the (possibly rounded) [fused multiply-subtraction] of decimals d, e, and f.\n// It computes d - e * f without any intermediate rounding.\n// This method is useful for improving the accuracy and performance of algorithms\n// that involve the accumulation of products, such as daily interest accrual.\n//\n// SubMul returns an error if the integer part of the result has more than [MaxPrec] digits.\n//\n// [fused multiply-subtraction]: https://en.wikipedia.org/wiki/Multiply%E2%80%93accumulate_operation#Fused_multiply%E2%80%93add\nfunc (d Decimal) SubMul(e, f Decimal) (Decimal, error) {\n\treturn d.AddMulExact(e.Neg(), f, 0)\n}\n\n// SubMulExact is similar to [Decimal.SubMul], but it allows you to specify the number of digits\n// after the decimal point that should be considered significant.\n// If any of the significant digits are lost during rounding, the method will return an error.\n// This method is useful for financial calculations where the scale should be\n// equal to or greater than the currency's scale.\nfunc (d Decimal) SubMulExact(e, f Decimal, scale int) (Decimal, error) {\n\treturn d.AddMulExact(e.Neg(), f, scale)\n}\n\n// AddMul returns the (possibly rounded) [fused multiply-addition] of decimals d, e, and f.\n// It computes d + e * f without any intermediate rounding.\n// This method is useful for improving the accuracy and performance of algorithms\n// that involve the accumulation of products, such as daily interest accrual.\n//\n// AddMul returns an error if the integer part of the result has more than [MaxPrec] digits.\n//\n// [fused multiply-addition]: https://en.wikipedia.org/wiki/Multiply%E2%80%93accumulate_operation#Fused_multiply%E2%80%93add\nfunc (d Decimal) AddMul(e, f Decimal) (Decimal, error) {\n\treturn d.AddMulExact(e, f, 0)\n}\n\n// AddMulExact is similar to [Decimal.AddMul], but it allows you to specify the number of digits\n// after the decimal point that should be considered significant.\n// If any of the significant digits are lost during rounding, the method will return an error.\n// This method is useful for financial calculations where the scale should be\n// equal to or greater than the currency's scale.\nfunc (d Decimal) AddMulExact(e, f Decimal, scale int) (Decimal, error) {\n\tif scale < MinScale || scale > MaxScale {\n\t\treturn Decimal{}, fmt.Errorf(\"computing [%v + %v * %v]: %w\", d, e, f, errScaleRange)\n\t}\n\n\t// General case\n\tg, err := d.addMulFint(e, f, scale)\n\tif err != nil {\n\t\tg, err = d.addMulBint(e, f, scale)\n\t\tif err != nil {\n\t\t\treturn Decimal{}, fmt.Errorf(\"computing [%v + %v * %v]: %w\", d, e, f, err)\n\t\t}\n\t}\n\n\treturn g, nil\n}\n\n// addMulFint computes the fused multiply-addition of three decimals using uint64 arithmetic.\nfunc (d Decimal) addMulFint(e, f Decimal, minScale int) (Decimal, error) {\n\tdcoef := d.coef\n\tdscale := d.Scale()\n\tdneg := d.IsNeg()\n\n\tecoef := e.coef\n\tescale := e.Scale()\n\teneg := e.IsNeg()\n\n\tfcoef := f.coef\n\n\t// Compute e = e * f\n\tvar ok bool\n\tecoef, ok = ecoef.mul(fcoef)\n\tif !ok {\n\t\treturn Decimal{}, errDecimalOverflow\n\t}\n\tescale = escale + f.Scale()\n\teneg = eneg != f.IsNeg()\n\n\t// Alignment\n\tswitch {\n\tcase dscale > escale:\n\t\tecoef, ok = ecoef.lsh(dscale - escale)\n\t\tif !ok {\n\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t}\n\tcase dscale < escale:\n\t\tdcoef, ok = dcoef.lsh(escale - dscale)\n\t\tif !ok {\n\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t}\n\t\tdscale = escale\n\t}\n\n\t// Compute d = d + e\n\tif dneg == eneg {\n\t\tdcoef, ok = dcoef.add(ecoef)\n\t\tif !ok {\n\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t}\n\t} else {\n\t\tif ecoef > dcoef {\n\t\t\tdneg = eneg\n\t\t}\n\t\tdcoef = dcoef.subAbs(ecoef)\n\t}\n\n\treturn newFromFint(dneg, dcoef, dscale, minScale)\n}\n\n// addMulBint computes the fused multiply-addition of three decimals using *big.Int arithmetic.\nfunc (d Decimal) addMulBint(e, f Decimal, minScale int) (Decimal, error) {\n\tdcoef := getBint()\n\tdefer putBint(dcoef)\n\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tfcoef := getBint()\n\tdefer putBint(fcoef)\n\n\tdcoef.setFint(d.coef)\n\tdscale := d.Scale()\n\tdneg := d.IsNeg()\n\tecoef.setFint(e.coef)\n\tescale := e.Scale()\n\teneg := e.IsNeg()\n\tfcoef.setFint(f.coef)\n\n\t// Compute e = e * f\n\tecoef.mul(ecoef, fcoef)\n\tescale = escale + f.Scale()\n\teneg = eneg != f.IsNeg()\n\n\t// Alignment\n\tswitch {\n\tcase dscale > escale:\n\t\tecoef.lsh(ecoef, dscale-escale)\n\tcase dscale < escale:\n\t\tdcoef.lsh(dcoef, escale-d.Scale())\n\t\tdscale = escale\n\t}\n\n\t// Compute d = d + e\n\tif dneg == eneg {\n\t\tdcoef.add(dcoef, ecoef)\n\t} else {\n\t\tif ecoef.cmp(dcoef) > 0 {\n\t\t\tdneg = eneg\n\t\t}\n\t\tdcoef.subAbs(dcoef, ecoef)\n\t}\n\n\treturn newFromBint(dneg, dcoef, dscale, minScale)\n}\n\n// SubQuo returns the (possibly rounded) fused quotient-subtraction of decimals d, e, and f.\n// It computes d - e / f with at least double precision during intermediate rounding.\n// This method is useful for improving the accuracy and performance of algorithms\n// that involve the accumulation of quotients, such as internal rate of return.\n//\n// AddQuo returns an error if:\n//   - the divisor is 0;\n//   - the integer part of the result has more than [MaxPrec] digits.\nfunc (d Decimal) SubQuo(e, f Decimal) (Decimal, error) {\n\treturn d.AddQuoExact(e.Neg(), f, 0)\n}\n\n// SubQuoExact is similar to [Decimal.SubQuo], but it allows you to specify the number of digits\n// after the decimal point that should be considered significant.\n// If any of the significant digits are lost during rounding, the method will return an error.\n// This method is useful for financial calculations where the scale should be\n// equal to or greater than the currency's scale.\nfunc (d Decimal) SubQuoExact(e, f Decimal, scale int) (Decimal, error) {\n\treturn d.AddQuoExact(e.Neg(), f, scale)\n}\n\n// AddQuo returns the (possibly rounded) fused quotient-addition of decimals d, e, and f.\n// It computes d + e / f with at least double precision during the intermediate rounding.\n// This method is useful for improving the accuracy and performance of algorithms\n// that involve the accumulation of quotients, such as internal rate of return.\n//\n// AddQuo returns an error if:\n//   - the divisor is 0;\n//   - the integer part of the result has more than [MaxPrec] digits.\nfunc (d Decimal) AddQuo(e, f Decimal) (Decimal, error) {\n\treturn d.AddQuoExact(e, f, 0)\n}\n\n// AddQuoExact is similar to [Decimal.AddQuo], but it allows you to specify the number of digits\n// after the decimal point that should be considered significant.\n// If any of the significant digits are lost during rounding, the method will return an error.\n// This method is useful for financial calculations where the scale should be\n// equal to or greater than the currency's scale.\nfunc (d Decimal) AddQuoExact(e, f Decimal, scale int) (Decimal, error) {\n\tif scale < MinScale || scale > MaxScale {\n\t\treturn Decimal{}, fmt.Errorf(\"computing [%v + %v / %v]: %w\", d, e, f, errScaleRange)\n\t}\n\n\t// Special case: zero divisor\n\tif f.IsZero() {\n\t\treturn Decimal{}, fmt.Errorf(\"computing [%v + %v / %v]: %w\", d, e, f, errDivisionByZero)\n\t}\n\n\t// Special case: zero dividend\n\tif e.IsZero() {\n\t\tscale = max(scale, e.Scale()-f.Scale())\n\t\treturn d.Pad(scale), nil\n\t}\n\n\t// General case\n\tg, err := d.addQuoFint(e, f, scale)\n\tif err != nil {\n\t\tg, err = d.addQuoBint(e, f, scale)\n\t\tif err != nil {\n\t\t\treturn Decimal{}, fmt.Errorf(\"computing [%v + %v / %v]: %w\", d, e, f, err)\n\t\t}\n\t}\n\n\t// Preferred scale\n\tscale = max(scale, d.Scale(), e.Scale()-f.Scale())\n\tg = g.Trim(scale)\n\n\treturn g, nil\n}\n\n// addQuoFint computes the fused quotient-addition of three decimals using uint64 arithmetic.\nfunc (d Decimal) addQuoFint(e, f Decimal, minScale int) (Decimal, error) {\n\tdcoef := d.coef\n\tdscale := d.Scale()\n\tdneg := d.IsNeg()\n\n\tecoef := e.coef\n\tescale := e.Scale()\n\teneg := e.IsNeg()\n\n\tfcoef := f.coef\n\n\t// Alignment\n\tvar ok bool\n\tif shift := MaxPrec - ecoef.prec(); shift > 0 {\n\t\tecoef, ok = ecoef.lsh(shift)\n\t\tif !ok {\n\t\t\treturn Decimal{}, errDecimalOverflow // Should never happen\n\t\t}\n\t\tescale = escale + shift\n\t}\n\tif shift := fcoef.ntz(); shift > 0 {\n\t\tfcoef = fcoef.rshDown(shift)\n\t\tescale = escale + shift\n\t}\n\n\t// Compute e = e / f\n\tecoef, ok = ecoef.quo(fcoef)\n\tif !ok {\n\t\treturn Decimal{}, errInexactDivision\n\t}\n\tescale = escale - f.Scale()\n\teneg = eneg != f.IsNeg()\n\n\t// Alignment\n\tswitch {\n\tcase dscale > escale:\n\t\tecoef, ok = ecoef.lsh(dscale - escale)\n\t\tif !ok {\n\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t}\n\tcase dscale < escale:\n\t\tif shift := min(escale-e.Scale()+f.Scale(), escale-dscale, ecoef.ntz()); shift > 0 {\n\t\t\tecoef = ecoef.rshDown(shift)\n\t\t\tescale = escale - shift\n\t\t}\n\t\tdcoef, ok = dcoef.lsh(escale - dscale)\n\t\tif !ok {\n\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t}\n\t\tdscale = escale\n\t}\n\n\t// Compute d = d + e\n\tif dneg == eneg {\n\t\tdcoef, ok = dcoef.add(ecoef)\n\t\tif !ok {\n\t\t\treturn Decimal{}, errDecimalOverflow\n\t\t}\n\t} else {\n\t\tif ecoef > dcoef {\n\t\t\tdneg = eneg\n\t\t}\n\t\tdcoef = dcoef.subAbs(ecoef)\n\t}\n\n\treturn newFromFint(dneg, dcoef, dscale, minScale)\n}\n\n// addQuoBint computes the fused quotient-addition of three decimals using *big.Int arithmetic.\nfunc (d Decimal) addQuoBint(e, f Decimal, minScale int) (Decimal, error) {\n\tdcoef := getBint()\n\tdefer putBint(dcoef)\n\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tfcoef := getBint()\n\tdefer putBint(fcoef)\n\n\tdcoef.setFint(d.coef)\n\tdneg := d.IsNeg()\n\tecoef.setFint(e.coef)\n\teneg := e.IsNeg()\n\tfcoef.setFint(f.coef)\n\n\t// Alignment\n\tecoef.lsh(ecoef, bscale-e.Scale()+f.Scale())\n\n\t// Compute e = ⌊e / f⌋\n\tecoef.quo(ecoef, fcoef)\n\teneg = eneg != f.IsNeg()\n\n\t// Alignment\n\tdcoef.lsh(dcoef, bscale-d.Scale())\n\n\t// Compute d = d + e\n\tif dneg == eneg {\n\t\tdcoef.add(dcoef, ecoef)\n\t} else {\n\t\tif ecoef.cmp(dcoef) > 0 {\n\t\t\tdneg = eneg\n\t\t}\n\t\tdcoef.subAbs(dcoef, ecoef)\n\t}\n\n\treturn newFromBint(dneg, dcoef, bscale, minScale)\n}\n\n// Inv returns the (possibly rounded) inverse of the decimal.\n//\n// Inv returns an error if:\n//   - the integer part of the result has more than [MaxPrec] digits;\n//   - the decimal is 0.\nfunc (d Decimal) Inv() (Decimal, error) {\n\tf, err := One.Quo(d)\n\tif err != nil {\n\t\treturn Decimal{}, fmt.Errorf(\"inverting %v: %w\", d, err)\n\t}\n\treturn f, nil\n}\n\n// Quo returns the (possibly rounded) quotient of decimals d and e.\n//\n// Quo returns an error if:\n//   - the divisor is 0;\n//   - the integer part of the result has more than [MaxPrec] digits.\nfunc (d Decimal) Quo(e Decimal) (Decimal, error) {\n\treturn d.QuoExact(e, 0)\n}\n\n// QuoExact is similar to [Decimal.Quo], but it allows you to specify the number of digits\n// after the decimal point that should be considered significant.\n// If any of the significant digits are lost during rounding, the method will return an error.\n// This method is useful for financial calculations where the scale should be\n// equal to or greater than the currency's scale.\nfunc (d Decimal) QuoExact(e Decimal, scale int) (Decimal, error) {\n\tif scale < MinScale || scale > MaxScale {\n\t\treturn Decimal{}, fmt.Errorf(\"computing [%v / %v]: %w\", d, e, errScaleRange)\n\t}\n\n\t// Special case: zero divisor\n\tif e.IsZero() {\n\t\treturn Decimal{}, fmt.Errorf(\"computing [%v / %v]: %w\", d, e, errDivisionByZero)\n\t}\n\n\t// Special case: zero dividend\n\tif d.IsZero() {\n\t\tscale = max(scale, d.Scale()-e.Scale())\n\t\treturn newSafe(false, 0, scale)\n\t}\n\n\t// General case\n\tf, err := d.quoFint(e, scale)\n\tif err != nil {\n\t\tf, err = d.quoBint(e, scale)\n\t\tif err != nil {\n\t\t\treturn Decimal{}, fmt.Errorf(\"computing [%v / %v]: %w\", d, e, err)\n\t\t}\n\t}\n\n\t// Preferred scale\n\tscale = max(scale, d.Scale()-e.Scale())\n\tf = f.Trim(scale)\n\n\treturn f, nil\n}\n\n// quoFint computes the quotient of two decimals using uint64 arithmetic.\nfunc (d Decimal) quoFint(e Decimal, minScale int) (Decimal, error) {\n\tdcoef := d.coef\n\tdscale := d.Scale()\n\tdneg := d.IsNeg()\n\n\tecoef := e.coef\n\n\t// Alignment\n\tvar ok bool\n\tif shift := MaxPrec - dcoef.prec(); shift > 0 {\n\t\tdcoef, ok = dcoef.lsh(shift)\n\t\tif !ok {\n\t\t\treturn Decimal{}, errDecimalOverflow // Should never happen\n\t\t}\n\t\tdscale = dscale + shift\n\t}\n\tif shift := ecoef.ntz(); shift > 0 {\n\t\tecoef = ecoef.rshDown(shift)\n\t\tdscale = dscale + shift\n\t}\n\n\t// Compute d = d / e\n\tdcoef, ok = dcoef.quo(ecoef)\n\tif !ok {\n\t\treturn Decimal{}, errInexactDivision\n\t}\n\tdscale = dscale - e.Scale()\n\tdneg = dneg != e.IsNeg()\n\n\treturn newFromFint(dneg, dcoef, dscale, minScale)\n}\n\n// quoBint computes the quotient of two decimals using *big.Int arithmetic.\nfunc (d Decimal) quoBint(e Decimal, minScale int) (Decimal, error) {\n\tdcoef := getBint()\n\tdefer putBint(dcoef)\n\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tdcoef.setFint(d.coef)\n\tdneg := d.IsNeg()\n\tecoef.setFint(e.coef)\n\n\t// Alignment\n\tdcoef.lsh(dcoef, bscale+e.Scale()-d.Scale())\n\n\t// Compute d = ⌊d / e⌋\n\tdcoef.quo(dcoef, ecoef)\n\tdneg = dneg != e.IsNeg()\n\n\treturn newFromBint(dneg, dcoef, bscale, minScale)\n}\n\n// QuoRem returns the quotient q and remainder r of decimals d and e\n// such that d = e * q + r, where q is an integer and the sign of the\n// reminder r is the same as the sign of the dividend d.\n//\n// QuoRem returns an error if:\n//   - the divisor is 0;\n//   - the integer part of the quotient has more than [MaxPrec] digits.\nfunc (d Decimal) QuoRem(e Decimal) (q, r Decimal, err error) {\n\t// Special case: zero divisor\n\tif e.IsZero() {\n\t\treturn Decimal{}, Decimal{}, fmt.Errorf(\"computing [%v div %v] and [%v mod %v]: %w\", d, e, d, e, errDivisionByZero)\n\t}\n\n\t// General case\n\tq, r, err = d.quoRemFint(e)\n\tif err != nil {\n\t\tq, r, err = d.quoRemBint(e)\n\t\tif err != nil {\n\t\t\treturn Decimal{}, Decimal{}, fmt.Errorf(\"computing [%v div %v] and [%v mod %v]: %w\", d, e, d, e, err)\n\t\t}\n\t}\n\n\treturn q, r, nil\n}\n\n// quoRemFint computes the quotient and remainder of two decimals using uint64 arithmetic.\nfunc (d Decimal) quoRemFint(e Decimal) (q, r Decimal, err error) {\n\tdcoef := d.coef\n\tecoef := e.coef\n\trscale := d.Scale()\n\n\t// Alignment\n\tvar ok bool\n\tswitch {\n\tcase d.Scale() > e.Scale():\n\t\tecoef, ok = ecoef.lsh(d.Scale() - e.Scale())\n\t\tif !ok {\n\t\t\treturn Decimal{}, Decimal{}, errDecimalOverflow\n\t\t}\n\tcase d.Scale() < e.Scale():\n\t\tdcoef, ok = dcoef.lsh(e.Scale() - d.Scale())\n\t\tif !ok {\n\t\t\treturn Decimal{}, Decimal{}, errDecimalOverflow\n\t\t}\n\t\trscale = e.Scale()\n\t}\n\n\t// Compute q = ⌊d / e⌋, r = d - e * q\n\tqcoef, rcoef, ok := dcoef.quoRem(ecoef)\n\tif !ok {\n\t\treturn Decimal{}, Decimal{}, errDivisionByZero // Should never happen\n\t}\n\tqsign := d.IsNeg() != e.IsNeg()\n\trsign := d.IsNeg()\n\n\tq, err = newFromFint(qsign, qcoef, 0, 0)\n\tif err != nil {\n\t\treturn Decimal{}, Decimal{}, err\n\t}\n\tr, err = newFromFint(rsign, rcoef, rscale, rscale)\n\tif err != nil {\n\t\treturn Decimal{}, Decimal{}, err\n\t}\n\treturn q, r, nil\n}\n\n// quoRemBint computes the quotient and remainder of two decimals using *big.Int arithmetic.\nfunc (d Decimal) quoRemBint(e Decimal) (q, r Decimal, err error) {\n\tdcoef := getBint()\n\tdefer putBint(dcoef)\n\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tqcoef := getBint()\n\tdefer putBint(qcoef)\n\n\trcoef := getBint()\n\tdefer putBint(rcoef)\n\n\tdcoef.setFint(d.coef)\n\tecoef.setFint(e.coef)\n\trscale := d.Scale()\n\n\t// Alignment\n\tswitch {\n\tcase d.Scale() > e.Scale():\n\t\tecoef.lsh(ecoef, d.Scale()-e.Scale())\n\tcase d.Scale() < e.Scale():\n\t\tdcoef.lsh(dcoef, e.Scale()-d.Scale())\n\t\trscale = e.Scale()\n\t}\n\n\t// Compute q = ⌊d / e⌋, r = d - e * q\n\tqcoef.quoRem(dcoef, ecoef, rcoef)\n\tqsign := d.IsNeg() != e.IsNeg()\n\trsign := d.IsNeg()\n\n\tq, err = newFromBint(qsign, qcoef, 0, 0)\n\tif err != nil {\n\t\treturn Decimal{}, Decimal{}, err\n\t}\n\tr, err = newFromBint(rsign, rcoef, rscale, rscale)\n\tif err != nil {\n\t\treturn Decimal{}, Decimal{}, err\n\t}\n\treturn q, r, nil\n}\n\n// Max returns the larger decimal.\n// See also method [Decimal.CmpTotal].\nfunc (d Decimal) Max(e Decimal) Decimal {\n\tif d.CmpTotal(e) >= 0 {\n\t\treturn d\n\t}\n\treturn e\n}\n\n// Min returns the smaller decimal.\n// See also method [Decimal.CmpTotal].\nfunc (d Decimal) Min(e Decimal) Decimal {\n\tif d.CmpTotal(e) <= 0 {\n\t\treturn d\n\t}\n\treturn e\n}\n\n// Clamp compares decimals and returns:\n//\n//\tmin if d < min\n//\tmax if d > max\n//\t  d otherwise\n//\n// See also method [Decimal.CmpTotal].\n//\n// Clamp returns an error if min is greater than max numerically.\n//\n//nolint:revive\nfunc (d Decimal) Clamp(min, max Decimal) (Decimal, error) {\n\tif min.Cmp(max) > 0 {\n\t\treturn Decimal{}, fmt.Errorf(\"clamping %v: invalid range\", d)\n\t}\n\tif min.CmpTotal(max) > 0 {\n\t\t// min and max are equal numerically but have different scales.\n\t\t// Swaping min and max to ensure total ordering.\n\t\tmin, max = max, min\n\t}\n\tif d.CmpTotal(min) < 0 {\n\t\treturn min, nil\n\t}\n\tif d.CmpTotal(max) > 0 {\n\t\treturn max, nil\n\t}\n\treturn d, nil\n}\n\n// CmpTotal compares decimal representations and returns:\n//\n//\t-1 if d < e\n//\t-1 if d = e and d.scale > e.scale\n//\t 0 if d = e and d.scale = e.scale\n//\t+1 if d = e and d.scale < e.scale\n//\t+1 if d > e\n//\n// See also method [Decimal.Cmp].\nfunc (d Decimal) CmpTotal(e Decimal) int {\n\tswitch d.Cmp(e) {\n\tcase -1:\n\t\treturn -1\n\tcase 1:\n\t\treturn 1\n\t}\n\tswitch {\n\tcase d.Scale() > e.Scale():\n\t\treturn -1\n\tcase d.Scale() < e.Scale():\n\t\treturn 1\n\t}\n\treturn 0\n}\n\n// CmpAbs compares absolute values of decimals and returns:\n//\n//\t-1 if |d| < |e|\n//\t 0 if |d| = |e|\n//\t+1 if |d| > |e|\n//\n// See also method [Decimal.Cmp].\nfunc (d Decimal) CmpAbs(e Decimal) int {\n\td, e = d.Abs(), e.Abs()\n\treturn d.Cmp(e)\n}\n\n// Equal compares decimals and returns:\n//\n//\t true if d = e\n//\tfalse otherwise\n//\n// See also method [Decimal.Cmp].\nfunc (d Decimal) Equal(e Decimal) bool {\n\treturn d.Cmp(e) == 0\n}\n\n// Less compares decimals and returns:\n//\n//\t true if d < e\n//\tfalse otherwise\n//\n// See also method [Decimal.Cmp].\nfunc (d Decimal) Less(e Decimal) bool {\n\treturn d.Cmp(e) < 0\n}\n\n// Cmp compares decimals and returns:\n//\n//\t-1 if d < e\n//\t 0 if d = e\n//\t+1 if d > e\n//\n// See also methods [Decimal.CmpAbs], [Decimal.CmpTotal].\nfunc (d Decimal) Cmp(e Decimal) int {\n\t// Special case: different signs\n\tswitch {\n\tcase d.Sign() > e.Sign():\n\t\treturn 1\n\tcase d.Sign() < e.Sign():\n\t\treturn -1\n\t}\n\n\t// General case\n\tr, err := d.cmpFint(e)\n\tif err != nil {\n\t\tr = d.cmpBint(e)\n\t}\n\treturn r\n}\n\n// cmpFint compares decimals using uint64 arithmetic.\nfunc (d Decimal) cmpFint(e Decimal) (int, error) {\n\tdcoef := d.coef\n\tecoef := e.coef\n\n\t// Alignment\n\tvar ok bool\n\tswitch {\n\tcase d.Scale() > e.Scale():\n\t\tecoef, ok = ecoef.lsh(d.Scale() - e.Scale())\n\t\tif !ok {\n\t\t\treturn 0, errDecimalOverflow\n\t\t}\n\tcase d.Scale() < e.Scale():\n\t\tdcoef, ok = dcoef.lsh(e.Scale() - d.Scale())\n\t\tif !ok {\n\t\t\treturn 0, errDecimalOverflow\n\t\t}\n\t}\n\n\t// Comparison\n\tswitch {\n\tcase dcoef > ecoef:\n\t\treturn d.Sign(), nil\n\tcase ecoef > dcoef:\n\t\treturn -e.Sign(), nil\n\t}\n\treturn 0, nil\n}\n\n// cmpBint compares decimals using *big.Int arithmetic.\nfunc (d Decimal) cmpBint(e Decimal) int {\n\tdcoef := getBint()\n\tdefer putBint(dcoef)\n\n\tecoef := getBint()\n\tdefer putBint(ecoef)\n\n\tdcoef.setFint(d.coef)\n\tecoef.setFint(e.coef)\n\n\t// Alignment\n\tswitch {\n\tcase d.Scale() > e.Scale():\n\t\tecoef.lsh(ecoef, d.Scale()-e.Scale())\n\tcase d.Scale() < e.Scale():\n\t\tdcoef.lsh(dcoef, e.Scale()-d.Scale())\n\t}\n\n\t// Comparison\n\tswitch dcoef.cmp(ecoef) {\n\tcase 1:\n\t\treturn d.Sign()\n\tcase -1:\n\t\treturn -e.Sign()\n\t}\n\treturn 0\n}\n\n// NullDecimal represents a decimal that can be null.\n// Its zero value is null.\n// NullDecimal is not thread-safe.\ntype NullDecimal struct {\n\tDecimal Decimal\n\tValid   bool\n}\n\n// Scan implements the [sql.Scanner] interface.\n// See also method [Decimal.Scan].\n//\n// [sql.Scanner]: https://pkg.go.dev/database/sql#Scanner\nfunc (n *NullDecimal) Scan(value any) error {\n\tif value == nil {\n\t\tn.Decimal = Decimal{}\n\t\tn.Valid = false\n\t\treturn nil\n\t}\n\tn.Valid = true\n\treturn n.Decimal.Scan(value)\n}\n\n// Value implements the [driver.Valuer] interface.\n// See also method [Decimal.Value].\n//\n// [driver.Valuer]: https://pkg.go.dev/database/sql/driver#Valuer\nfunc (n NullDecimal) Value() (driver.Value, error) {\n\tif !n.Valid {\n\t\treturn nil, nil\n\t}\n\treturn n.Decimal.Value()\n}\n\n// UnmarshalJSON implements the [json.Unmarshaler] interface.\n// See also method [Decimal.UnmarshalJSON].\n//\n// [json.Unmarshaler]: https://pkg.go.dev/encoding/json#Unmarshaler\nfunc (n *NullDecimal) UnmarshalJSON(data []byte) error {\n\tif string(data) == \"null\" {\n\t\tn.Decimal = Decimal{}\n\t\tn.Valid = false\n\t\treturn nil\n\t}\n\tn.Valid = true\n\treturn n.Decimal.UnmarshalJSON(data)\n}\n\n// MarshalJSON implements the [json.Marshaler] interface.\n// See also method [Decimal.MarshalJSON].\n//\n// [json.Marshaler]: https://pkg.go.dev/encoding/json#Marshaler\nfunc (n NullDecimal) MarshalJSON() ([]byte, error) {\n\tif !n.Valid {\n\t\treturn []byte(\"null\"), nil\n\t}\n\treturn n.Decimal.MarshalJSON()\n}\n\n// UnmarshalBSONValue implements the [v2/bson.ValueUnmarshaler] interface.\n// UnmarshalBSONValue supports the following [types]: Null, Double, String, 32-bit Integer, 64-bit Integer, and [Decimal128].\n// See also method [Decimal.UnmarshalBSONValue].\n//\n// [v2/bson.ValueUnmarshaler]: https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#ValueUnmarshaler\n// [types]: https://bsonspec.org/spec.html\n// [Decimal128]: https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.md\nfunc (n *NullDecimal) UnmarshalBSONValue(typ byte, data []byte) error {\n\t// constants are from https://bsonspec.org/spec.html\n\tif typ == 10 {\n\t\tn.Decimal = Decimal{}\n\t\tn.Valid = false\n\t\treturn nil\n\t}\n\tn.Valid = true\n\treturn n.Decimal.UnmarshalBSONValue(typ, data)\n}\n\n// MarshalBSONValue implements the [v2/bson.ValueMarshaler] interface.\n// MarshalBSONValue returns [Null] or [Decimal128].\n// See also method [Decimal.MarshalBSONValue].\n//\n// [v2/bson.ValueMarshaler]: https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#ValueMarshaler\n// [Null]: https://bsonspec.org/spec.html\n// [Decimal128]: https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.md\nfunc (n NullDecimal) MarshalBSONValue() (typ byte, data []byte, err error) {\n\t// constants are from https://bsonspec.org/spec.html\n\tif !n.Valid {\n\t\treturn 10, nil, nil\n\t}\n\treturn n.Decimal.MarshalBSONValue()\n}\n"
  },
  {
    "path": "decimal_test.go",
    "content": "package decimal\n\nimport (\n\t\"bytes\"\n\t\"database/sql\"\n\t\"database/sql/driver\"\n\t\"encoding\"\n\t\"encoding/json\"\n\t\"fmt\"\n\t\"math\"\n\t\"math/big\"\n\t\"testing\"\n\t\"unsafe\"\n)\n\nfunc TestDecimal_ZeroValue(t *testing.T) {\n\tgot := Decimal{}\n\twant := MustNew(0, 0)\n\tif got != want {\n\t\tt.Errorf(\"Decimal{} = %q, want %q\", got, want)\n\t}\n}\n\nfunc TestDecimal_Size(t *testing.T) {\n\td := Decimal{}\n\tgot := unsafe.Sizeof(d)\n\twant := uintptr(16)\n\tif got != want {\n\t\tt.Errorf(\"unsafe.Sizeof(%q) = %v, want %v\", d, got, want)\n\t}\n}\n\nfunc TestDecimal_Interfaces(t *testing.T) {\n\tvar d any\n\n\td = Decimal{}\n\t_, ok := d.(fmt.Stringer)\n\tif !ok {\n\t\tt.Errorf(\"%T does not implement fmt.Stringer\", d)\n\t}\n\t_, ok = d.(fmt.Formatter)\n\tif !ok {\n\t\tt.Errorf(\"%T does not implement fmt.Formatter\", d)\n\t}\n\t_, ok = d.(json.Marshaler)\n\tif !ok {\n\t\tt.Errorf(\"%T does not implement json.Marshaler\", d)\n\t}\n\t_, ok = d.(encoding.TextMarshaler)\n\tif !ok {\n\t\tt.Errorf(\"%T does not implement encoding.TextMarshaler\", d)\n\t}\n\t_, ok = d.(encoding.BinaryMarshaler)\n\tif !ok {\n\t\tt.Errorf(\"%T does not implement encoding.BinaryMarshaler\", d)\n\t}\n\t// Uncomment when Go 1.24 is minimum supported version.\n\t// _, ok = d.(encoding.TextAppender)\n\t// if !ok {\n\t// \tt.Errorf(\"%T does not implement encoding.TextAppender\", d)\n\t// }\n\t// _, ok = d.(encoding.BinaryAppender)\n\t// if !ok {\n\t// \tt.Errorf(\"%T does not implement encoding.BinaryAppender\", d)\n\t// }\n\t_, ok = d.(driver.Valuer)\n\tif !ok {\n\t\tt.Errorf(\"%T does not implement driver.Valuer\", d)\n\t}\n\n\td = &Decimal{}\n\t_, ok = d.(json.Unmarshaler)\n\tif !ok {\n\t\tt.Errorf(\"%T does not implement json.Unmarshaler\", d)\n\t}\n\t_, ok = d.(encoding.TextUnmarshaler)\n\tif !ok {\n\t\tt.Errorf(\"%T does not implement encoding.TextUnmarshaler\", d)\n\t}\n\t_, ok = d.(encoding.BinaryUnmarshaler)\n\tif !ok {\n\t\tt.Errorf(\"%T does not implement encoding.BinaryUnmarshaler\", d)\n\t}\n\t_, ok = d.(sql.Scanner)\n\tif !ok {\n\t\tt.Errorf(\"%T does not implement sql.Scanner\", d)\n\t}\n}\n\nfunc TestNew(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\tvalue int64\n\t\t\tscale int\n\t\t\twant  string\n\t\t}{\n\t\t\t{math.MinInt64, 0, \"-9223372036854775808\"},\n\t\t\t{math.MinInt64, 1, \"-922337203685477580.8\"},\n\t\t\t{math.MinInt64, 2, \"-92233720368547758.08\"},\n\t\t\t{math.MinInt64, 19, \"-0.9223372036854775808\"},\n\t\t\t{0, 0, \"0\"},\n\t\t\t{0, 1, \"0.0\"},\n\t\t\t{0, 2, \"0.00\"},\n\t\t\t{0, 3, \"0.000\"},\n\t\t\t{0, 19, \"0.0000000000000000000\"},\n\t\t\t{1, 0, \"1\"},\n\t\t\t{1, 1, \"0.1\"},\n\t\t\t{1, 2, \"0.01\"},\n\t\t\t{1, 19, \"0.0000000000000000001\"},\n\t\t\t{math.MaxInt64, 0, \"9223372036854775807\"},\n\t\t\t{math.MaxInt64, 1, \"922337203685477580.7\"},\n\t\t\t{math.MaxInt64, 2, \"92233720368547758.07\"},\n\t\t\t{math.MaxInt64, 19, \"0.9223372036854775807\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\tgot, err := New(tt.value, tt.scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"New(%v, %v) failed: %v\", tt.value, tt.scale, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"New(%v, %v) = %q, want %q\", tt.value, tt.scale, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]struct {\n\t\t\tvalue int64\n\t\t\tscale int\n\t\t}{\n\t\t\t\"scale range 1\": {math.MinInt64, -1},\n\t\t\t\"scale range 2\": {math.MaxInt64, -1},\n\t\t\t\"scale range 3\": {0, -1},\n\t\t\t\"scale range 4\": {1, -1},\n\t\t\t\"scale range 5\": {math.MinInt64, 20},\n\t\t\t\"scale range 6\": {math.MinInt64, 39},\n\t\t\t\"scale range 7\": {math.MaxInt64, 20},\n\t\t\t\"scale range 8\": {math.MaxInt64, 39},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\t_, err := New(tt.value, tt.scale)\n\t\t\tif err == nil {\n\t\t\t\tt.Errorf(\"New(%v, %v) did not fail\", tt.value, tt.scale)\n\t\t\t}\n\t\t}\n\t})\n}\n\nfunc TestMustNew(t *testing.T) {\n\tt.Run(\"error\", func(t *testing.T) {\n\t\tdefer func() {\n\t\t\tif r := recover(); r == nil {\n\t\t\t\tt.Errorf(\"MustNew(0, -1) did not panic\")\n\t\t\t}\n\t\t}()\n\t\tMustNew(0, -1)\n\t})\n}\n\nfunc TestNewFromInt64(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\twhole, frac int64\n\t\t\tscale       int\n\t\t\twant        string\n\t\t}{\n\t\t\t// Zeros\n\t\t\t{0, 0, 0, \"0\"},\n\t\t\t{0, 0, 19, \"0\"},\n\n\t\t\t// Negatives\n\t\t\t{-1, -1, 1, \"-1.1\"},\n\t\t\t{-1, -1, 2, \"-1.01\"},\n\t\t\t{-1, -1, 3, \"-1.001\"},\n\t\t\t{-1, -1, 18, \"-1.000000000000000001\"},\n\n\t\t\t// Positives\n\t\t\t{1, 1, 1, \"1.1\"},\n\t\t\t{1, 1, 2, \"1.01\"},\n\t\t\t{1, 1, 3, \"1.001\"},\n\t\t\t{1, 100000000, 9, \"1.1\"},\n\t\t\t{1, 1, 18, \"1.000000000000000001\"},\n\t\t\t{100000000000000000, 100000000000000000, 18, \"100000000000000000.1\"},\n\t\t\t{1, 1, 19, \"1.000000000000000000\"},\n\t\t\t{999999999999999999, 9, 1, \"999999999999999999.9\"},\n\t\t\t{999999999999999999, 99, 2, \"1000000000000000000\"},\n\t\t\t{math.MaxInt64, math.MaxInt32, 10, \"9223372036854775807\"},\n\t\t\t{math.MaxInt64, math.MaxInt64, 19, \"9223372036854775808\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\tgot, err := NewFromInt64(tt.whole, tt.frac, tt.scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"NewFromInt64(%v, %v, %v) failed: %v\", tt.whole, tt.frac, tt.scale, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"NewFromInt64(%v, %v, %v) = %q, want %q\", tt.whole, tt.frac, tt.scale, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]struct {\n\t\t\twhole, frac int64\n\t\t\tscale       int\n\t\t}{\n\t\t\t\"different signs 1\": {-1, 1, 0},\n\t\t\t\"fraction range 1\":  {1, 1, 0},\n\t\t\t\"scale range 1\":     {1, 1, -1},\n\t\t\t\"scale range 2\":     {1, 0, -1},\n\t\t\t\"scale range 3\":     {1, 1, 20},\n\t\t\t\"scale range 4\":     {1, 0, 20},\n\t\t}\n\t\tfor name, tt := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\t_, err := NewFromInt64(tt.whole, tt.frac, tt.scale)\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"NewFromInt64(%v, %v, %v) did not fail\", tt.whole, tt.frac, tt.scale)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestNewFromFloat64(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\tf    float64\n\t\t\twant string\n\t\t}{\n\t\t\t// Zeros\n\t\t\t{-0, \"0\"},\n\t\t\t{0, \"0\"},\n\t\t\t{0.0, \"0\"},\n\t\t\t{0.00, \"0\"},\n\t\t\t{0.0000000000000000000, \"0\"},\n\n\t\t\t// Smallest non-zero\n\t\t\t{math.SmallestNonzeroFloat64, \"0.0000000000000000000\"},\n\n\t\t\t// Powers of ten\n\t\t\t{1e-21, \"0.0000000000000000000\"},\n\t\t\t{1e-20, \"0.0000000000000000000\"},\n\t\t\t{1e-19, \"0.0000000000000000001\"},\n\t\t\t{1e-18, \"0.000000000000000001\"},\n\t\t\t{1e-17, \"0.00000000000000001\"},\n\t\t\t{1e-16, \"0.0000000000000001\"},\n\t\t\t{1e-15, \"0.000000000000001\"},\n\t\t\t{1e-14, \"0.00000000000001\"},\n\t\t\t{1e-13, \"0.0000000000001\"},\n\t\t\t{1e-12, \"0.000000000001\"},\n\t\t\t{1e-11, \"0.00000000001\"},\n\t\t\t{1e-10, \"0.0000000001\"},\n\t\t\t{1e-9, \"0.000000001\"},\n\t\t\t{1e-8, \"0.00000001\"},\n\t\t\t{1e-7, \"0.0000001\"},\n\t\t\t{1e-6, \"0.000001\"},\n\t\t\t{1e-5, \"0.00001\"},\n\t\t\t{1e-4, \"0.0001\"},\n\t\t\t{1e-3, \"0.001\"},\n\t\t\t{1e-2, \"0.01\"},\n\t\t\t{1e-1, \"0.1\"},\n\t\t\t{1e0, \"1\"},\n\t\t\t{1e1, \"10\"},\n\t\t\t{1e2, \"100\"},\n\t\t\t{1e3, \"1000\"},\n\t\t\t{1e4, \"10000\"},\n\t\t\t{1e5, \"100000\"},\n\t\t\t{1e6, \"1000000\"},\n\t\t\t{1e7, \"10000000\"},\n\t\t\t{1e8, \"100000000\"},\n\t\t\t{1e9, \"1000000000\"},\n\t\t\t{1e10, \"10000000000\"},\n\t\t\t{1e11, \"100000000000\"},\n\t\t\t{1e12, \"1000000000000\"},\n\t\t\t{1e13, \"10000000000000\"},\n\t\t\t{1e14, \"100000000000000\"},\n\t\t\t{1e15, \"1000000000000000\"},\n\t\t\t{1e16, \"10000000000000000\"},\n\t\t\t{1e17, \"100000000000000000\"},\n\t\t\t{1e18, \"1000000000000000000\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\tgot, err := NewFromFloat64(tt.f)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"NewFromFloat64(%v) failed: %v\", tt.f, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"NewFromFloat64(%v) = %q, want %q\", tt.f, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]float64{\n\t\t\t\"overflow 1\":      1e19,\n\t\t\t\"overflow 2\":      1e20,\n\t\t\t\"overflow 3\":      math.MaxFloat64,\n\t\t\t\"overflow 4\":      -1e19,\n\t\t\t\"overflow 5\":      -1e20,\n\t\t\t\"overflow 6\":      -math.MaxFloat64,\n\t\t\t\"special value 1\": math.NaN(),\n\t\t\t\"special value 2\": math.Inf(1),\n\t\t\t\"special value 3\": math.Inf(-1),\n\t\t}\n\t\tfor name, tt := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\t_, err := NewFromFloat64(tt)\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"NewFromFloat64(%v) did not fail\", tt)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestParse(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\ts         string\n\t\t\twantNeg   bool\n\t\t\twantCoef  uint64\n\t\t\twantScale int\n\t\t}{\n\t\t\t{\"-9999999999999999999.0\", true, 9999999999999999999, 0},\n\t\t\t{\"-9999999999999999999\", true, 9999999999999999999, 0},\n\t\t\t{\"-999999999999999999.9\", true, 9999999999999999999, 1},\n\t\t\t{\"-99999999999999999.99\", true, 9999999999999999999, 2},\n\t\t\t{\"-1000000000000000000.0\", true, 1000000000000000000, 0},\n\t\t\t{\"-0.9999999999999999999\", true, 9999999999999999999, 19},\n\t\t\t{\"-00000000000000000000000000000000000001\", true, 1, 0},\n\t\t\t{\"-1\", true, 1, 0},\n\t\t\t{\"-1.\", true, 1, 0},\n\t\t\t{\"-.1\", true, 1, 1},\n\t\t\t{\"-0.1\", true, 1, 1},\n\t\t\t{\"-0.01\", true, 1, 2},\n\t\t\t{\"-0.0000000000000000001\", true, 1, 19},\n\t\t\t{\"-00000000000000000000000000000000000000\", false, 0, 0},\n\t\t\t{\"+00000000000000000000000000000000000000\", false, 0, 0},\n\t\t\t{\"0\", false, 0, 0},\n\t\t\t{\"0.\", false, 0, 0},\n\t\t\t{\".0\", false, 0, 1},\n\t\t\t{\"0.0\", false, 0, 1},\n\t\t\t{\"0.00\", false, 0, 2},\n\t\t\t{\"0.000000000000000000\", false, 0, 18},\n\t\t\t{\"0.0000000000000000000\", false, 0, 19},\n\t\t\t{\"0.00000000000000000000\", false, 0, 19},\n\t\t\t{\"00000000000000000000000000000000000001\", false, 1, 0},\n\t\t\t{\"1\", false, 1, 0},\n\t\t\t{\"1.\", false, 1, 0},\n\t\t\t{\".1\", false, 1, 1},\n\t\t\t{\"0.1\", false, 1, 1},\n\t\t\t{\"0.01\", false, 1, 2},\n\t\t\t{\"0.0000000000000000001\", false, 1, 19},\n\t\t\t{\"1000000000000000000.0\", false, 1000000000000000000, 0},\n\t\t\t{\"9999999999999999999.0\", false, 9999999999999999999, 0},\n\t\t\t{\"9999999999999999999\", false, 9999999999999999999, 0},\n\t\t\t{\"999999999999999999.9\", false, 9999999999999999999, 1},\n\t\t\t{\"99999999999999999.99\", false, 9999999999999999999, 2},\n\t\t\t{\"0.9999999999999999999\", false, 9999999999999999999, 19},\n\n\t\t\t// Rounding\n\t\t\t{\"-999999999999999999.99\", true, 1000000000000000000, 0},\n\t\t\t{\"0.00000000000000000000000000000000000000\", false, 0, 19},\n\t\t\t{\"0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", false, 0, 19},\n\t\t\t{\"-0.00000000000000000000000000000000000001\", false, 0, 19},\n\t\t\t{\"0.00000000000000000000000000000000000001\", false, 0, 19},\n\t\t\t{\"0.123456789012345678901234567890\", false, 1234567890123456789, 19},\n\t\t\t{\"0.12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678\", false, 1234567890123456789, 19},\n\n\t\t\t// Exponential notation\n\t\t\t{\"0e9\", false, 0, 0},\n\t\t\t{\"0e-9\", false, 0, 9},\n\t\t\t{\"1.23e-12\", false, 123, 14},\n\t\t\t{\"1.23e-5\", false, 123, 7},\n\t\t\t{\"1.23e-4\", false, 123, 6},\n\t\t\t{\"1.23e-3\", false, 123, 5},\n\t\t\t{\"1.23e-2\", false, 123, 4},\n\t\t\t{\"1.23e-1\", false, 123, 3},\n\t\t\t{\"1.23e+0\", false, 123, 2},\n\t\t\t{\"1.23e+1\", false, 123, 1},\n\t\t\t{\"1.23e+2\", false, 123, 0},\n\t\t\t{\"1.23e+3\", false, 1230, 0},\n\t\t\t{\"1.23e+4\", false, 12300, 0},\n\t\t\t{\"1.23e+5\", false, 123000, 0},\n\t\t\t{\"1.23e+12\", false, 1230000000000, 0},\n\t\t\t{\"0.0e-38\", false, 0, 19},\n\t\t\t{\"0e-38\", false, 0, 19},\n\t\t\t{\"1e-2\", false, 1, 2},\n\t\t\t{\"1e-1\", false, 1, 1},\n\t\t\t{\"1e0\", false, 1, 0},\n\t\t\t{\"1e+1\", false, 10, 0},\n\t\t\t{\"1e+2\", false, 100, 0},\n\t\t\t{\"0.0000000000000000001e-19\", false, 0, 19},\n\t\t\t{\"0.0000000000000000001e19\", false, 1, 0},\n\t\t\t{\"1000000000000000000e-19\", false, 1000000000000000000, 19},\n\t\t\t{\"1000000000000000000e-38\", false, 0, 19},\n\t\t\t{\"10000000000000000000e-38\", false, 1, 19},\n\t\t\t{\"100000000000000000000e-38\", false, 10, 19},\n\t\t\t{\"10000000000000000000000000000000000000e-38\", false, 1000000000000000000, 19},\n\t\t\t{\"1e+18\", false, 1000000000000000000, 0},\n\t\t\t{\"0.0000000001e10\", false, 1, 0},\n\t\t\t{\"10000000000e-10\", false, 10000000000, 10},\n\t\t\t{\"4E9\", false, 4000000000, 0},\n\t\t\t{\"0.73e-7\", false, 73, 9},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\tgot, err := Parse(tt.s)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"Parse(%q) failed: %v\", tt.s, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif got.IsNeg() != tt.wantNeg {\n\t\t\t\tt.Errorf(\"Parse(%q).IsNeg() = %v, want %v\", tt.s, got.IsNeg(), tt.wantNeg)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif got.Coef() != tt.wantCoef {\n\t\t\t\tt.Errorf(\"Parse(%q).Coef() = %v, want %v\", tt.s, got.Coef(), tt.wantCoef)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tif got.Scale() != tt.wantScale {\n\t\t\t\tt.Errorf(\"Parse(%q).Scale() = %v, want %v\", tt.s, got.Scale(), tt.wantScale)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]struct {\n\t\t\ts     string\n\t\t\tscale int\n\t\t}{\n\t\t\t\"missing digits 1\":  {\"\", 0},\n\t\t\t\"missing digits 2\":  {\"+\", 0},\n\t\t\t\"missing digits 3\":  {\"-\", 0},\n\t\t\t\"missing digits 4\":  {\".\", 0},\n\t\t\t\"missing digits 5\":  {\"..\", 0},\n\t\t\t\"missing digits 6\":  {\".e\", 0},\n\t\t\t\"missing digits 7\":  {\"e1\", 0},\n\t\t\t\"missing digits 8\":  {\"+e\", 0},\n\t\t\t\"missing digits 9\":  {\"-e\", 0},\n\t\t\t\"missing digits 10\": {\"e+\", 0},\n\t\t\t\"missing digits 11\": {\"e-\", 0},\n\t\t\t\"missing digits 12\": {\"e.0\", 0},\n\t\t\t\"missing digits 13\": {\"e+1\", 0},\n\t\t\t\"missing digits 14\": {\"e-1\", 0},\n\t\t\t\"invalid char 1\":    {\"a\", 0},\n\t\t\t\"invalid char 2\":    {\"1a\", 0},\n\t\t\t\"invalid char 3\":    {\"1.a\", 0},\n\t\t\t\"invalid char 4\":    {\" 1\", 0},\n\t\t\t\"invalid char 5\":    {\" +1\", 0},\n\t\t\t\"invalid char 6\":    {\" -1\", 0},\n\t\t\t\"invalid char 7\":    {\"1 \", 0},\n\t\t\t\"invalid char 8\":    {\"+1 \", 0},\n\t\t\t\"invalid char 9\":    {\"-1 \", 0},\n\t\t\t\"invalid char 10\":   {\" 1 \", 0},\n\t\t\t\"invalid char 11\":   {\" + 1\", 0},\n\t\t\t\"invalid char 12\":   {\" - 1\", 0},\n\t\t\t\"invalid char 13\":   {\"1,1\", 0},\n\t\t\t\"missing exp 1\":     {\"0.e\", 0},\n\t\t\t\"missing exp 2\":     {\"1e\", 0},\n\t\t\t\"missing exp 3\":     {\"1ee\", 0},\n\t\t\t\"exp range 1\":       {\"1e-331\", 0},\n\t\t\t\"exp range 2\":       {\"1e331\", 0},\n\t\t\t\"double sign 1\":     {\"++1\", 0},\n\t\t\t\"double sign 2\":     {\"--1\", 0},\n\t\t\t\"double sign 3\":     {\"+-1\", 0},\n\t\t\t\"double sign 4\":     {\"-+1\", 0},\n\t\t\t\"double sign 5\":     {\"-1.-1\", 0},\n\t\t\t\"double sign 6\":     {\"1.1-\", 0},\n\t\t\t\"double sign 7\":     {\"1e--1\", 0},\n\t\t\t\"double sign 8\":     {\"1e-+1\", 0},\n\t\t\t\"double sign 9\":     {\"1e+-1\", 0},\n\t\t\t\"double sign 10\":    {\"1e++1\", 0},\n\t\t\t\"double sign 11\":    {\"1e-1-\", 0},\n\t\t\t\"double sign 12\":    {\"-1-\", 0},\n\t\t\t\"double dot 1\":      {\"1.1.1\", 0},\n\t\t\t\"double dot 2\":      {\"..1\", 0},\n\t\t\t\"double dot 3\":      {\"1..1\", 0},\n\t\t\t\"double dot 4\":      {\".1.1\", 0},\n\t\t\t\"double dot 5\":      {\"1.1.\", 0},\n\t\t\t\"double dot 6\":      {\".1.\", 0},\n\t\t\t\"special value 1\":   {\"Inf\", 0},\n\t\t\t\"special value 2\":   {\"-infinity\", 0},\n\t\t\t\"special value 3\":   {\"NaN\", 0},\n\t\t\t\"overflow 1\":        {\"-10000000000000000000\", 0},\n\t\t\t\"overflow 2\":        {\"-99999999999999999990\", 0},\n\t\t\t\"overflow 3\":        {\"10000000000000000000\", 0},\n\t\t\t\"overflow 4\":        {\"99999999999999999990\", 0},\n\t\t\t\"overflow 5\":        {\"123456789012345678901234567890123456789\", 0},\n\t\t\t\"many digits\":       {\"0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 0},\n\t\t\t\"scale 1\":           {\"0\", MaxScale + 1},\n\t\t\t\"scale 2\":           {\"10\", MaxScale},\n\t\t\t\"scale 3\":           {\"100\", MaxScale - 1},\n\t\t}\n\t\tfor name, tt := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\t_, err := ParseExact(tt.s, tt.scale)\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"ParseExact(%q, %v) did not fail\", tt.s, tt.scale)\n\t\t\t\t\treturn\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestMustParse(t *testing.T) {\n\tt.Run(\"error\", func(t *testing.T) {\n\t\tdefer func() {\n\t\t\tif r := recover(); r == nil {\n\t\t\t\tt.Errorf(\"MustParse(\\\".\\\") did not panic\")\n\t\t\t}\n\t\t}()\n\t\tMustParse(\".\")\n\t})\n}\n\nfunc TestDecimalUnmarshalText(t *testing.T) {\n\tt.Run(\"error\", func(t *testing.T) {\n\t\td := Decimal{}\n\t\terr := d.UnmarshalText([]byte(\"1.1.1\"))\n\t\tif err == nil {\n\t\t\tt.Errorf(\"UnmarshalText(\\\"1.1.1\\\") did not fail\")\n\t\t}\n\t})\n}\n\nfunc TestDecimalUnmarshalBinary(t *testing.T) {\n\tt.Run(\"error\", func(t *testing.T) {\n\t\td := Decimal{}\n\t\terr := d.UnmarshalBinary([]byte(\"1.1.1\"))\n\t\tif err == nil {\n\t\t\tt.Errorf(\"UnmarshalBinary(\\\"1.1.1\\\") did not fail\")\n\t\t}\n\t})\n}\n\nfunc TestDecimalUnmarshalJSON(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\ts    string\n\t\t\twant string\n\t\t}{\n\t\t\t{\"null\", \"0\"},\n\t\t\t{\"\\\"-9999999999999999999.0\\\"\", \"-9999999999999999999\"},\n\t\t\t{\"\\\"-9999999999999999999\\\"\", \"-9999999999999999999\"},\n\t\t\t{\"\\\"-999999999999999999.9\\\"\", \"-999999999999999999.9\"},\n\t\t\t{\"\\\"-99999999999999999.99\\\"\", \"-99999999999999999.99\"},\n\t\t\t{\"\\\"-1000000000000000000.0\\\"\", \"-1000000000000000000\"},\n\t\t\t{\"\\\"-0.9999999999999999999\\\"\", \"-0.9999999999999999999\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\tvar got Decimal\n\t\t\terr := got.UnmarshalJSON([]byte(tt.s))\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"UnmarshalJSON(%q) failed: %v\", tt.s, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"UnmarshalJSON(%q) = %q, want %q\", tt.s, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\td := Decimal{}\n\t\terr := d.UnmarshalJSON([]byte(\"\\\"-1.1.1\\\"\"))\n\t\tif err == nil {\n\t\t\tt.Errorf(\"UnmarshalJSON(\\\"-1.1.1\\\") did not fail\")\n\t\t}\n\t})\n}\n\nfunc TestDecimalUnmarshalBSONValue(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\ttyp  byte\n\t\t\tdata []byte\n\t\t\twant string\n\t\t}{\n\t\t\t{1, []byte{0x0, 0x0, 0x0, 0x0, 0x80, 0x0, 0xf0, 0x3f}, \"1.0001220703125\"},\n\t\t\t{2, []byte{0x15, 0x0, 0x0, 0x0, 0x2d, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x0}, \"-9999999999999999999\"},\n\t\t\t{10, nil, \"0\"},\n\t\t\t{16, []byte{0xff, 0xff, 0xff, 0x7f}, \"2147483647\"},\n\t\t\t{18, []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f}, \"9223372036854775807\"},\n\t\t\t{19, []byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3a, 0x30}, \"1.265\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\tgot := Decimal{}\n\t\t\terr := got.UnmarshalBSONValue(tt.typ, tt.data)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"UnmarshalBSONValue(%v, % x) failed: %v\", tt.typ, tt.data, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"UnmarshalBSONValue(%v, % x) = %q, want %q\", tt.typ, tt.data, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\td := Decimal{}\n\t\terr := d.UnmarshalBSONValue(12, nil)\n\t\tif err == nil {\n\t\t\tt.Errorf(\"UnmarshalBSONValue(12, nil) did not fail\")\n\t\t}\n\t})\n}\n\nfunc TestParseBSONFloat64(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\tb    []byte\n\t\t\twant string\n\t\t}{\n\t\t\t// Zero\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, \"0\"},\n\n\t\t\t// Negative zero\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80}, \"0\"},\n\n\t\t\t// Integers\n\t\t\t{[]byte{0x2a, 0x1b, 0xf5, 0xf4, 0x10, 0x22, 0xb1, 0xc3}, \"-1234567892123200000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf0, 0xbf}, \"-1\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf0, 0x3f}, \"1\"},\n\t\t\t{[]byte{0x2a, 0x1b, 0xf5, 0xf4, 0x10, 0x22, 0xb1, 0x43}, \"1234567892123200000\"},\n\n\t\t\t// Floats\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x80, 0x0, 0xf0, 0xbf}, \"-1.0001220703125\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x80, 0x0, 0xf0, 0x3f}, \"1.0001220703125\"},\n\t\t}\n\n\t\tfor _, tt := range tests {\n\t\t\tgot, err := parseBSONFloat64(tt.b)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"parseBSONFloat64(%v) failed: %v\", tt.b, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"parseBSONFloat64(%v) = %q, want %q\", tt.b, got, want)\n\t\t\t}\n\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string][]byte{\n\t\t\t\"length 1\": {},\n\t\t\t\"length 2\": {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},\n\t\t\t\"length 3\": {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},\n\t\t\t\"nan 1\":    {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf8, 0x7f},\n\t\t\t\"nan 2\":    {0x12, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf8, 0x7f},\n\t\t\t\"inf 1\":    {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf0, 0x7f},\n\t\t\t\"inf 2\":    {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf0, 0xff},\n\t\t}\n\t\tfor name, tt := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\t_, err := parseBSONFloat64(tt)\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"parseBSONFloat64(%v) did not fail\", tt)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestParseBSONString(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\tb    []byte\n\t\t\twant string\n\t\t}{\n\t\t\t{[]byte{0x15, 0x0, 0x0, 0x0, 0x2d, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x0}, \"-9999999999999999999\"},\n\t\t\t{[]byte{0x17, 0x0, 0x0, 0x0, 0x2d, 0x30, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x0}, \"-0.0000000000000000001\"},\n\t\t\t{[]byte{0x16, 0x0, 0x0, 0x0, 0x30, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x0}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x2, 0x0, 0x0, 0x0, 0x30, 0x0}, \"0\"},\n\t\t\t{[]byte{0x16, 0x0, 0x0, 0x0, 0x30, 0x2e, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x0}, \"0.0000000000000000001\"},\n\t\t\t{[]byte{0x2, 0x0, 0x0, 0x0, 0x31, 0x0}, \"1\"},\n\t\t\t{[]byte{0x3, 0x0, 0x0, 0x0, 0x30, 0x31, 0x0}, \"1\"},\n\t\t\t{[]byte{0x15, 0x0, 0x0, 0x0, 0x33, 0x2e, 0x31, 0x34, 0x31, 0x35, 0x39, 0x32, 0x36, 0x35, 0x33, 0x35, 0x38, 0x39, 0x37, 0x39, 0x33, 0x32, 0x33, 0x38, 0x0}, \"3.141592653589793238\"},\n\t\t\t{[]byte{0x3, 0x0, 0x0, 0x0, 0x31, 0x30, 0x0}, \"10\"},\n\t\t\t{[]byte{0x14, 0x0, 0x0, 0x0, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x39, 0x0}, \"9999999999999999999\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\tgot, err := parseBSONString(tt.b)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"parseBSONString(%v) failed: %v\", tt.b, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"parseBSONString(%v) = %q, want %q\", tt.b, got, want)\n\t\t\t}\n\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string][]byte{\n\t\t\t\"length 1\":     {},\n\t\t\t\"length 2\":     {0x0, 0x0, 0x0, 0x0},\n\t\t\t\"length 3\":     {0x2, 0x0, 0x0, 0x0, 0x30},\n\t\t\t\"terminator 1\": {0x2, 0x0, 0x0, 0x0, 0x30, 0x30},\n\t\t}\n\t\tfor name, tt := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\t_, err := parseBSONString(tt)\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"parseBSONString(%v) did not fail\", tt)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestParseBSONInt32(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\tb    []byte\n\t\t\twant string\n\t\t}{\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x80}, \"-2147483648\"},\n\t\t\t{[]byte{0xff, 0xff, 0xff, 0xff}, \"-1\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0}, \"0\"},\n\t\t\t{[]byte{0x1, 0x0, 0x0, 0x0}, \"1\"},\n\t\t\t{[]byte{0xff, 0xff, 0xff, 0x7f}, \"2147483647\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\tgot, err := parseBSONInt32(tt.b)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"parseBSONInt32(%v) failed: %v\", tt.b, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"parseBSONInt32(%v) = %q, want %q\", tt.b, got, want)\n\t\t\t}\n\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string][]byte{\n\t\t\t\"length 1\": {},\n\t\t\t\"length 2\": {0x0, 0x0, 0x0},\n\t\t\t\"length 3\": {0x0, 0x0, 0x0, 0x0, 0x0},\n\t\t}\n\t\tfor name, tt := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\t_, err := parseBSONInt32(tt)\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"parseBSONInt32(%v) did not fail\", tt)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestParseBSONInt64(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\tb    []byte\n\t\t\twant string\n\t\t}{\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80}, \"-9223372036854775808\"},\n\t\t\t{[]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, \"-1\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, \"0\"},\n\t\t\t{[]byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, \"1\"},\n\t\t\t{[]byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f}, \"9223372036854775807\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\tgot, err := parseBSONInt64(tt.b)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"parseBSONInt64(%v) failed: %v\", tt.b, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"parseBSONInt64(%v) = %q, want %q\", tt.b, got, want)\n\t\t\t}\n\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string][]byte{\n\t\t\t\"length 1\": {},\n\t\t\t\"length 2\": {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},\n\t\t\t\"length 3\": {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},\n\t\t}\n\t\tfor name, tt := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\t_, err := parseBSONInt64(tt)\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"parseBSONInt64(%v) did not fail\", tt)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestParseIEEEDecimal128(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\tb    []byte\n\t\t\twant string\n\t\t}{\n\t\t\t// Zeros\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7a, 0x2b}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2a, 0x30}, \"0.00000000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2c, 0x30}, \"0.0000000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2e, 0x30}, \"0.000000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x30, 0x30}, \"0.00000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x32, 0x30}, \"0.0000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x34, 0x30}, \"0.000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x36, 0x30}, \"0.00000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x38, 0x30}, \"0.0000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3a, 0x30}, \"0.000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3c, 0x30}, \"0.00\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3e, 0x30}, \"0.0\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"0\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x42, 0x30}, \"0\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x30}, \"0\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x46, 0x30}, \"0\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x48, 0x30}, \"0\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4a, 0x30}, \"0\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4c, 0x30}, \"0\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4e, 0x30}, \"0\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x50, 0x30}, \"0\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x52, 0x30}, \"0\"},\n\n\t\t\t// Negative zeroes\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2e, 0xb0}, \"0.000000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x30, 0xb0}, \"0.00000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x32, 0xb0}, \"0.0000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x34, 0xb0}, \"0.000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x36, 0xb0}, \"0.00000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x38, 0xb0}, \"0.0000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3a, 0xb0}, \"0.000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3c, 0xb0}, \"0.00\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3e, 0xb0}, \"0.0\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xb0}, \"0\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x46, 0xb0}, \"0\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x52, 0xb0}, \"0\"},\n\n\t\t\t// Overflows with 0 coefficient\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0x5f}, \"0\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f}, \"0\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0xdf}, \"0\"},\n\n\t\t\t// Underflows\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0a, 0x5b, 0xc1, 0x38, 0x93, 0x8d, 0x44, 0xc6, 0x4d, 0x31, 0x0, 0x0}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x0a, 0x5b, 0xc1, 0x38, 0x93, 0x8d, 0x44, 0xc6, 0x4d, 0x31, 0x0, 0x80}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x81, 0xef, 0xac, 0x85, 0x5b, 0x41, 0x6d, 0x2d, 0xee, 0x04, 0x0, 0x0}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x81, 0xef, 0xac, 0x85, 0x5b, 0x41, 0x6d, 0x2d, 0xee, 0x04, 0x0, 0x0}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x81, 0xef, 0xac, 0x85, 0x5b, 0x41, 0x6d, 0x2d, 0xee, 0x04, 0x0, 0x80}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x81, 0xef, 0xac, 0x85, 0x5b, 0x41, 0x6d, 0x2d, 0xee, 0x04, 0x0, 0x80}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0x20, 0x3b, 0x9d, 0xb5, 0x05, 0x6f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x24}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x0, 0x0, 0xfe, 0xd8, 0x3f, 0x4e, 0x7c, 0x9f, 0xe4, 0xe2, 0x69, 0xe3, 0x8a, 0x5b, 0xcd, 0x17}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x02, 0x0}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x02, 0x0}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x02, 0x80}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x02, 0x80}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x42, 0x0}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x42, 0x80}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x72, 0x28}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0a, 0x5b, 0xc1, 0x38, 0x93, 0x8d, 0x44, 0xc6, 0x4d, 0x31, 0x0, 0x0}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x01, 0x0, 0x0, 0x0, 0x0a, 0x5b, 0xc1, 0x38, 0x93, 0x8d, 0x44, 0xc6, 0x4d, 0x31, 0x0, 0x80}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x0a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x0a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x0a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x0a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x80}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0x3c, 0x17, 0x25, 0x84, 0x19, 0xd7, 0x10, 0xc4, 0x2f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x24}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0xff, 0xff, 0xff, 0xff, 0x09, 0x5b, 0xc1, 0x38, 0x93, 0x8d, 0x44, 0xc6, 0x4d, 0x31, 0x0, 0x0}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0xff, 0xff, 0xff, 0xff, 0x09, 0x5b, 0xc1, 0x38, 0x93, 0x8d, 0x44, 0xc6, 0x4d, 0x31, 0x0, 0x80}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0xff, 0xff, 0xff, 0xff, 0x63, 0x8e, 0x8d, 0x37, 0xc0, 0x87, 0xad, 0xbe, 0x09, 0xed, 0x01, 0x0}, \"0.0000000000000000000\"},\n\n\t\t\t// Powers of 10\n\t\t\t{[]byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xb0}, \"-1\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3e, 0xb0}, \"-1.0\"},\n\t\t\t{[]byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3e, 0xb0}, \"-0.1\"},\n\t\t\t{[]byte{0x64, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2c, 0xb0}, \"-0.0000000100\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x26, 0x30}, \"0.0000000000010\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x28, 0x30}, \"0.000000000010\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2a, 0x30}, \"0.00000000010\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2c, 0x30}, \"0.0000000010\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2e, 0x30}, \"0.000000010\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x30, 0x30}, \"0.00000010\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x32, 0x30}, \"0.0000010\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x34, 0x30}, \"0.000010\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x36, 0x30}, \"0.00010\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x38, 0x30}, \"0.0010\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3a, 0x30}, \"0.010\"},\n\t\t\t{[]byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3e, 0x30}, \"0.1\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3c, 0x30}, \"0.10\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0xa, 0x5b, 0xc1, 0x38, 0x93, 0x8d, 0x44, 0xc6, 0x4d, 0x31, 0xfc, 0x2f}, \"0.1000000000000000000\"},\n\t\t\t{[]byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"1\"},\n\t\t\t{[]byte{0x64, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3c, 0x30}, \"1.00\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3e, 0x30}, \"1.0\"},\n\t\t\t{[]byte{0x64, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3e, 0x30}, \"10.0\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"10\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x42, 0x30}, \"100\"},\n\t\t\t{[]byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x46, 0x30}, \"1000\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x30}, \"1000\"},\n\t\t\t{[]byte{0xe8, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"1000\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x46, 0x30}, \"10000\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x48, 0x30}, \"100000\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4a, 0x30}, \"1000000\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4c, 0x30}, \"10000000\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4e, 0x30}, \"100000000\"},\n\t\t\t{[]byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x52, 0x30}, \"1000000000\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x50, 0x30}, \"1000000000\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x52, 0x30}, \"10000000000\"},\n\t\t\t{[]byte{0x64, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x52, 0x30}, \"100000000000\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x54, 0x30}, \"100000000000\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x56, 0x30}, \"1000000000000\"},\n\t\t\t{[]byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x58, 0x30}, \"10000000000000\"},\n\n\t\t\t// Integers\n\t\t\t{[]byte{0xee, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xb0}, \"-750\"},\n\t\t\t{[]byte{0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xb0}, \"-123\"},\n\t\t\t{[]byte{0x4c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xb0}, \"-76\"},\n\t\t\t{[]byte{0xc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xb0}, \"-12\"},\n\t\t\t{[]byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xb0}, \"-1\"},\n\t\t\t{[]byte{0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"2\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"7\"},\n\t\t\t{[]byte{0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"9\"},\n\t\t\t{[]byte{0xc, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"12\"},\n\t\t\t{[]byte{0x11, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"17\"},\n\t\t\t{[]byte{0x13, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"19\"},\n\t\t\t{[]byte{0x14, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"20\"},\n\t\t\t{[]byte{0x1d, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"29\"},\n\t\t\t{[]byte{0x1e, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"30\"},\n\t\t\t{[]byte{0x27, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"39\"},\n\t\t\t{[]byte{0x28, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"40\"},\n\t\t\t{[]byte{0x2c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"44\"},\n\t\t\t{[]byte{0x31, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"49\"},\n\t\t\t{[]byte{0x32, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"50\"},\n\t\t\t{[]byte{0x3b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"59\"},\n\t\t\t{[]byte{0x3c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"60\"},\n\t\t\t{[]byte{0x45, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"69\"},\n\t\t\t{[]byte{0x46, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"70\"},\n\t\t\t{[]byte{0x47, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"71\"},\n\t\t\t{[]byte{0x48, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"72\"},\n\t\t\t{[]byte{0x49, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"73\"},\n\t\t\t{[]byte{0x4a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"74\"},\n\t\t\t{[]byte{0x4b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"75\"},\n\t\t\t{[]byte{0x4c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"76\"},\n\t\t\t{[]byte{0x4d, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"77\"},\n\t\t\t{[]byte{0x4e, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"78\"},\n\t\t\t{[]byte{0x4f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"79\"},\n\t\t\t{[]byte{0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"123\"},\n\t\t\t{[]byte{0x8, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"520\"},\n\t\t\t{[]byte{0x9, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"521\"},\n\t\t\t{[]byte{0x9, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"777\"},\n\t\t\t{[]byte{0xa, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"778\"},\n\t\t\t{[]byte{0x13, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"787\"},\n\t\t\t{[]byte{0x1f, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"799\"},\n\t\t\t{[]byte{0x6d, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"877\"},\n\t\t\t{[]byte{0x78, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"888\"},\n\t\t\t{[]byte{0x79, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"889\"},\n\t\t\t{[]byte{0x82, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"898\"},\n\t\t\t{[]byte{0x83, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"899\"},\n\t\t\t{[]byte{0xd3, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"979\"},\n\t\t\t{[]byte{0xdc, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"988\"},\n\t\t\t{[]byte{0xdd, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"989\"},\n\t\t\t{[]byte{0xe2, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"994\"},\n\t\t\t{[]byte{0xe3, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"995\"},\n\t\t\t{[]byte{0xe5, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"997\"},\n\t\t\t{[]byte{0xe6, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"998\"},\n\t\t\t{[]byte{0xe7, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"999\"},\n\t\t\t{[]byte{0x30, 0x75, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"30000\"},\n\t\t\t{[]byte{0x90, 0x94, 0xd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"890000\"},\n\n\t\t\t{[]byte{0xfe, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"4294967294\"},\n\t\t\t{[]byte{0xff, 0xff, 0xff, 0xff, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"4294967295\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"4294967296\"},\n\t\t\t{[]byte{0x1, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"4294967297\"},\n\n\t\t\t{[]byte{0x1, 0x0, 0x0, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xb0}, \"-2147483649\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xb0}, \"-2147483648\"},\n\t\t\t{[]byte{0xff, 0xff, 0xff, 0x7f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xb0}, \"-2147483647\"},\n\t\t\t{[]byte{0xfe, 0xff, 0xff, 0x7f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xb0}, \"-2147483646\"},\n\t\t\t{[]byte{0xfe, 0xff, 0xff, 0x7f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"2147483646\"},\n\t\t\t{[]byte{0xff, 0xff, 0xff, 0x7f, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"2147483647\"},\n\t\t\t{[]byte{0x0, 0x0, 0x0, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"2147483648\"},\n\t\t\t{[]byte{0x1, 0x0, 0x0, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"2147483649\"},\n\n\t\t\t// 1265 multiplied by powers of 10\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x10, 0x30}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x12, 0x30}, \"0.0000000000000000000\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x14, 0x30}, \"0.0000000000000000001\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x16, 0x30}, \"0.0000000000000000013\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x18, 0x30}, \"0.0000000000000000126\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x28, 0x30}, \"0.000000001265\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2a, 0x30}, \"0.00000001265\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2c, 0x30}, \"0.0000001265\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2e, 0x30}, \"0.000001265\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x30, 0x30}, \"0.00001265\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x32, 0x30}, \"0.0001265\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x34, 0x30}, \"0.001265\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x36, 0x30}, \"0.01265\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x38, 0x30}, \"0.1265\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3a, 0x30}, \"1.265\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3c, 0x30}, \"12.65\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3e, 0x30}, \"126.5\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"1265\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x42, 0x30}, \"12650\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x30}, \"126500\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x46, 0x30}, \"1265000\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x48, 0x30}, \"12650000\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4a, 0x30}, \"126500000\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4c, 0x30}, \"1265000000\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4e, 0x30}, \"12650000000\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x50, 0x30}, \"126500000000\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x52, 0x30}, \"1265000000000\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x54, 0x30}, \"12650000000000\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x56, 0x30}, \"126500000000000\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x58, 0x30}, \"1265000000000000\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5a, 0x30}, \"12650000000000000\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5c, 0x30}, \"126500000000000000\"},\n\t\t\t{[]byte{0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5e, 0x30}, \"1265000000000000000\"},\n\n\t\t\t// 7 multiplied by powers of 10\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x26, 0x30}, \"0.0000000000007\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x28, 0x30}, \"0.000000000007\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2a, 0x30}, \"0.00000000007\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2c, 0x30}, \"0.0000000007\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2e, 0x30}, \"0.000000007\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x30, 0x30}, \"0.00000007\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x32, 0x30}, \"0.0000007\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x34, 0x30}, \"0.000007\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x36, 0x30}, \"0.00007\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x38, 0x30}, \"0.0007\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3a, 0x30}, \"0.007\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3c, 0x30}, \"0.07\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3e, 0x30}, \"0.7\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"7\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x42, 0x30}, \"70\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x44, 0x30}, \"700\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x46, 0x30}, \"7000\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x48, 0x30}, \"70000\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4a, 0x30}, \"700000\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4c, 0x30}, \"7000000\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4e, 0x30}, \"70000000\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x50, 0x30}, \"700000000\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x52, 0x30}, \"7000000000\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x52, 0x30}, \"7000000000\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x54, 0x30}, \"70000000000\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x56, 0x30}, \"700000000000\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x58, 0x30}, \"7000000000000\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5a, 0x30}, \"70000000000000\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5c, 0x30}, \"700000000000000\"},\n\t\t\t{[]byte{0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5e, 0x30}, \"7000000000000000\"},\n\n\t\t\t// Sequences of digits\n\t\t\t{[]byte{0x18, 0x5c, 0xa, 0xce, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x38, 0xb0}, \"-345678.5432\"},\n\t\t\t{[]byte{0x39, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xb0}, \"-12345\"},\n\t\t\t{[]byte{0xd2, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xb0}, \"-1234\"},\n\t\t\t{[]byte{0x39, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3c, 0xb0}, \"-123.45\"},\n\t\t\t{[]byte{0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3c, 0xb0}, \"-1.23\"},\n\t\t\t{[]byte{0x15, 0xcd, 0x5b, 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x20, 0x30}, \"0.0000000123456789\"},\n\t\t\t{[]byte{0x15, 0xcd, 0x5b, 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x22, 0x30}, \"0.000000123456789\"},\n\t\t\t{[]byte{0xf2, 0xaf, 0x96, 0x7e, 0xd0, 0x5c, 0x82, 0xde, 0x32, 0x97, 0xff, 0x6f, 0xde, 0x3c, 0xf0, 0x2f}, \"0.0000001234567890123\"},\n\t\t\t{[]byte{0x15, 0xcd, 0x5b, 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x24, 0x30}, \"0.00000123456789\"},\n\t\t\t{[]byte{0x15, 0xcd, 0x5b, 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x26, 0x30}, \"0.0000123456789\"},\n\t\t\t{[]byte{0x40, 0xef, 0x5a, 0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x2a, 0x30}, \"0.00123400000\"},\n\t\t\t{[]byte{0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3a, 0x30}, \"0.123\"},\n\t\t\t{[]byte{0x78, 0xdf, 0xd, 0x86, 0x48, 0x70, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x22, 0x30}, \"0.123456789012344\"},\n\t\t\t{[]byte{0x79, 0xdf, 0xd, 0x86, 0x48, 0x70, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x22, 0x30}, \"0.123456789012345\"},\n\t\t\t{[]byte{0xf2, 0xaf, 0x96, 0x7e, 0xd0, 0x5c, 0x82, 0xde, 0x32, 0x97, 0xff, 0x6f, 0xde, 0x3c, 0xfc, 0x2f}, \"0.1234567890123456789\"},\n\t\t\t{[]byte{0x7b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3c, 0x30}, \"1.23\"},\n\t\t\t{[]byte{0xd2, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3a, 0x30}, \"1.234\"},\n\t\t\t{[]byte{0x39, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3c, 0x30}, \"123.45\"},\n\t\t\t{[]byte{0xd2, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"1234\"},\n\t\t\t{[]byte{0x39, 0x30, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"12345\"},\n\t\t\t{[]byte{0x18, 0x5c, 0xa, 0xce, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x38, 0x30}, \"345678.5432\"},\n\t\t\t{[]byte{0x6a, 0xf9, 0xb, 0x7c, 0x50, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x34, 0x30}, \"345678.543210\"},\n\t\t\t{[]byte{0xf1, 0x98, 0x67, 0xc, 0x8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x36, 0x30}, \"345678.54321\"},\n\t\t\t{[]byte{0x6a, 0x19, 0x56, 0x25, 0x22, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x34, 0x30}, \"2345678.543210\"},\n\t\t\t{[]byte{0x6a, 0xb9, 0xc8, 0x73, 0x3a, 0xb, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x34, 0x30}, \"12345678.543210\"},\n\t\t\t{[]byte{0x40, 0xaf, 0xd, 0x86, 0x48, 0x70, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x34, 0x30}, \"123456789.000000\"},\n\t\t\t{[]byte{0x80, 0x91, 0xf, 0x86, 0x48, 0x70, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x34, 0x30}, \"123456789.123456\"},\n\t\t\t{[]byte{0x80, 0x91, 0xf, 0x86, 0x48, 0x70, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}, \"123456789123456\"},\n\t\t}\n\n\t\tfor _, tt := range tests {\n\t\t\tgot, err := parseIEEEDecimal128(tt.b)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"parseIEEEDecimal128([% x]) failed: %v\", tt.b, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"parseIEEEDecimal128([% x]) = %q, want %q\", tt.b, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string][]byte{\n\t\t\t\"length 1\":    {},\n\t\t\t\"length 2\":    {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},\n\t\t\t\"length 3\":    {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},\n\t\t\t\"inf 1\":       {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x78},\n\t\t\t\"inf 2\":       {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf8},\n\t\t\t\"nan 1\":       {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7c},\n\t\t\t\"nan 2\":       {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfc},\n\t\t\t\"nan 3\":       {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7e},\n\t\t\t\"nan 4\":       {0x12, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x7e},\n\t\t\t\"nan 5\":       {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe},\n\t\t\t\"overflow 1\":  {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x41, 0x30},\n\t\t\t\"overflow 2\":  {0x0, 0x0, 0x0, 0x0, 0xa, 0x5b, 0xc1, 0x38, 0x93, 0x8d, 0x44, 0xc6, 0x4d, 0x31, 0xcc, 0x37},\n\t\t\t\"overflow 3\":  {0x0, 0x0, 0x0, 0x0, 0xa, 0x5b, 0xc1, 0x38, 0x93, 0x8d, 0x44, 0xc6, 0x4d, 0x31, 0xfe, 0x5f},\n\t\t\t\"overflow 4\":  {0x0, 0x0, 0x0, 0x0, 0xa, 0x5b, 0xc1, 0x38, 0x93, 0x8d, 0x44, 0xc6, 0x4d, 0x31, 0xfe, 0xdf},\n\t\t\t\"overflow 5\":  {0x0, 0x0, 0x0, 0x0, 0x81, 0xef, 0xac, 0x85, 0x5b, 0x41, 0x6d, 0x2d, 0xee, 0x4, 0xfe, 0x5f},\n\t\t\t\"overflow 6\":  {0x0, 0x0, 0x0, 0x10, 0x61, 0x2, 0x25, 0x3e, 0x5e, 0xce, 0x4f, 0x20, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 7\":  {0x0, 0x0, 0x0, 0x40, 0xea, 0xed, 0x74, 0x46, 0xd0, 0x9c, 0x2c, 0x9f, 0xc, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 8\":  {0x0, 0x0, 0x0, 0x4a, 0x48, 0x1, 0x14, 0x16, 0x95, 0x45, 0x8, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 9\":  {0x0, 0x0, 0x0, 0x80, 0x26, 0x4b, 0x91, 0xc0, 0x22, 0x20, 0xbe, 0x37, 0x7e, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 10\": {0x0, 0x0, 0x0, 0x80, 0x7f, 0x1b, 0xcf, 0x85, 0xb2, 0x70, 0x59, 0xc8, 0xa4, 0x3c, 0xfe, 0x5f},\n\t\t\t\"overflow 11\": {0x0, 0x0, 0x0, 0x80, 0x7f, 0x1b, 0xcf, 0x85, 0xb2, 0x70, 0x59, 0xc8, 0xa4, 0x3c, 0xfe, 0xdf},\n\t\t\t\"overflow 12\": {0x0, 0x0, 0x0, 0xa0, 0xca, 0x17, 0x72, 0x6d, 0xae, 0xf, 0x1e, 0x43, 0x1, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 13\": {0x0, 0x0, 0x0, 0xa1, 0xed, 0xcc, 0xce, 0x1b, 0xc2, 0xd3, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 14\": {0x0, 0x0, 0x0, 0xe4, 0xd2, 0xc, 0xc8, 0xdc, 0xd2, 0xb7, 0x52, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 15\": {0x0, 0x0, 0x0, 0xe8, 0x3c, 0x80, 0xd0, 0x9f, 0x3c, 0x2e, 0x3b, 0x3, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 16\": {0x0, 0x0, 0x10, 0x63, 0x2d, 0x5e, 0xc7, 0x6b, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 17\": {0x0, 0x0, 0x40, 0xb2, 0xba, 0xc9, 0xe0, 0x19, 0x1e, 0x2, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 18\": {0x0, 0x0, 0x64, 0xa7, 0xb3, 0xb6, 0xe0, 0xd, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 19\": {0x0, 0x0, 0x80, 0xf6, 0x4a, 0xe1, 0xc7, 0x2, 0x2d, 0x15, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 20\": {0x0, 0x0, 0x8a, 0x5d, 0x78, 0x45, 0x63, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 21\": {0x0, 0x0, 0xa0, 0xde, 0xc5, 0xad, 0xc9, 0x35, 0x36, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 22\": {0x0, 0x0, 0xc1, 0x6f, 0xf2, 0x86, 0x23, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 23\": {0x0, 0x0, 0xe8, 0x89, 0x4, 0x23, 0xc7, 0x8a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 24\": {0x0, 0x10, 0xa5, 0xd4, 0xe8, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 25\": {0x0, 0x40, 0x7a, 0x10, 0xf3, 0x5a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 26\": {0x0, 0x80, 0xc6, 0xa4, 0x7e, 0x8d, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 27\": {0x0, 0xa0, 0x72, 0x4e, 0x18, 0x9, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 28\": {0x0, 0xca, 0x9a, 0x3b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 29\": {0x0, 0xe1, 0xf5, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 30\": {0x0, 0xe4, 0xb, 0x54, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 31\": {0x0, 0xe8, 0x76, 0x48, 0x17, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 32\": {0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf4, 0x30},\n\t\t\t\"overflow 33\": {0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfc, 0x5f},\n\t\t\t\"overflow 34\": {0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 35\": {0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x6, 0x31},\n\t\t\t\"overflow 36\": {0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xe, 0x38},\n\t\t\t\"overflow 37\": {0x7, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1e, 0x5f},\n\t\t\t\"overflow 38\": {0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf4, 0x30},\n\t\t\t\"overflow 39\": {0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 40\": {0x10, 0x27, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 41\": {0x40, 0x42, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 42\": {0x64, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xf4, 0x30},\n\t\t\t\"overflow 43\": {0x64, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 44\": {0x79, 0xd9, 0xe0, 0xf9, 0x76, 0x3a, 0xda, 0x42, 0x9d, 0x2, 0x0, 0x0, 0x0, 0x0, 0x58, 0x30},\n\t\t\t\"overflow 45\": {0x80, 0x96, 0x98, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 46\": {0xa0, 0x86, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 47\": {0xc7, 0x71, 0x1c, 0xc7, 0xb5, 0x48, 0xf3, 0x77, 0xdc, 0x80, 0xa1, 0x31, 0xc8, 0x36, 0x40, 0x30},\n\t\t\t\"overflow 48\": {0xe8, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0xfe, 0x5f},\n\t\t\t\"overflow 49\": {0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x60, 0x30},\n\t\t\t\"overflow 50\": {0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x62, 0x30},\n\t\t\t\"overflow 51\": {0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x64, 0x30},\n\t\t\t\"overflow 52\": {0xf1, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x68, 0x30},\n\t\t\t\"overflow 53\": {0xf2, 0xaf, 0x96, 0x7e, 0xd0, 0x5c, 0x82, 0xde, 0x32, 0x97, 0xff, 0x6f, 0xde, 0x3c, 0x40, 0x30},\n\t\t\t\"overflow 54\": {0xf2, 0xaf, 0x96, 0x7e, 0xd0, 0x5c, 0x82, 0xde, 0x32, 0x97, 0xff, 0x6f, 0xde, 0x3c, 0x40, 0xb0},\n\t\t\t\"overflow 55\": {0xf2, 0xaf, 0x96, 0x7e, 0xd0, 0x5c, 0x82, 0xde, 0x32, 0x97, 0xff, 0x6f, 0xde, 0x3c, 0xfe, 0x5f},\n\t\t\t\"overflow 56\": {0xf2, 0xaf, 0x96, 0x7e, 0xd0, 0x5c, 0x82, 0xde, 0x32, 0x97, 0xff, 0x6f, 0xde, 0x3c, 0xfe, 0xdf},\n\t\t\t\"overflow 57\": {0xff, 0xff, 0xff, 0xff, 0x63, 0x8e, 0x8d, 0x37, 0xc0, 0x87, 0xad, 0xbe, 0x9, 0xed, 0x41, 0x30},\n\t\t\t\"overflow 58\": {0xff, 0xff, 0xff, 0xff, 0x63, 0x8e, 0x8d, 0x37, 0xc0, 0x87, 0xad, 0xbe, 0x9, 0xed, 0xff, 0x5f},\n\t\t\t\"overflow 59\": {0xff, 0xff, 0xff, 0xff, 0x63, 0x8e, 0x8d, 0x37, 0xc0, 0x87, 0xad, 0xbe, 0x9, 0xed, 0xff, 0xdf},\n\t\t\t\"overflow 60\": {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x40, 0x30},\n\t\t}\n\t\tfor name, tt := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\t_, err := parseIEEEDecimal128(tt)\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"parseIEEEDecimal128([% x]) did not fail\", tt)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestDecimal_IEEEDecimal128(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td    string\n\t\t\twant []byte\n\t\t}{\n\t\t\t{\"-9999999999999999999\", []byte{0xff, 0xff, 0xe7, 0x89, 0x4, 0x23, 0xc7, 0x8a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xb0}},\n\t\t\t{\"-999999999999999999.9\", []byte{0xff, 0xff, 0xe7, 0x89, 0x4, 0x23, 0xc7, 0x8a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3e, 0xb0}},\n\t\t\t{\"-99999999999999999.99\", []byte{0xff, 0xff, 0xe7, 0x89, 0x4, 0x23, 0xc7, 0x8a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3c, 0xb0}},\n\t\t\t{\"-9999999999999999.999\", []byte{0xff, 0xff, 0xe7, 0x89, 0x4, 0x23, 0xc7, 0x8a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3a, 0xb0}},\n\t\t\t{\"-0.9999999999999999999\", []byte{0xff, 0xff, 0xe7, 0x89, 0x4, 0x23, 0xc7, 0x8a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1a, 0xb0}},\n\t\t\t{\"-1\", []byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xb0}},\n\t\t\t{\"-0.1\", []byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3e, 0xb0}},\n\t\t\t{\"-0.01\", []byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3c, 0xb0}},\n\t\t\t{\"-0.0000000000000000001\", []byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1a, 0xb0}},\n\t\t\t{\"0\", []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}},\n\t\t\t{\"0.0\", []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3e, 0x30}},\n\t\t\t{\"0.00\", []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3c, 0x30}},\n\t\t\t{\"0.0000000000000000000\", []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1a, 0x30}},\n\t\t\t{\"0.0000000000000000001\", []byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1a, 0x30}},\n\t\t\t{\"0.01\", []byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3c, 0x30}},\n\t\t\t{\"0.1\", []byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3e, 0x30}},\n\t\t\t{\"1\", []byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}},\n\t\t\t{\"0.9999999999999999999\", []byte{0xff, 0xff, 0xe7, 0x89, 0x4, 0x23, 0xc7, 0x8a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1a, 0x30}},\n\t\t\t{\"9999999999999999.999\", []byte{0xff, 0xff, 0xe7, 0x89, 0x4, 0x23, 0xc7, 0x8a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3a, 0x30}},\n\t\t\t{\"99999999999999999.99\", []byte{0xff, 0xff, 0xe7, 0x89, 0x4, 0x23, 0xc7, 0x8a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3c, 0x30}},\n\t\t\t{\"999999999999999999.9\", []byte{0xff, 0xff, 0xe7, 0x89, 0x4, 0x23, 0xc7, 0x8a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3e, 0x30}},\n\t\t\t{\"9999999999999999999\", []byte{0xff, 0xff, 0xe7, 0x89, 0x4, 0x23, 0xc7, 0x8a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}},\n\n\t\t\t// Exported constants\n\t\t\t{NegOne.String(), []byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0xb0}},\n\t\t\t{Zero.String(), []byte{0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}},\n\t\t\t{One.String(), []byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}},\n\t\t\t{Two.String(), []byte{0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}},\n\t\t\t{Ten.String(), []byte{0xa, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}},\n\t\t\t{Hundred.String(), []byte{0x64, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}},\n\t\t\t{Thousand.String(), []byte{0xe8, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x40, 0x30}},\n\t\t\t{E.String(), []byte{0x73, 0x61, 0xb3, 0xc0, 0xeb, 0x46, 0xb9, 0x25, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1c, 0x30}},\n\t\t\t{Pi.String(), []byte{0xd6, 0x49, 0x32, 0xa2, 0xdf, 0x2d, 0x99, 0x2b, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1c, 0x30}},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\tgot := d.ieeeDecimal128()\n\t\t\tif !bytes.Equal(got, tt.want) {\n\t\t\t\tt.Errorf(\"%q.ieeeDecimal128() = [% x], want [% x]\", d, got, tt.want)\n\t\t\t}\n\n\t\t}\n\t})\n}\n\nfunc TestDecimal_String(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\tneg   bool\n\t\t\tcoef  fint\n\t\t\tscale int\n\t\t\twant  string\n\t\t}{\n\t\t\t{true, maxCoef, 0, \"-9999999999999999999\"},\n\t\t\t{true, maxCoef, 1, \"-999999999999999999.9\"},\n\t\t\t{true, maxCoef, 2, \"-99999999999999999.99\"},\n\t\t\t{true, maxCoef, 3, \"-9999999999999999.999\"},\n\t\t\t{true, maxCoef, 19, \"-0.9999999999999999999\"},\n\t\t\t{true, 1, 0, \"-1\"},\n\t\t\t{true, 1, 1, \"-0.1\"},\n\t\t\t{true, 1, 2, \"-0.01\"},\n\t\t\t{true, 1, 19, \"-0.0000000000000000001\"},\n\t\t\t{false, 0, 0, \"0\"},\n\t\t\t{false, 0, 1, \"0.0\"},\n\t\t\t{false, 0, 2, \"0.00\"},\n\t\t\t{false, 0, 19, \"0.0000000000000000000\"},\n\t\t\t{false, 1, 19, \"0.0000000000000000001\"},\n\t\t\t{false, 1, 2, \"0.01\"},\n\t\t\t{false, 1, 1, \"0.1\"},\n\t\t\t{false, 1, 0, \"1\"},\n\t\t\t{false, maxCoef, 19, \"0.9999999999999999999\"},\n\t\t\t{false, maxCoef, 3, \"9999999999999999.999\"},\n\t\t\t{false, maxCoef, 2, \"99999999999999999.99\"},\n\t\t\t{false, maxCoef, 1, \"999999999999999999.9\"},\n\t\t\t{false, maxCoef, 0, \"9999999999999999999\"},\n\n\t\t\t// Exported constants\n\t\t\t{NegOne.neg, NegOne.coef, NegOne.Scale(), \"-1\"},\n\t\t\t{Zero.neg, Zero.coef, Zero.Scale(), \"0\"},\n\t\t\t{One.neg, One.coef, One.Scale(), \"1\"},\n\t\t\t{Two.neg, Two.coef, Two.Scale(), \"2\"},\n\t\t\t{Ten.neg, Ten.coef, Ten.Scale(), \"10\"},\n\t\t\t{Hundred.neg, Hundred.coef, Hundred.Scale(), \"100\"},\n\t\t\t{Thousand.neg, Thousand.coef, Thousand.Scale(), \"1000\"},\n\t\t\t{E.neg, E.coef, E.Scale(), \"2.718281828459045235\"},\n\t\t\t{Pi.neg, Pi.coef, Pi.Scale(), \"3.141592653589793238\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td, err := newSafe(tt.neg, tt.coef, tt.scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"newDecimal(%v, %v, %v) failed: %v\", tt.neg, tt.coef, tt.scale, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tgot := d.String()\n\t\t\tif got != tt.want {\n\t\t\t\tt.Errorf(\"newDecimal(%v, %v, %v).String() = %q, want %q\", tt.neg, tt.coef, tt.scale, got, tt.want)\n\t\t\t}\n\t\t}\n\t})\n}\n\nfunc TestDecimal_Float64(t *testing.T) {\n\ttests := []struct {\n\t\td         string\n\t\twantFloat float64\n\t\twantOk    bool\n\t}{\n\t\t{\"-9999999999999999999\", -9999999999999999999, true},\n\t\t{\"-1000000000000000000\", -1000000000000000000, true},\n\t\t{\"-1\", -1, true},\n\t\t{\"-0.9999999999999999999\", -0.9999999999999999999, true},\n\t\t{\"-0.0000000000000000001\", -0.0000000000000000001, true},\n\t\t{\"0.0000000000000000001\", 0.0000000000000000001, true},\n\t\t{\"0.9999999999999999999\", 0.9999999999999999999, true},\n\t\t{\"1\", 1, true},\n\t\t{\"1000000000000000000\", 1000000000000000000, true},\n\t\t{\"9999999999999999999\", 9999999999999999999, true},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\tgotFloat, gotOk := d.Float64()\n\t\tif gotFloat != tt.wantFloat || gotOk != tt.wantOk {\n\t\t\tt.Errorf(\"%q.Float64() = [%v %v], want [%v %v]\", d, gotFloat, gotOk, tt.wantFloat, tt.wantOk)\n\t\t}\n\t}\n}\n\nfunc TestDecimal_Int64(t *testing.T) {\n\ttests := []struct {\n\t\td                   string\n\t\tscale               int\n\t\twantWhole, wantFrac int64\n\t\twantOk              bool\n\t}{\n\t\t// Zeros\n\t\t{\"0.00\", 2, 0, 0, true},\n\t\t{\"0.0\", 1, 0, 0, true},\n\t\t{\"0\", 0, 0, 0, true},\n\n\t\t// Trailing zeros\n\t\t{\"0.1000\", 4, 0, 1000, true},\n\t\t{\"0.100\", 4, 0, 1000, true},\n\t\t{\"0.10\", 4, 0, 1000, true},\n\t\t{\"0.1\", 4, 0, 1000, true},\n\n\t\t{\"0.1000\", 4, 0, 1000, true},\n\t\t{\"0.100\", 3, 0, 100, true},\n\t\t{\"0.10\", 2, 0, 10, true},\n\t\t{\"0.1\", 1, 0, 1, true},\n\n\t\t// Powers of ten\n\t\t{\"0.0001\", 4, 0, 1, true},\n\t\t{\"0.0001\", 4, 0, 1, true},\n\t\t{\"0.001\", 4, 0, 10, true},\n\t\t{\"0.001\", 3, 0, 1, true},\n\t\t{\"0.01\", 4, 0, 100, true},\n\t\t{\"0.01\", 2, 0, 1, true},\n\t\t{\"0.1\", 4, 0, 1000, true},\n\t\t{\"0.1\", 1, 0, 1, true},\n\t\t{\"1\", 4, 1, 0, true},\n\t\t{\"1\", 0, 1, 0, true},\n\t\t{\"10\", 4, 10, 0, true},\n\t\t{\"10\", 0, 10, 0, true},\n\t\t{\"100\", 4, 100, 0, true},\n\t\t{\"100\", 0, 100, 0, true},\n\t\t{\"1000\", 4, 1000, 0, true},\n\t\t{\"1000\", 0, 1000, 0, true},\n\n\t\t// Signs\n\t\t{\"0.1\", 1, 0, 1, true},\n\t\t{\"1.0\", 1, 1, 0, true},\n\t\t{\"1.1\", 1, 1, 1, true},\n\n\t\t{\"-0.1\", 1, 0, -1, true},\n\t\t{\"-1.0\", 1, -1, 0, true},\n\t\t{\"-1.1\", 1, -1, -1, true},\n\n\t\t// Rounding\n\t\t{\"5\", 0, 5, 0, true},\n\t\t{\"5\", 1, 5, 0, true},\n\t\t{\"5\", 2, 5, 0, true},\n\t\t{\"5\", 3, 5, 0, true},\n\n\t\t{\"0.5\", 0, 0, 0, true},\n\t\t{\"0.5\", 1, 0, 5, true},\n\t\t{\"0.5\", 2, 0, 50, true},\n\t\t{\"0.5\", 3, 0, 500, true},\n\n\t\t{\"0.05\", 0, 0, 0, true},\n\t\t{\"0.05\", 1, 0, 0, true},\n\t\t{\"0.05\", 2, 0, 5, true},\n\t\t{\"0.05\", 3, 0, 50, true},\n\n\t\t{\"0.005\", 0, 0, 0, true},\n\t\t{\"0.005\", 1, 0, 0, true},\n\t\t{\"0.005\", 2, 0, 0, true},\n\t\t{\"0.005\", 3, 0, 5, true},\n\n\t\t{\"0.51\", 0, 1, 0, true},\n\t\t{\"0.051\", 1, 0, 1, true},\n\t\t{\"0.0051\", 2, 0, 1, true},\n\t\t{\"0.00051\", 3, 0, 1, true},\n\n\t\t{\"0.9\", 0, 1, 0, true},\n\t\t{\"0.9\", 1, 0, 9, true},\n\t\t{\"0.9\", 2, 0, 90, true},\n\t\t{\"0.9\", 3, 0, 900, true},\n\n\t\t{\"0.9999999999999999999\", 0, 1, 0, true},\n\t\t{\"0.9999999999999999999\", 1, 1, 0, true},\n\t\t{\"0.9999999999999999999\", 2, 1, 0, true},\n\t\t{\"0.9999999999999999999\", 3, 1, 0, true},\n\n\t\t// Edge cases\n\t\t{\"-9223372036854775808\", 0, -9223372036854775808, 0, true},\n\t\t{\"-922337203685477580.9\", 1, -922337203685477580, -9, true},\n\t\t{\"-9.223372036854775809\", 18, -9, -223372036854775809, true},\n\t\t{\"-0.9223372036854775808\", 19, 0, -9223372036854775808, true},\n\t\t{\"0.9223372036854775807\", 19, 0, 9223372036854775807, true},\n\t\t{\"9.223372036854775808\", 18, 9, 223372036854775808, true},\n\t\t{\"922337203685477580.8\", 1, 922337203685477580, 8, true},\n\t\t{\"9223372036854775807\", 0, 9223372036854775807, 0, true},\n\n\t\t// Failures\n\t\t{\"-9999999999999999999\", 0, 0, 0, false},\n\t\t{\"-9223372036854775809\", 0, 0, 0, false},\n\t\t{\"-0.9999999999999999999\", 19, 0, 0, false},\n\t\t{\"-0.9223372036854775809\", 19, 0, 0, false},\n\t\t{\"0.1\", -1, 0, 0, false},\n\t\t{\"0.1\", 20, 0, 0, false},\n\t\t{\"0.9223372036854775808\", 19, 0, 0, false},\n\t\t{\"0.9999999999999999999\", 19, 0, 0, false},\n\t\t{\"9223372036854775808\", 0, 0, 0, false},\n\t\t{\"9999999999999999999\", 0, 0, 0, false},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\tgotWhole, gotFrac, gotOk := d.Int64(tt.scale)\n\t\tif gotWhole != tt.wantWhole || gotFrac != tt.wantFrac || gotOk != tt.wantOk {\n\t\t\tt.Errorf(\"%q.Int64(%v) = [%v %v %v], want [%v %v %v]\", d, tt.scale, gotWhole, gotFrac, gotOk, tt.wantWhole, tt.wantFrac, tt.wantOk)\n\t\t}\n\t}\n}\n\nfunc TestDecimal_Scan(t *testing.T) {\n\tt.Run(\"float64\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\tf    float64\n\t\t\twant string\n\t\t}{\n\t\t\t{math.SmallestNonzeroFloat64, \"0.0000000000000000000\"},\n\t\t\t{1e-20, \"0.0000000000000000000\"},\n\t\t\t{1e-19, \"0.0000000000000000001\"},\n\t\t\t{1e-5, \"0.00001\"},\n\t\t\t{1e-4, \"0.0001\"},\n\t\t\t{1e-3, \"0.001\"},\n\t\t\t{1e-2, \"0.01\"},\n\t\t\t{1e-1, \"0.1\"},\n\t\t\t{1e0, \"1\"},\n\t\t\t{1e1, \"10\"},\n\t\t\t{1e2, \"100\"},\n\t\t\t{1e3, \"1000\"},\n\t\t\t{1e4, \"10000\"},\n\t\t\t{1e5, \"100000\"},\n\t\t\t{1e18, \"1000000000000000000\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\tgot := Decimal{}\n\t\t\terr := got.Scan(tt.f)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"Scan(%v) failed: %v\", tt.f, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"Scan(%v) = %v, want %v\", tt.f, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"float32\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\tf    float32\n\t\t\twant string\n\t\t}{\n\t\t\t{math.SmallestNonzeroFloat32, \"0.0000000000000000000\"},\n\t\t\t{1e-20, \"0.0000000000000000000\"},\n\t\t\t{1e-19, \"0.0000000000000000001\"},\n\t\t\t{1e-5, \"0.0000099999997473788\"},\n\t\t\t{1e-4, \"0.0000999999974737875\"},\n\t\t\t{1e-3, \"0.0010000000474974513\"},\n\t\t\t{1e-2, \"0.009999999776482582\"},\n\t\t\t{1e-1, \"0.10000000149011612\"},\n\t\t\t{1e0, \"1\"},\n\t\t\t{1e1, \"10\"},\n\t\t\t{1e2, \"100\"},\n\t\t\t{1e3, \"1000\"},\n\t\t\t{1e4, \"10000\"},\n\t\t\t{1e5, \"100000\"},\n\t\t\t{1e18, \"999999984306749400\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\tgot := Decimal{}\n\t\t\terr := got.Scan(tt.f)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"Scan(%v) failed: %v\", tt.f, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"Scan(%v) = %v, want %v\", tt.f, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"int64\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\ti    int64\n\t\t\twant string\n\t\t}{\n\t\t\t{math.MinInt64, \"-9223372036854775808\"},\n\t\t\t{0, \"0\"},\n\t\t\t{math.MaxInt64, \"9223372036854775807\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\tgot := Decimal{}\n\t\t\terr := got.Scan(tt.i)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"Scan(%v) failed: %v\", tt.i, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"Scan(%v) = %v, want %v\", tt.i, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"uint64\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\ti    uint64\n\t\t\twant string\n\t\t}{\n\t\t\t{0, \"0\"},\n\t\t\t{9999999999999999999, \"9999999999999999999\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\tgot := Decimal{}\n\t\t\terr := got.Scan(tt.i)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"Scan(%v) failed: %v\", tt.i, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"Scan(%v) = %v, want %v\", tt.i, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"[]byte\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\tb    []byte\n\t\t\twant string\n\t\t}{\n\t\t\t{[]byte(\"-9223372036854775808\"), \"-9223372036854775808\"},\n\t\t\t{[]byte(\"0\"), \"0\"},\n\t\t\t{[]byte(\"9223372036854775807\"), \"9223372036854775807\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\tgot := Decimal{}\n\t\t\terr := got.Scan(tt.b)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"Scan(%v) failed: %v\", tt.b, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"Scan(%v) = %v, want %v\", tt.b, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := []any{\n\t\t\tint8(123),\n\t\t\tint16(123),\n\t\t\tint32(123),\n\t\t\tint(123),\n\t\t\tuint8(123),\n\t\t\tuint16(123),\n\t\t\tuint32(123),\n\t\t\tuint(123),\n\t\t\tnil,\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\tgot := Decimal{}\n\t\t\terr := got.Scan(tt)\n\t\t\tif err == nil {\n\t\t\t\tt.Errorf(\"Scan(%v) did not fail\", tt)\n\t\t\t}\n\t\t}\n\t})\n}\n\nfunc TestDecimal_Format(t *testing.T) {\n\ttests := []struct {\n\t\td, format, want string\n\t}{\n\t\t// %T verb\n\t\t{\"12.34\", \"%T\", \"decimal.Decimal\"},\n\n\t\t// %q verb\n\t\t{\"12.34\", \"%q\", \"\\\"12.34\\\"\"},\n\t\t{\"12.34\", \"%+q\", \"\\\"+12.34\\\"\"},\n\t\t{\"12.34\", \"%.6q\", \"\\\"12.34\\\"\"}, // precision is ignored\n\t\t{\"12.34\", \"%7q\", \"\\\"12.34\\\"\"},\n\t\t{\"12.34\", \"%8q\", \" \\\"12.34\\\"\"},\n\t\t{\"12.34\", \"%9q\", \"  \\\"12.34\\\"\"},\n\t\t{\"12.34\", \"%10q\", \"   \\\"12.34\\\"\"},\n\t\t{\"12.34\", \"%010q\", \"\\\"00012.34\\\"\"},\n\t\t{\"12.34\", \"%+10q\", \"  \\\"+12.34\\\"\"},\n\t\t{\"12.34\", \"%-10q\", \"\\\"12.34\\\"   \"},\n\n\t\t// %s verb\n\t\t{\"12.34\", \"%s\", \"12.34\"},\n\t\t{\"12.34\", \"%+s\", \"+12.34\"},\n\t\t{\"12.34\", \"%.6s\", \"12.34\"}, // precision is ignored\n\t\t{\"12.34\", \"%7s\", \"  12.34\"},\n\t\t{\"12.34\", \"%8s\", \"   12.34\"},\n\t\t{\"12.34\", \"%9s\", \"    12.34\"},\n\t\t{\"12.34\", \"%10s\", \"     12.34\"},\n\t\t{\"12.34\", \"%010s\", \"0000012.34\"},\n\t\t{\"12.34\", \"%+10s\", \"    +12.34\"},\n\t\t{\"12.34\", \"%-10s\", \"12.34     \"},\n\n\t\t// %v verb\n\t\t{\"12.34\", \"%v\", \"12.34\"},\n\t\t{\"12.34\", \"% v\", \" 12.34\"},\n\t\t{\"12.34\", \"%+v\", \"+12.34\"},\n\t\t{\"12.34\", \"%.6v\", \"12.34\"}, // precision is ignored\n\t\t{\"12.34\", \"%7v\", \"  12.34\"},\n\t\t{\"12.34\", \"%8v\", \"   12.34\"},\n\t\t{\"12.34\", \"%9v\", \"    12.34\"},\n\t\t{\"12.34\", \"%10v\", \"     12.34\"},\n\t\t{\"12.34\", \"%010v\", \"0000012.34\"},\n\t\t{\"12.34\", \"%+10v\", \"    +12.34\"},\n\t\t{\"12.34\", \"%-10v\", \"12.34     \"},\n\n\t\t// %k verb\n\t\t{\"12.34\", \"%k\", \"1234%\"},\n\t\t{\"12.34\", \"%+k\", \"+1234%\"},\n\t\t{\"12.34\", \"%.1k\", \"1234.0%\"},\n\t\t{\"12.34\", \"%.2k\", \"1234.00%\"},\n\t\t{\"12.34\", \"%.3k\", \"1234.000%\"},\n\t\t{\"12.34\", \"%.4k\", \"1234.0000%\"},\n\t\t{\"12.34\", \"%.5k\", \"1234.00000%\"},\n\t\t{\"12.34\", \"%.6k\", \"1234.000000%\"},\n\t\t{\"12.34\", \"%7k\", \"  1234%\"},\n\t\t{\"12.34\", \"%8k\", \"   1234%\"},\n\t\t{\"12.34\", \"%9k\", \"    1234%\"},\n\t\t{\"12.34\", \"%10k\", \"     1234%\"},\n\t\t{\"12.34\", \"%010k\", \"000001234%\"},\n\t\t{\"12.34\", \"%+10k\", \"    +1234%\"},\n\t\t{\"12.34\", \"%-10k\", \"1234%     \"},\n\t\t{\"2.3\", \"%k\", \"230%\"},\n\t\t{\"0.23\", \"%k\", \"23%\"},\n\t\t{\"0.023\", \"%k\", \"2.3%\"},\n\t\t{\"2.30\", \"%k\", \"230%\"},\n\t\t{\"0.230\", \"%k\", \"23.0%\"},\n\t\t{\"0.0230\", \"%k\", \"2.30%\"},\n\t\t{\"2.300\", \"%k\", \"230.0%\"},\n\t\t{\"0.2300\", \"%k\", \"23.00%\"},\n\t\t{\"0.02300\", \"%k\", \"2.300%\"},\n\n\t\t// %f verb\n\t\t{\"12.34\", \"%f\", \"12.34\"},\n\t\t{\"12.34\", \"%+f\", \"+12.34\"},\n\t\t{\"12.34\", \"%.1f\", \"12.3\"},\n\t\t{\"12.34\", \"%.2f\", \"12.34\"},\n\t\t{\"12.34\", \"%.3f\", \"12.340\"},\n\t\t{\"12.34\", \"%.4f\", \"12.3400\"},\n\t\t{\"12.34\", \"%.5f\", \"12.34000\"},\n\t\t{\"12.34\", \"%.6f\", \"12.340000\"},\n\t\t{\"12.34\", \"%7f\", \"  12.34\"},\n\t\t{\"12.34\", \"%8f\", \"   12.34\"},\n\t\t{\"12.34\", \"%9f\", \"    12.34\"},\n\t\t{\"12.34\", \"%10f\", \"     12.34\"},\n\t\t{\"12.34\", \"%010f\", \"0000012.34\"},\n\t\t{\"12.34\", \"%+10f\", \"    +12.34\"},\n\t\t{\"12.34\", \"%-10f\", \"12.34     \"},\n\t\t{\"12.34\", \"%.1f\", \"12.3\"},\n\t\t{\"0\", \"%.2f\", \"0.00\"},\n\t\t{\"0\", \"%5.2f\", \" 0.00\"},\n\t\t{\"9.996208266660\", \"%.2f\", \"10.00\"},\n\t\t{\"0.9996208266660\", \"%.2f\", \"1.00\"},\n\t\t{\"0.09996208266660\", \"%.2f\", \"0.10\"},\n\t\t{\"0.009996208266660\", \"%.2f\", \"0.01\"},\n\t\t{\"500.44\", \"%6.1f\", \" 500.4\"},\n\t\t{\"-404.040\", \"%-010.f\", \"-404      \"},\n\t\t{\"-404.040\", \"%-10.f\", \"-404      \"},\n\t\t{\"1\", \"%.20f\", \"1.00000000000000000000\"},\n\t\t{\"1.000000000000000000\", \"%.20f\", \"1.00000000000000000000\"},\n\t\t{\"9999999999999999999\", \"%.1f\", \"9999999999999999999.0\"},\n\t\t{\"9999999999999999999\", \"%.2f\", \"9999999999999999999.00\"},\n\t\t{\"9999999999999999999\", \"%.3f\", \"9999999999999999999.000\"},\n\n\t\t// Wrong verbs\n\t\t{\"12.34\", \"%b\", \"%!b(decimal.Decimal=12.34)\"},\n\t\t{\"12.34\", \"%e\", \"%!e(decimal.Decimal=12.34)\"},\n\t\t{\"12.34\", \"%E\", \"%!E(decimal.Decimal=12.34)\"},\n\t\t{\"12.34\", \"%g\", \"%!g(decimal.Decimal=12.34)\"},\n\t\t{\"12.34\", \"%G\", \"%!G(decimal.Decimal=12.34)\"},\n\t\t{\"12.34\", \"%x\", \"%!x(decimal.Decimal=12.34)\"},\n\t\t{\"12.34\", \"%X\", \"%!X(decimal.Decimal=12.34)\"},\n\n\t\t// Errors\n\t\t{\"9999999999999999999\", \"%k\", \"%!k(PANIC=Format method: formatting percent: computing [9999999999999999999 * 100]: decimal overflow: the integer part of a decimal.Decimal can have at most 19 digits, but it has 21 digits)\"},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\tgot := fmt.Sprintf(tt.format, d)\n\t\tif got != tt.want {\n\t\t\tt.Errorf(\"fmt.Sprintf(%q, %q) = %q, want %q\", tt.format, tt.d, got, tt.want)\n\t\t}\n\t}\n}\n\nfunc TestDecimal_Prec(t *testing.T) {\n\ttests := []struct {\n\t\td    string\n\t\twant int\n\t}{\n\t\t{\"0000\", 0},\n\t\t{\"000\", 0},\n\t\t{\"00\", 0},\n\t\t{\"0\", 0},\n\t\t{\"0.000\", 0},\n\t\t{\"0.00\", 0},\n\t\t{\"0.0\", 0},\n\t\t{\"0\", 0},\n\t\t{\"0.0000000000000000001\", 1},\n\t\t{\"0.000000000000000001\", 1},\n\t\t{\"0.00000000000000001\", 1},\n\t\t{\"0.0000000000000001\", 1},\n\t\t{\"0.000000000000001\", 1},\n\t\t{\"0.00000000000001\", 1},\n\t\t{\"0.0000000000001\", 1},\n\t\t{\"0.000000000001\", 1},\n\t\t{\"0.00000000001\", 1},\n\t\t{\"0.0000000001\", 1},\n\t\t{\"0.000000001\", 1},\n\t\t{\"0.00000001\", 1},\n\t\t{\"0.0000001\", 1},\n\t\t{\"0.000001\", 1},\n\t\t{\"0.00001\", 1},\n\t\t{\"0.0001\", 1},\n\t\t{\"0.001\", 1},\n\t\t{\"0.01\", 1},\n\t\t{\"0.1\", 1},\n\t\t{\"1\", 1},\n\t\t{\"0.1000000000000000000\", 19},\n\t\t{\"0.100000000000000000\", 18},\n\t\t{\"0.10000000000000000\", 17},\n\t\t{\"0.1000000000000000\", 16},\n\t\t{\"0.100000000000000\", 15},\n\t\t{\"0.10000000000000\", 14},\n\t\t{\"0.1000000000000\", 13},\n\t\t{\"0.100000000000\", 12},\n\t\t{\"0.10000000000\", 11},\n\t\t{\"0.1000000000\", 10},\n\t\t{\"0.100000000\", 9},\n\t\t{\"0.10000000\", 8},\n\t\t{\"0.1000000\", 7},\n\t\t{\"0.100000\", 6},\n\t\t{\"0.10000\", 5},\n\t\t{\"0.1000\", 4},\n\t\t{\"0.100\", 3},\n\t\t{\"0.10\", 2},\n\t\t{\"0.1\", 1},\n\t\t{\"1\", 1},\n\t\t{\"10\", 2},\n\t\t{\"100\", 3},\n\t\t{\"1000\", 4},\n\t\t{\"10000\", 5},\n\t\t{\"100000\", 6},\n\t\t{\"1000000\", 7},\n\t\t{\"10000000\", 8},\n\t\t{\"100000000\", 9},\n\t\t{\"1000000000\", 10},\n\t\t{\"10000000000\", 11},\n\t\t{\"100000000000\", 12},\n\t\t{\"1000000000000\", 13},\n\t\t{\"10000000000000\", 14},\n\t\t{\"100000000000000\", 15},\n\t\t{\"1000000000000000\", 16},\n\t\t{\"10000000000000000\", 17},\n\t\t{\"100000000000000000\", 18},\n\t\t{\"1000000000000000000\", 19},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\tgot := d.Prec()\n\t\tif got != tt.want {\n\t\t\tt.Errorf(\"%q.Prec() = %v, want %v\", tt.d, got, tt.want)\n\t\t}\n\t}\n}\n\nfunc TestDecimal_Rescale(t *testing.T) {\n\ttests := []struct {\n\t\td     string\n\t\tscale int\n\t\twant  string\n\t}{\n\t\t// Zeros\n\t\t{\"0\", 0, \"0\"},\n\t\t{\"0\", 1, \"0.0\"},\n\t\t{\"0\", 2, \"0.00\"},\n\t\t{\"0\", 19, \"0.0000000000000000000\"},\n\t\t{\"0.0\", 1, \"0.0\"},\n\t\t{\"0.00\", 2, \"0.00\"},\n\t\t{\"0.000000000\", 19, \"0.0000000000000000000\"},\n\t\t{\"0.000000000\", 0, \"0\"},\n\t\t{\"0.000000000\", 1, \"0.0\"},\n\t\t{\"0.000000000\", 2, \"0.00\"},\n\n\t\t// Tests from GDA\n\t\t{\"2.17\", 0, \"2\"},\n\t\t{\"2.17\", 1, \"2.2\"},\n\t\t{\"2.17\", 2, \"2.17\"},\n\t\t{\"2.17\", 9, \"2.170000000\"},\n\t\t{\"1.2345\", 2, \"1.23\"},\n\t\t{\"1.2355\", 2, \"1.24\"},\n\t\t{\"1.2345\", 9, \"1.234500000\"},\n\t\t{\"9.9999\", 2, \"10.00\"},\n\t\t{\"0.0001\", 2, \"0.00\"},\n\t\t{\"0.001\", 2, \"0.00\"},\n\t\t{\"0.009\", 2, \"0.01\"},\n\n\t\t// Some extra tests\n\t\t{\"0.03\", 2, \"0.03\"},\n\t\t{\"0.02\", 2, \"0.02\"},\n\t\t{\"0.01\", 2, \"0.01\"},\n\t\t{\"0.00\", 2, \"0.00\"},\n\t\t{\"-0.01\", 2, \"-0.01\"},\n\t\t{\"-0.02\", 2, \"-0.02\"},\n\t\t{\"-0.03\", 2, \"-0.03\"},\n\t\t{\"0.0049\", 2, \"0.00\"},\n\t\t{\"0.0051\", 2, \"0.01\"},\n\t\t{\"0.0149\", 2, \"0.01\"},\n\t\t{\"0.0151\", 2, \"0.02\"},\n\t\t{\"-0.0049\", 2, \"0.00\"},\n\t\t{\"-0.0051\", 2, \"-0.01\"},\n\t\t{\"-0.0149\", 2, \"-0.01\"},\n\t\t{\"-0.0151\", 2, \"-0.02\"},\n\t\t{\"0.0050\", 2, \"0.00\"},\n\t\t{\"0.0150\", 2, \"0.02\"},\n\t\t{\"0.0250\", 2, \"0.02\"},\n\t\t{\"0.0350\", 2, \"0.04\"},\n\t\t{\"-0.0050\", 2, \"0.00\"},\n\t\t{\"-0.0150\", 2, \"-0.02\"},\n\t\t{\"-0.0250\", 2, \"-0.02\"},\n\t\t{\"-0.0350\", 2, \"-0.04\"},\n\t\t{\"3.0448\", 2, \"3.04\"},\n\t\t{\"3.0450\", 2, \"3.04\"},\n\t\t{\"3.0452\", 2, \"3.05\"},\n\t\t{\"3.0956\", 2, \"3.10\"},\n\n\t\t// Tests from Wikipedia\n\t\t{\"1.8\", 0, \"2\"},\n\t\t{\"1.5\", 0, \"2\"},\n\t\t{\"1.2\", 0, \"1\"},\n\t\t{\"0.8\", 0, \"1\"},\n\t\t{\"0.5\", 0, \"0\"},\n\t\t{\"0.2\", 0, \"0\"},\n\t\t{\"-0.2\", 0, \"0\"},\n\t\t{\"-0.5\", 0, \"0\"},\n\t\t{\"-0.8\", 0, \"-1\"},\n\t\t{\"-1.2\", 0, \"-1\"},\n\t\t{\"-1.5\", 0, \"-2\"},\n\t\t{\"-1.8\", 0, \"-2\"},\n\n\t\t// Negative scale\n\t\t{\"1000000000000000000\", -1, \"1000000000000000000\"},\n\n\t\t// Padding overflow\n\t\t{\"1000000000000000000\", 1, \"1000000000000000000\"},\n\t\t{\"100000000000000000\", 2, \"100000000000000000.0\"},\n\t\t{\"10000000000000000\", 3, \"10000000000000000.00\"},\n\t\t{\"1000000000000000\", 4, \"1000000000000000.000\"},\n\t\t{\"100000000000000\", 5, \"100000000000000.0000\"},\n\t\t{\"10000000000000\", 6, \"10000000000000.00000\"},\n\t\t{\"1000000000000\", 7, \"1000000000000.000000\"},\n\t\t{\"1\", 19, \"1.000000000000000000\"},\n\t\t{\"0\", 20, \"0.0000000000000000000\"},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\tgot := d.Rescale(tt.scale)\n\t\twant := MustParse(tt.want)\n\t\tif got != want {\n\t\t\tt.Errorf(\"%q.Rescale(%v) = %q, want %q\", d, tt.scale, got, want)\n\t\t}\n\t}\n}\n\nfunc TestDecimal_Quantize(t *testing.T) {\n\ttests := []struct {\n\t\td, e, want string\n\t}{\n\t\t{\"0\", \"0\", \"0\"},\n\t\t{\"0\", \"0.0\", \"0.0\"},\n\t\t{\"0.0\", \"0\", \"0\"},\n\t\t{\"0.0\", \"0.0\", \"0.0\"},\n\n\t\t{\"0.0078\", \"0.00001\", \"0.00780\"},\n\t\t{\"0.0078\", \"0.0001\", \"0.0078\"},\n\t\t{\"0.0078\", \"0.001\", \"0.008\"},\n\t\t{\"0.0078\", \"0.01\", \"0.01\"},\n\t\t{\"0.0078\", \"0.1\", \"0.0\"},\n\t\t{\"0.0078\", \"1\", \"0\"},\n\n\t\t{\"-0.0078\", \"0.00001\", \"-0.00780\"},\n\t\t{\"-0.0078\", \"0.0001\", \"-0.0078\"},\n\t\t{\"-0.0078\", \"0.001\", \"-0.008\"},\n\t\t{\"-0.0078\", \"0.01\", \"-0.01\"},\n\t\t{\"-0.0078\", \"0.1\", \"0.0\"},\n\t\t{\"-0.0078\", \"1\", \"0\"},\n\n\t\t{\"0.6666666\", \"0.1\", \"0.7\"},\n\t\t{\"9.9999\", \"1.00\", \"10.00\"},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\te := MustParse(tt.e)\n\t\tgot := d.Quantize(e)\n\t\twant := MustParse(tt.want)\n\t\tif got != want {\n\t\t\tt.Errorf(\"%q.Quantize(%q) = %q, want %q\", d, e, got, want)\n\t\t}\n\t}\n}\n\nfunc TestDecimal_Pad(t *testing.T) {\n\ttests := []struct {\n\t\td     string\n\t\tscale int\n\t\twant  string\n\t}{\n\t\t// Zeros\n\t\t{\"0\", 0, \"0\"},\n\t\t{\"0\", 1, \"0.0\"},\n\t\t{\"0\", 2, \"0.00\"},\n\t\t{\"0\", 19, \"0.0000000000000000000\"},\n\t\t{\"0\", 20, \"0.0000000000000000000\"},\n\t\t{\"0.000000000\", 0, \"0.000000000\"},\n\t\t{\"0.000000000\", 1, \"0.000000000\"},\n\t\t{\"0.000000000\", 2, \"0.000000000\"},\n\t\t{\"0.000000000\", 19, \"0.0000000000000000000\"},\n\t\t{\"0.000000000\", 20, \"0.0000000000000000000\"},\n\n\t\t// Tests from GDA\n\t\t{\"2.17\", 0, \"2.17\"},\n\t\t{\"2.17\", 1, \"2.17\"},\n\t\t{\"2.17\", 2, \"2.17\"},\n\t\t{\"2.17\", 9, \"2.170000000\"},\n\t\t{\"1.2345\", 2, \"1.2345\"},\n\t\t{\"1.2355\", 2, \"1.2355\"},\n\t\t{\"1.2345\", 9, \"1.234500000\"},\n\t\t{\"9.9999\", 2, \"9.9999\"},\n\t\t{\"0.0001\", 2, \"0.0001\"},\n\t\t{\"0.001\", 2, \"0.001\"},\n\t\t{\"0.009\", 2, \"0.009\"},\n\n\t\t// Negative scale\n\t\t{\"1000000000000000000\", -1, \"1000000000000000000\"},\n\n\t\t// Padding overflow\n\t\t{\"1000000000000000000\", 1, \"1000000000000000000\"},\n\t\t{\"100000000000000000\", 2, \"100000000000000000.0\"},\n\t\t{\"10000000000000000\", 3, \"10000000000000000.00\"},\n\t\t{\"1000000000000000\", 4, \"1000000000000000.000\"},\n\t\t{\"100000000000000\", 5, \"100000000000000.0000\"},\n\t\t{\"10000000000000\", 6, \"10000000000000.00000\"},\n\t\t{\"1000000000000\", 7, \"1000000000000.000000\"},\n\t\t{\"-0.0000000000032\", 63, \"-0.0000000000032000000\"},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\tgot := d.Pad(tt.scale)\n\t\twant := MustParse(tt.want)\n\t\tif got != want {\n\t\t\tt.Errorf(\"%q.Pad(%v) = %q, want %q\", d, tt.scale, got, want)\n\t\t}\n\t}\n}\n\nfunc TestDecimal_Round(t *testing.T) {\n\ttests := []struct {\n\t\td     string\n\t\tscale int\n\t\twant  string\n\t}{\n\t\t// Zeros\n\t\t{\"0\", -1, \"0\"},\n\t\t{\"0\", 0, \"0\"},\n\t\t{\"0\", 1, \"0\"},\n\t\t{\"0\", 2, \"0\"},\n\t\t{\"0\", 19, \"0\"},\n\t\t{\"0.0\", 1, \"0.0\"},\n\t\t{\"0.00\", 2, \"0.00\"},\n\t\t{\"0.000000000\", 19, \"0.000000000\"},\n\t\t{\"0.000000000\", 0, \"0\"},\n\t\t{\"0.000000000\", 1, \"0.0\"},\n\t\t{\"0.000000000\", 2, \"0.00\"},\n\n\t\t// Tests from GDA\n\t\t{\"2.17\", -1, \"2\"},\n\t\t{\"2.17\", 0, \"2\"},\n\t\t{\"2.17\", 1, \"2.2\"},\n\t\t{\"2.17\", 2, \"2.17\"},\n\t\t{\"2.17\", 9, \"2.17\"},\n\t\t{\"1.2345\", 2, \"1.23\"},\n\t\t{\"1.2355\", 2, \"1.24\"},\n\t\t{\"1.2345\", 9, \"1.2345\"},\n\t\t{\"9.9999\", 2, \"10.00\"},\n\t\t{\"0.0001\", 2, \"0.00\"},\n\t\t{\"0.001\", 2, \"0.00\"},\n\t\t{\"0.009\", 2, \"0.01\"},\n\n\t\t// Some extra tests\n\t\t{\"0.03\", 2, \"0.03\"},\n\t\t{\"0.02\", 2, \"0.02\"},\n\t\t{\"0.01\", 2, \"0.01\"},\n\t\t{\"0.00\", 2, \"0.00\"},\n\t\t{\"-0.01\", 2, \"-0.01\"},\n\t\t{\"-0.02\", 2, \"-0.02\"},\n\t\t{\"-0.03\", 2, \"-0.03\"},\n\t\t{\"0.0049\", 2, \"0.00\"},\n\t\t{\"0.0050\", 2, \"0.00\"},\n\t\t{\"0.0051\", 2, \"0.01\"},\n\t\t{\"0.0149\", 2, \"0.01\"},\n\t\t{\"0.0150\", 2, \"0.02\"},\n\t\t{\"0.0151\", 2, \"0.02\"},\n\t\t{\"0.0250\", 2, \"0.02\"},\n\t\t{\"0.0350\", 2, \"0.04\"},\n\t\t{\"-0.0049\", 2, \"0.00\"},\n\t\t{\"-0.0051\", 2, \"-0.01\"},\n\t\t{\"-0.0050\", 2, \"0.00\"},\n\t\t{\"-0.0149\", 2, \"-0.01\"},\n\t\t{\"-0.0151\", 2, \"-0.02\"},\n\t\t{\"-0.0150\", 2, \"-0.02\"},\n\t\t{\"-0.0250\", 2, \"-0.02\"},\n\t\t{\"-0.0350\", 2, \"-0.04\"},\n\t\t{\"3.0448\", 2, \"3.04\"},\n\t\t{\"3.0450\", 2, \"3.04\"},\n\t\t{\"3.0452\", 2, \"3.05\"},\n\t\t{\"3.0956\", 2, \"3.10\"},\n\n\t\t// Tests from Wikipedia\n\t\t{\"1.8\", 0, \"2\"},\n\t\t{\"1.5\", 0, \"2\"},\n\t\t{\"1.2\", 0, \"1\"},\n\t\t{\"0.8\", 0, \"1\"},\n\t\t{\"0.5\", 0, \"0\"},\n\t\t{\"0.2\", 0, \"0\"},\n\t\t{\"-0.2\", 0, \"0\"},\n\t\t{\"-0.5\", 0, \"0\"},\n\t\t{\"-0.8\", 0, \"-1\"},\n\t\t{\"-1.2\", 0, \"-1\"},\n\t\t{\"-1.5\", 0, \"-2\"},\n\t\t{\"-1.8\", 0, \"-2\"},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\tgot := d.Round(tt.scale)\n\t\twant := MustParse(tt.want)\n\t\tif got != want {\n\t\t\tt.Errorf(\"%q.Round(%v) = %q, want %q\", d, tt.scale, got, want)\n\t\t}\n\t}\n}\n\nfunc TestDecimal_Trunc(t *testing.T) {\n\ttests := []struct {\n\t\td     string\n\t\tscale int\n\t\twant  string\n\t}{\n\t\t// Zeros\n\t\t{\"0\", -1, \"0\"},\n\t\t{\"0\", 0, \"0\"},\n\t\t{\"0\", 1, \"0\"},\n\t\t{\"0\", 2, \"0\"},\n\t\t{\"0\", 19, \"0\"},\n\t\t{\"0.0\", 1, \"0.0\"},\n\t\t{\"0.00\", 2, \"0.00\"},\n\t\t{\"0.000000000\", 19, \"0.000000000\"},\n\t\t{\"0.000000000\", 0, \"0\"},\n\t\t{\"0.000000000\", 1, \"0.0\"},\n\t\t{\"0.000000000\", 2, \"0.00\"},\n\n\t\t// Tests from GDA\n\t\t{\"2.17\", 0, \"2\"},\n\t\t{\"2.17\", 1, \"2.1\"},\n\t\t{\"2.17\", 2, \"2.17\"},\n\t\t{\"2.17\", 9, \"2.17\"},\n\t\t{\"1.2345\", 2, \"1.23\"},\n\t\t{\"1.2355\", 2, \"1.23\"},\n\t\t{\"1.2345\", 9, \"1.2345\"},\n\t\t{\"9.9999\", 2, \"9.99\"},\n\t\t{\"0.0001\", 2, \"0.00\"},\n\t\t{\"0.001\", 2, \"0.00\"},\n\t\t{\"0.009\", 2, \"0.00\"},\n\n\t\t// Some extra tests\n\t\t{\"0.03\", 2, \"0.03\"},\n\t\t{\"0.02\", 2, \"0.02\"},\n\t\t{\"0.01\", 2, \"0.01\"},\n\t\t{\"0.00\", 2, \"0.00\"},\n\t\t{\"-0.01\", 2, \"-0.01\"},\n\t\t{\"-0.02\", 2, \"-0.02\"},\n\t\t{\"-0.03\", 2, \"-0.03\"},\n\t\t{\"0.0049\", 2, \"0.00\"},\n\t\t{\"0.0051\", 2, \"0.00\"},\n\t\t{\"0.0149\", 2, \"0.01\"},\n\t\t{\"0.0151\", 2, \"0.01\"},\n\t\t{\"-0.0049\", 2, \"0.00\"},\n\t\t{\"-0.0051\", 2, \"-0.00\"},\n\t\t{\"-0.0149\", 2, \"-0.01\"},\n\t\t{\"-0.0151\", 2, \"-0.01\"},\n\t\t{\"0.0050\", 2, \"0.00\"},\n\t\t{\"0.0150\", 2, \"0.01\"},\n\t\t{\"0.0250\", 2, \"0.02\"},\n\t\t{\"0.0350\", 2, \"0.03\"},\n\t\t{\"-0.0050\", 2, \"0.00\"},\n\t\t{\"-0.0150\", 2, \"-0.01\"},\n\t\t{\"-0.0250\", 2, \"-0.02\"},\n\t\t{\"-0.0350\", 2, \"-0.03\"},\n\t\t{\"3.0448\", 2, \"3.04\"},\n\t\t{\"3.0450\", 2, \"3.04\"},\n\t\t{\"3.0452\", 2, \"3.04\"},\n\t\t{\"3.0956\", 2, \"3.09\"},\n\n\t\t// Tests from Wikipedia\n\t\t{\"1.8\", 0, \"1\"},\n\t\t{\"1.5\", 0, \"1\"},\n\t\t{\"1.2\", 0, \"1\"},\n\t\t{\"0.8\", 0, \"0\"},\n\t\t{\"0.5\", 0, \"0\"},\n\t\t{\"0.2\", 0, \"0\"},\n\t\t{\"-0.2\", 0, \"0\"},\n\t\t{\"-0.5\", 0, \"0\"},\n\t\t{\"-0.8\", 0, \"0\"},\n\t\t{\"-1.2\", 0, \"-1\"},\n\t\t{\"-1.5\", 0, \"-1\"},\n\t\t{\"-1.8\", 0, \"-1\"},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\tgot := d.Trunc(tt.scale)\n\t\twant := MustParse(tt.want)\n\t\tif got != want {\n\t\t\tt.Errorf(\"%q.Trunc(%v) = %q, want %q\", d, tt.scale, got, want)\n\t\t}\n\t}\n}\n\nfunc TestDecimal_Ceil(t *testing.T) {\n\ttests := []struct {\n\t\td     string\n\t\tscale int\n\t\twant  string\n\t}{\n\t\t// Zeros\n\t\t{\"0\", -1, \"0\"},\n\t\t{\"0\", 0, \"0\"},\n\t\t{\"0\", 1, \"0\"},\n\t\t{\"0\", 2, \"0\"},\n\t\t{\"0\", 19, \"0\"},\n\t\t{\"0.0\", 1, \"0.0\"},\n\t\t{\"0.00\", 2, \"0.00\"},\n\t\t{\"0.000000000\", 19, \"0.000000000\"},\n\t\t{\"0.000000000\", 0, \"0\"},\n\t\t{\"0.000000000\", 1, \"0.0\"},\n\t\t{\"0.000000000\", 2, \"0.00\"},\n\n\t\t// Tests from GDA\n\t\t{\"2.17\", 0, \"3\"},\n\t\t{\"2.17\", 1, \"2.2\"},\n\t\t{\"2.17\", 2, \"2.17\"},\n\t\t{\"2.17\", 9, \"2.17\"},\n\t\t{\"1.2345\", 2, \"1.24\"},\n\t\t{\"1.2355\", 2, \"1.24\"},\n\t\t{\"1.2345\", 9, \"1.2345\"},\n\t\t{\"9.9999\", 2, \"10.00\"},\n\t\t{\"0.0001\", 2, \"0.01\"},\n\t\t{\"0.001\", 2, \"0.01\"},\n\t\t{\"0.009\", 2, \"0.01\"},\n\t\t{\"-2.17\", 0, \"-2\"},\n\t\t{\"-2.17\", 1, \"-2.1\"},\n\t\t{\"-2.17\", 2, \"-2.17\"},\n\t\t{\"-2.17\", 9, \"-2.17\"},\n\t\t{\"-1.2345\", 2, \"-1.23\"},\n\t\t{\"-1.2355\", 2, \"-1.23\"},\n\t\t{\"-1.2345\", 9, \"-1.2345\"},\n\t\t{\"-9.9999\", 2, \"-9.99\"},\n\t\t{\"-0.0001\", 2, \"0.00\"},\n\t\t{\"-0.001\", 2, \"0.00\"},\n\t\t{\"-0.009\", 2, \"0.00\"},\n\n\t\t// Some extra tests\n\t\t{\"0.03\", 2, \"0.03\"},\n\t\t{\"0.02\", 2, \"0.02\"},\n\t\t{\"0.01\", 2, \"0.01\"},\n\t\t{\"0.00\", 2, \"0.00\"},\n\t\t{\"-0.01\", 2, \"-0.01\"},\n\t\t{\"-0.02\", 2, \"-0.02\"},\n\t\t{\"-0.03\", 2, \"-0.03\"},\n\t\t{\"0.0049\", 2, \"0.01\"},\n\t\t{\"0.0051\", 2, \"0.01\"},\n\t\t{\"0.0149\", 2, \"0.02\"},\n\t\t{\"0.0151\", 2, \"0.02\"},\n\t\t{\"-0.0049\", 2, \"0.00\"},\n\t\t{\"-0.0051\", 2, \"0.00\"},\n\t\t{\"-0.0149\", 2, \"-0.01\"},\n\t\t{\"-0.0151\", 2, \"-0.01\"},\n\t\t{\"0.0050\", 2, \"0.01\"},\n\t\t{\"0.0150\", 2, \"0.02\"},\n\t\t{\"0.0250\", 2, \"0.03\"},\n\t\t{\"0.0350\", 2, \"0.04\"},\n\t\t{\"-0.0050\", 2, \"0.00\"},\n\t\t{\"-0.0150\", 2, \"-0.01\"},\n\t\t{\"-0.0250\", 2, \"-0.02\"},\n\t\t{\"-0.0350\", 2, \"-0.03\"},\n\t\t{\"3.0448\", 2, \"3.05\"},\n\t\t{\"3.0450\", 2, \"3.05\"},\n\t\t{\"3.0452\", 2, \"3.05\"},\n\t\t{\"3.0956\", 2, \"3.10\"},\n\n\t\t// Tests from Wikipedia\n\t\t{\"1.8\", 0, \"2\"},\n\t\t{\"1.5\", 0, \"2\"},\n\t\t{\"1.2\", 0, \"2\"},\n\t\t{\"0.8\", 0, \"1\"},\n\t\t{\"0.5\", 0, \"1\"},\n\t\t{\"0.2\", 0, \"1\"},\n\t\t{\"-0.2\", 0, \"0\"},\n\t\t{\"-0.5\", 0, \"0\"},\n\t\t{\"-0.8\", 0, \"0\"},\n\t\t{\"-1.2\", 0, \"-1\"},\n\t\t{\"-1.5\", 0, \"-1\"},\n\t\t{\"-1.8\", 0, \"-1\"},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\tgot := d.Ceil(tt.scale)\n\t\twant := MustParse(tt.want)\n\t\tif got != want {\n\t\t\tt.Errorf(\"%q.Ceil(%v) = %q, want %q\", d, tt.scale, got, want)\n\t\t}\n\t}\n}\n\nfunc TestDecimal_Floor(t *testing.T) {\n\ttests := []struct {\n\t\td     string\n\t\tscale int\n\t\twant  string\n\t}{\n\t\t// Zeros\n\t\t{\"0\", -1, \"0\"},\n\t\t{\"0\", 0, \"0\"},\n\t\t{\"0\", 1, \"0\"},\n\t\t{\"0\", 2, \"0\"},\n\t\t{\"0\", 19, \"0\"},\n\t\t{\"0.0\", 1, \"0.0\"},\n\t\t{\"0.00\", 2, \"0.00\"},\n\t\t{\"0.000000000\", 19, \"0.000000000\"},\n\t\t{\"0.000000000\", 0, \"0\"},\n\t\t{\"0.000000000\", 1, \"0.0\"},\n\t\t{\"0.000000000\", 2, \"0.00\"},\n\n\t\t// Tests from GDA\n\t\t{\"2.17\", 0, \"2\"},\n\t\t{\"2.17\", 1, \"2.1\"},\n\t\t{\"2.17\", 2, \"2.17\"},\n\t\t{\"2.17\", 9, \"2.17\"},\n\t\t{\"1.2345\", 2, \"1.23\"},\n\t\t{\"1.2355\", 2, \"1.23\"},\n\t\t{\"1.2345\", 9, \"1.2345\"},\n\t\t{\"9.9999\", 2, \"9.99\"},\n\t\t{\"0.0001\", 2, \"0.00\"},\n\t\t{\"0.001\", 2, \"0.00\"},\n\t\t{\"0.009\", 2, \"0.00\"},\n\t\t{\"-2.17\", 0, \"-3\"},\n\t\t{\"-2.17\", 1, \"-2.2\"},\n\t\t{\"-2.17\", 2, \"-2.17\"},\n\t\t{\"-2.17\", 9, \"-2.17\"},\n\t\t{\"-1.2345\", 2, \"-1.24\"},\n\t\t{\"-1.2355\", 2, \"-1.24\"},\n\t\t{\"-1.2345\", 9, \"-1.2345\"},\n\t\t{\"-9.9999\", 2, \"-10.00\"},\n\t\t{\"-0.0001\", 2, \"-0.01\"},\n\t\t{\"-0.001\", 2, \"-0.01\"},\n\t\t{\"-0.009\", 2, \"-0.01\"},\n\n\t\t// Some extra tests\n\t\t{\"0.03\", 2, \"0.03\"},\n\t\t{\"0.02\", 2, \"0.02\"},\n\t\t{\"0.01\", 2, \"0.01\"},\n\t\t{\"0.00\", 2, \"0.00\"},\n\t\t{\"-0.01\", 2, \"-0.01\"},\n\t\t{\"-0.02\", 2, \"-0.02\"},\n\t\t{\"-0.03\", 2, \"-0.03\"},\n\t\t{\"0.0049\", 2, \"0.00\"},\n\t\t{\"0.0051\", 2, \"0.00\"},\n\t\t{\"0.0149\", 2, \"0.01\"},\n\t\t{\"0.0151\", 2, \"0.01\"},\n\t\t{\"-0.0049\", 2, \"-0.01\"},\n\t\t{\"-0.0051\", 2, \"-0.01\"},\n\t\t{\"-0.0149\", 2, \"-0.02\"},\n\t\t{\"-0.0151\", 2, \"-0.02\"},\n\t\t{\"0.0050\", 2, \"0.00\"},\n\t\t{\"0.0150\", 2, \"0.01\"},\n\t\t{\"0.0250\", 2, \"0.02\"},\n\t\t{\"0.0350\", 2, \"0.03\"},\n\t\t{\"-0.0050\", 2, \"-0.01\"},\n\t\t{\"-0.0150\", 2, \"-0.02\"},\n\t\t{\"-0.0250\", 2, \"-0.03\"},\n\t\t{\"-0.0350\", 2, \"-0.04\"},\n\t\t{\"3.0448\", 2, \"3.04\"},\n\t\t{\"3.0450\", 2, \"3.04\"},\n\t\t{\"3.0452\", 2, \"3.04\"},\n\t\t{\"3.0956\", 2, \"3.09\"},\n\n\t\t// Tests from Wikipedia\n\t\t{\"1.8\", 0, \"1\"},\n\t\t{\"1.5\", 0, \"1\"},\n\t\t{\"1.2\", 0, \"1\"},\n\t\t{\"0.8\", 0, \"0\"},\n\t\t{\"0.5\", 0, \"0\"},\n\t\t{\"0.2\", 0, \"0\"},\n\t\t{\"-0.2\", 0, \"-1\"},\n\t\t{\"-0.5\", 0, \"-1\"},\n\t\t{\"-0.8\", 0, \"-1\"},\n\t\t{\"-1.2\", 0, \"-2\"},\n\t\t{\"-1.5\", 0, \"-2\"},\n\t\t{\"-1.8\", 0, \"-2\"},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\tgot := d.Floor(tt.scale)\n\t\twant := MustParse(tt.want)\n\t\tif got != want {\n\t\t\tt.Errorf(\"%q.Floor(%v) = %q, want %q\", d, tt.scale, got, want)\n\t\t}\n\t}\n}\n\nfunc TestDecimal_MinScale(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td    string\n\t\t\twant int\n\t\t}{\n\t\t\t{\"0\", 0},\n\t\t\t{\"0.0\", 0},\n\t\t\t{\"1\", 0},\n\t\t\t{\"1.000000000\", 0},\n\t\t\t{\"0.100000000\", 1},\n\t\t\t{\"0.010000000\", 2},\n\t\t\t{\"0.001000000\", 3},\n\t\t\t{\"0.000100000\", 4},\n\t\t\t{\"0.000010000\", 5},\n\t\t\t{\"0.000001000\", 6},\n\t\t\t{\"0.000000100\", 7},\n\t\t\t{\"0.000000010\", 8},\n\t\t\t{\"0.000000001\", 9},\n\t\t\t{\"0.000000000\", 0},\n\t\t\t{\"0.0000000000000000000\", 0},\n\t\t\t{\"0.1000000000000000000\", 1},\n\t\t\t{\"0.0000000000000000001\", 19},\n\t\t\t{\"0.9999999999999999999\", 19},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\tgot := d.MinScale()\n\t\t\tif got != tt.want {\n\t\t\t\tt.Errorf(\"%q.MinScale() = %v, want %v\", d, got, tt.want)\n\t\t\t}\n\t\t}\n\t})\n}\n\nfunc TestDecimal_Trim(t *testing.T) {\n\ttests := []struct {\n\t\td     string\n\t\tscale int\n\t\twant  string\n\t}{\n\t\t{\"0.000000\", 0, \"0\"},\n\t\t{\"0.000000\", 2, \"0.00\"},\n\t\t{\"0.000000\", 4, \"0.0000\"},\n\t\t{\"0.000000\", 6, \"0.000000\"},\n\t\t{\"0.000000\", 8, \"0.000000\"},\n\t\t{\"-10.00\", 0, \"-10\"},\n\t\t{\"10.00\", 0, \"10\"},\n\t\t{\"0.000001\", 0, \"0.000001\"},\n\t\t{\"0.0000010\", 0, \"0.000001\"},\n\t\t{\"-0.000001\", 0, \"-0.000001\"},\n\t\t{\"-0.0000010\", 0, \"-0.000001\"},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\tgot := d.Trim(tt.scale)\n\t\twant := MustParse(tt.want)\n\t\tif got != want {\n\t\t\tt.Errorf(\"%q.Trim(%v) = %q, want %q\", d, tt.scale, got, want)\n\t\t}\n\t}\n}\n\nfunc TestSum(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td    []string\n\t\t\twant string\n\t\t}{\n\t\t\t{[]string{\"0\"}, \"0\"},\n\t\t\t{[]string{\"1\"}, \"1\"},\n\t\t\t{[]string{\"1\", \"1\"}, \"2\"},\n\t\t\t{[]string{\"2\", \"3\"}, \"5\"},\n\t\t\t{[]string{\"5.75\", \"3.3\"}, \"9.05\"},\n\t\t\t{[]string{\"5\", \"-3\"}, \"2\"},\n\t\t\t{[]string{\"-5\", \"-3\"}, \"-8\"},\n\t\t\t{[]string{\"-7\", \"2.5\"}, \"-4.5\"},\n\t\t\t{[]string{\"0.7\", \"0.3\"}, \"1.0\"},\n\t\t\t{[]string{\"1.25\", \"1.25\"}, \"2.50\"},\n\t\t\t{[]string{\"1.1\", \"0.11\"}, \"1.21\"},\n\t\t\t{[]string{\"1.234567890\", \"1.000000000\"}, \"2.234567890\"},\n\t\t\t{[]string{\"1.234567890\", \"1.000000110\"}, \"2.234568000\"},\n\n\t\t\t{[]string{\"0.9998\", \"0.0000\"}, \"0.9998\"},\n\t\t\t{[]string{\"0.9998\", \"0.0001\"}, \"0.9999\"},\n\t\t\t{[]string{\"0.9998\", \"0.0002\"}, \"1.0000\"},\n\t\t\t{[]string{\"0.9998\", \"0.0003\"}, \"1.0001\"},\n\n\t\t\t{[]string{\"999999999999999999\", \"1\"}, \"1000000000000000000\"},\n\t\t\t{[]string{\"99999999999999999\", \"1\"}, \"100000000000000000\"},\n\t\t\t{[]string{\"9999999999999999\", \"1\"}, \"10000000000000000\"},\n\t\t\t{[]string{\"999999999999999\", \"1\"}, \"1000000000000000\"},\n\t\t\t{[]string{\"99999999999999\", \"1\"}, \"100000000000000\"},\n\t\t\t{[]string{\"9999999999999\", \"1\"}, \"10000000000000\"},\n\t\t\t{[]string{\"999999999999\", \"1\"}, \"1000000000000\"},\n\t\t\t{[]string{\"99999999999\", \"1\"}, \"100000000000\"},\n\t\t\t{[]string{\"9999999999\", \"1\"}, \"10000000000\"},\n\t\t\t{[]string{\"999999999\", \"1\"}, \"1000000000\"},\n\t\t\t{[]string{\"99999999\", \"1\"}, \"100000000\"},\n\t\t\t{[]string{\"9999999\", \"1\"}, \"10000000\"},\n\t\t\t{[]string{\"999999\", \"1\"}, \"1000000\"},\n\t\t\t{[]string{\"99999\", \"1\"}, \"100000\"},\n\t\t\t{[]string{\"9999\", \"1\"}, \"10000\"},\n\t\t\t{[]string{\"999\", \"1\"}, \"1000\"},\n\t\t\t{[]string{\"99\", \"1\"}, \"100\"},\n\t\t\t{[]string{\"9\", \"1\"}, \"10\"},\n\n\t\t\t{[]string{\"100000000000\", \"0.00000000\"}, \"100000000000.0000000\"},\n\t\t\t{[]string{\"100000000000\", \"0.00000001\"}, \"100000000000.0000000\"},\n\n\t\t\t{[]string{\"0.0\", \"0\"}, \"0.0\"},\n\t\t\t{[]string{\"0.00\", \"0\"}, \"0.00\"},\n\t\t\t{[]string{\"0.000\", \"0\"}, \"0.000\"},\n\t\t\t{[]string{\"0.0000000\", \"0\"}, \"0.0000000\"},\n\t\t\t{[]string{\"0\", \"0.0\"}, \"0.0\"},\n\t\t\t{[]string{\"0\", \"0.00\"}, \"0.00\"},\n\t\t\t{[]string{\"0\", \"0.000\"}, \"0.000\"},\n\t\t\t{[]string{\"0\", \"0.0000000\"}, \"0.0000000\"},\n\n\t\t\t{[]string{\"9999999999999999999\", \"0.4\"}, \"9999999999999999999\"},\n\t\t\t{[]string{\"-9999999999999999999\", \"-0.4\"}, \"-9999999999999999999\"},\n\t\t\t{[]string{\"1\", \"-9999999999999999999\"}, \"-9999999999999999998\"},\n\t\t\t{[]string{\"9999999999999999999\", \"-1\"}, \"9999999999999999998\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := make([]Decimal, len(tt.d))\n\t\t\tfor i, s := range tt.d {\n\t\t\t\td[i] = MustParse(s)\n\t\t\t}\n\t\t\tgot, err := Sum(d...)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"Sum(%v) failed: %v\", d, err)\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"Sum(%v) = %q, want %q\", d, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string][]string{\n\t\t\t\"no arguments\": {},\n\t\t\t\"overflow 1\":   {\"9999999999999999999\", \"1\"},\n\t\t\t\"overflow 2\":   {\"9999999999999999999\", \"0.6\"},\n\t\t\t\"overflow 3\":   {\"-9999999999999999999\", \"-1\"},\n\t\t\t\"overflow 4\":   {\"-9999999999999999999\", \"-0.6\"},\n\t\t}\n\t\tfor name, ss := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\td := make([]Decimal, len(ss))\n\t\t\t\tfor i, s := range ss {\n\t\t\t\t\td[i] = MustParse(s)\n\t\t\t\t}\n\t\t\t\t_, err := Sum(d...)\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"Sum(%v) did not fail\", d)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestDecimal_Add(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, e, want string\n\t\t}{\n\t\t\t{\"1\", \"1\", \"2\"},\n\t\t\t{\"2\", \"3\", \"5\"},\n\t\t\t{\"5.75\", \"3.3\", \"9.05\"},\n\t\t\t{\"5\", \"-3\", \"2\"},\n\t\t\t{\"-5\", \"-3\", \"-8\"},\n\t\t\t{\"-7\", \"2.5\", \"-4.5\"},\n\t\t\t{\"0.7\", \"0.3\", \"1.0\"},\n\t\t\t{\"1.25\", \"1.25\", \"2.50\"},\n\t\t\t{\"1.1\", \"0.11\", \"1.21\"},\n\t\t\t{\"1.234567890\", \"1.000000000\", \"2.234567890\"},\n\t\t\t{\"1.234567890\", \"1.000000110\", \"2.234568000\"},\n\n\t\t\t{\"0.9998\", \"0.0000\", \"0.9998\"},\n\t\t\t{\"0.9998\", \"0.0001\", \"0.9999\"},\n\t\t\t{\"0.9998\", \"0.0002\", \"1.0000\"},\n\t\t\t{\"0.9998\", \"0.0003\", \"1.0001\"},\n\n\t\t\t{\"999999999999999999\", \"1\", \"1000000000000000000\"},\n\t\t\t{\"99999999999999999\", \"1\", \"100000000000000000\"},\n\t\t\t{\"9999999999999999\", \"1\", \"10000000000000000\"},\n\t\t\t{\"999999999999999\", \"1\", \"1000000000000000\"},\n\t\t\t{\"99999999999999\", \"1\", \"100000000000000\"},\n\t\t\t{\"9999999999999\", \"1\", \"10000000000000\"},\n\t\t\t{\"999999999999\", \"1\", \"1000000000000\"},\n\t\t\t{\"99999999999\", \"1\", \"100000000000\"},\n\t\t\t{\"9999999999\", \"1\", \"10000000000\"},\n\t\t\t{\"999999999\", \"1\", \"1000000000\"},\n\t\t\t{\"99999999\", \"1\", \"100000000\"},\n\t\t\t{\"9999999\", \"1\", \"10000000\"},\n\t\t\t{\"999999\", \"1\", \"1000000\"},\n\t\t\t{\"99999\", \"1\", \"100000\"},\n\t\t\t{\"9999\", \"1\", \"10000\"},\n\t\t\t{\"999\", \"1\", \"1000\"},\n\t\t\t{\"99\", \"1\", \"100\"},\n\t\t\t{\"9\", \"1\", \"10\"},\n\n\t\t\t{\"100000000000\", \"0.00000000\", \"100000000000.0000000\"},\n\t\t\t{\"100000000000\", \"0.00000001\", \"100000000000.0000000\"},\n\n\t\t\t{\"0.0\", \"0\", \"0.0\"},\n\t\t\t{\"0.00\", \"0\", \"0.00\"},\n\t\t\t{\"0.000\", \"0\", \"0.000\"},\n\t\t\t{\"0.0000000\", \"0\", \"0.0000000\"},\n\t\t\t{\"0\", \"0.0\", \"0.0\"},\n\t\t\t{\"0\", \"0.00\", \"0.00\"},\n\t\t\t{\"0\", \"0.000\", \"0.000\"},\n\t\t\t{\"0\", \"0.0000000\", \"0.0000000\"},\n\n\t\t\t{\"9999999999999999999\", \"0.4\", \"9999999999999999999\"},\n\t\t\t{\"-9999999999999999999\", \"-0.4\", \"-9999999999999999999\"},\n\t\t\t{\"1\", \"-9999999999999999999\", \"-9999999999999999998\"},\n\t\t\t{\"9999999999999999999\", \"-1\", \"9999999999999999998\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\te := MustParse(tt.e)\n\t\t\tgot, err := d.Add(e)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.Add(%q) failed: %v\", d, e, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"%q.Add(%q) = %q, want %q\", d, e, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]struct {\n\t\t\td, e  string\n\t\t\tscale int\n\t\t}{\n\t\t\t\"overflow 1\": {\"9999999999999999999\", \"1\", 0},\n\t\t\t\"overflow 2\": {\"9999999999999999999\", \"0.6\", 0},\n\t\t\t\"overflow 3\": {\"-9999999999999999999\", \"-1\", 0},\n\t\t\t\"overflow 4\": {\"-9999999999999999999\", \"-0.6\", 0},\n\t\t\t\"scale 1\":    {\"1\", \"1\", MaxScale},\n\t\t\t\"scale 2\":    {\"0\", \"0\", MaxScale + 1},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\te := MustParse(tt.e)\n\t\t\t_, err := d.AddExact(e, tt.scale)\n\t\t\tif err == nil {\n\t\t\t\tt.Errorf(\"%q.AddExact(%q, %v) did not fail\", d, e, tt.scale)\n\t\t\t}\n\t\t}\n\t})\n}\n\nfunc TestDecimal_Sub(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, e, want string\n\t\t}{\n\t\t\t// Signs\n\t\t\t{\"5\", \"3\", \"2\"},\n\t\t\t{\"3\", \"5\", \"-2\"},\n\t\t\t{\"-5\", \"-3\", \"-2\"},\n\t\t\t{\"-3\", \"-5\", \"2\"},\n\t\t\t{\"-5\", \"3\", \"-8\"},\n\t\t\t{\"-3\", \"5\", \"-8\"},\n\t\t\t{\"5\", \"-3\", \"8\"},\n\t\t\t{\"3\", \"-5\", \"8\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\te := MustParse(tt.e)\n\t\t\tgot, err := d.Sub(e)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.Sub(%q) failed: %v\", d, e, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"%q.Sub(%q) = %q, want %q\", d, e, got, want)\n\t\t\t}\n\t\t}\n\t})\n}\n\nfunc TestDecimal_SubAbs(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, e, want string\n\t\t}{\n\t\t\t// Signs\n\t\t\t{\"5\", \"3\", \"2\"},\n\t\t\t{\"3\", \"5\", \"2\"},\n\t\t\t{\"-5\", \"-3\", \"2\"},\n\t\t\t{\"-3\", \"-5\", \"2\"},\n\t\t\t{\"-5\", \"3\", \"8\"},\n\t\t\t{\"-3\", \"5\", \"8\"},\n\t\t\t{\"5\", \"-3\", \"8\"},\n\t\t\t{\"3\", \"-5\", \"8\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\te := MustParse(tt.e)\n\t\t\tgot, err := d.SubAbs(e)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.SubAbs(%q) failed: %v\", d, e, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"%q.SubAbs(%q) = %q, want %q\", d, e, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]struct {\n\t\t\td, e string\n\t\t}{\n\t\t\t\"overflow 1\": {\"1\", \"-9999999999999999999\"},\n\t\t\t\"overflow 2\": {\"9999999999999999999\", \"-1\"},\n\t\t\t\"overflow 3\": {\"9999999999999999999\", \"-9999999999999999999\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\te := MustParse(tt.e)\n\t\t\t_, err := d.SubAbs(e)\n\t\t\tif err == nil {\n\t\t\t\tt.Errorf(\"%q.SubAbs(%q) did not fail\", d, e)\n\t\t\t}\n\t\t}\n\t})\n}\n\nfunc TestProd(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td    []string\n\t\t\twant string\n\t\t}{\n\t\t\t{[]string{\"0\"}, \"0\"},\n\t\t\t{[]string{\"1\"}, \"1\"},\n\t\t\t{[]string{\"2\", \"2\"}, \"4\"},\n\t\t\t{[]string{\"2\", \"3\"}, \"6\"},\n\t\t\t{[]string{\"5\", \"1\"}, \"5\"},\n\t\t\t{[]string{\"5\", \"2\"}, \"10\"},\n\t\t\t{[]string{\"1.20\", \"2\"}, \"2.40\"},\n\t\t\t{[]string{\"1.20\", \"0\"}, \"0.00\"},\n\t\t\t{[]string{\"1.20\", \"-2\"}, \"-2.40\"},\n\t\t\t{[]string{\"-1.20\", \"2\"}, \"-2.40\"},\n\t\t\t{[]string{\"-1.20\", \"0\"}, \"0.00\"},\n\t\t\t{[]string{\"-1.20\", \"-2\"}, \"2.40\"},\n\t\t\t{[]string{\"5.09\", \"7.1\"}, \"36.139\"},\n\t\t\t{[]string{\"2.5\", \"4\"}, \"10.0\"},\n\t\t\t{[]string{\"2.50\", \"4\"}, \"10.00\"},\n\t\t\t{[]string{\"0.70\", \"1.05\"}, \"0.7350\"},\n\t\t\t{[]string{\"1.000000000\", \"1\"}, \"1.000000000\"},\n\t\t\t{[]string{\"1.23456789\", \"1.00000000\"}, \"1.2345678900000000\"},\n\t\t\t{[]string{\"1.000000000000000000\", \"1.000000000000000000\"}, \"1.000000000000000000\"},\n\t\t\t{[]string{\"1.000000000000000001\", \"1.000000000000000001\"}, \"1.000000000000000002\"},\n\t\t\t{[]string{\"9.999999999999999999\", \"9.999999999999999999\"}, \"99.99999999999999998\"},\n\t\t\t{[]string{\"0.0000000000000000001\", \"0.0000000000000000001\"}, \"0.0000000000000000000\"},\n\t\t\t{[]string{\"0.0000000000000000001\", \"0.9999999999999999999\"}, \"0.0000000000000000001\"},\n\t\t\t{[]string{\"0.0000000000000000003\", \"0.9999999999999999999\"}, \"0.0000000000000000003\"},\n\t\t\t{[]string{\"0.9999999999999999999\", \"0.9999999999999999999\"}, \"0.9999999999999999998\"},\n\t\t\t{[]string{\"0.9999999999999999999\", \"0.9999999999999999999\", \"0.9999999999999999999\"}, \"0.9999999999999999997\"},\n\t\t\t{[]string{\"6963.788300835654596\", \"0.001436\"}, \"10.00000000000000000\"},\n\n\t\t\t// Captured during fuzzing\n\t\t\t{[]string{\"92233720368547757.26\", \"0.0000000000000000002\"}, \"0.0184467440737095515\"},\n\t\t\t{[]string{\"9223372036854775.807\", \"-0.0000000000000000013\"}, \"-0.0119903836479112085\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := make([]Decimal, len(tt.d))\n\t\t\tfor i, s := range tt.d {\n\t\t\t\td[i] = MustParse(s)\n\t\t\t}\n\t\t\tgot, err := Prod(d...)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"Prod(%v) failed: %v\", d, err)\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"Prod(%v) = %q, want %q\", d, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string][]string{\n\t\t\t\"no arguments\": {},\n\t\t\t\"overflow 1\":   {\"10000000000\", \"1000000000\"},\n\t\t\t\"overflow 2\":   {\"1000000000000000000\", \"10\"},\n\t\t\t\"overflow 3\":   {\"4999999999999999995\", \"-2.000000000000000002\"},\n\t\t\t\"overflow 4\": {\n\t\t\t\t\"9999999999999999999\", \"9999999999999999999\",\n\t\t\t\t\"9999999999999999999\", \"9999999999999999999\",\n\t\t\t\t\"9999999999999999999\", \"9999999999999999999\",\n\t\t\t\t\"9999999999999999999\", \"9999999999999999999\",\n\t\t\t},\n\t\t}\n\t\tfor name, ss := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\td := make([]Decimal, len(ss))\n\t\t\t\tfor i, s := range ss {\n\t\t\t\t\td[i] = MustParse(s)\n\t\t\t\t}\n\t\t\t\t_, err := Prod(d...)\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"Prod(%v) did not fail\", d)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestMean(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td    []string\n\t\t\twant string\n\t\t}{\n\t\t\t{[]string{\"1\"}, \"1\"},\n\t\t\t{[]string{\"1\", \"1\"}, \"1\"},\n\t\t\t{[]string{\"2\", \"3\"}, \"2.5\"},\n\t\t\t{[]string{\"5.75\", \"3.3\"}, \"4.525\"},\n\t\t\t{[]string{\"5\", \"-3\"}, \"1\"},\n\t\t\t{[]string{\"-5\", \"-3\"}, \"-4\"},\n\t\t\t{[]string{\"-7\", \"2.5\"}, \"-2.25\"},\n\t\t\t{[]string{\"0.7\", \"0.3\"}, \"0.5\"},\n\t\t\t{[]string{\"1.25\", \"1.25\"}, \"1.25\"},\n\t\t\t{[]string{\"1.1\", \"0.11\"}, \"0.605\"},\n\t\t\t{[]string{\"1.234567890\", \"1.000000000\"}, \"1.117283945\"},\n\t\t\t{[]string{\"1.234567890\", \"1.000000110\"}, \"1.117284000\"},\n\n\t\t\t{[]string{\"0.9998\", \"0.0000\"}, \"0.4999\"},\n\t\t\t{[]string{\"0.9998\", \"0.0001\"}, \"0.49995\"},\n\t\t\t{[]string{\"0.9998\", \"0.0002\"}, \"0.5000\"},\n\t\t\t{[]string{\"0.9998\", \"0.0003\"}, \"0.50005\"},\n\n\t\t\t{[]string{\"999999999999999999\", \"1\"}, \"500000000000000000\"},\n\t\t\t{[]string{\"99999999999999999\", \"1\"}, \"50000000000000000\"},\n\t\t\t{[]string{\"9999999999999999\", \"1\"}, \"5000000000000000\"},\n\t\t\t{[]string{\"999999999999999\", \"1\"}, \"500000000000000\"},\n\t\t\t{[]string{\"99999999999999\", \"1\"}, \"50000000000000\"},\n\t\t\t{[]string{\"9999999999999\", \"1\"}, \"5000000000000\"},\n\t\t\t{[]string{\"999999999999\", \"1\"}, \"500000000000\"},\n\t\t\t{[]string{\"99999999999\", \"1\"}, \"50000000000\"},\n\t\t\t{[]string{\"9999999999\", \"1\"}, \"5000000000\"},\n\t\t\t{[]string{\"999999999\", \"1\"}, \"500000000\"},\n\t\t\t{[]string{\"99999999\", \"1\"}, \"50000000\"},\n\t\t\t{[]string{\"9999999\", \"1\"}, \"5000000\"},\n\t\t\t{[]string{\"999999\", \"1\"}, \"500000\"},\n\t\t\t{[]string{\"99999\", \"1\"}, \"50000\"},\n\t\t\t{[]string{\"9999\", \"1\"}, \"5000\"},\n\t\t\t{[]string{\"999\", \"1\"}, \"500\"},\n\t\t\t{[]string{\"99\", \"1\"}, \"50\"},\n\t\t\t{[]string{\"9\", \"1\"}, \"5\"},\n\n\t\t\t{[]string{\"100000000000\", \"0.00000000\"}, \"50000000000.00000000\"},\n\t\t\t{[]string{\"100000000000\", \"0.00000001\"}, \"50000000000.00000000\"},\n\n\t\t\t{[]string{\"0.0\", \"0\"}, \"0.0\"},\n\t\t\t{[]string{\"0.00\", \"0\"}, \"0.00\"},\n\t\t\t{[]string{\"0.000\", \"0\"}, \"0.000\"},\n\t\t\t{[]string{\"0.0000000\", \"0\"}, \"0.0000000\"},\n\t\t\t{[]string{\"0\", \"0.0\"}, \"0.0\"},\n\t\t\t{[]string{\"0\", \"0.00\"}, \"0.00\"},\n\t\t\t{[]string{\"0\", \"0.000\"}, \"0.000\"},\n\t\t\t{[]string{\"0\", \"0.0000000\"}, \"0.0000000\"},\n\n\t\t\t{[]string{\"9999999999999999999\", \"0.4\"}, \"5000000000000000000\"},\n\t\t\t{[]string{\"-9999999999999999999\", \"-0.4\"}, \"-5000000000000000000\"},\n\t\t\t{[]string{\"1\", \"-9999999999999999999\"}, \"-4999999999999999999\"},\n\t\t\t{[]string{\"9999999999999999999\", \"-1\"}, \"4999999999999999999\"},\n\n\t\t\t// Smallest and largest numbers\n\t\t\t{[]string{\"-0.0000000000000000001\", \"-0.0000000000000000001\"}, \"-0.0000000000000000001\"},\n\t\t\t{[]string{\"0.0000000000000000001\", \"0.0000000000000000001\"}, \"0.0000000000000000001\"},\n\t\t\t{[]string{\"-9999999999999999999\", \"-9999999999999999999\"}, \"-9999999999999999999\"},\n\t\t\t{[]string{\"9999999999999999999\", \"9999999999999999999\"}, \"9999999999999999999\"},\n\n\t\t\t// Captured during fuzzing\n\t\t\t{[]string{\"9223372036854775807\", \"9223372036854775807\", \"922337203685477580.7\"}, \"6456360425798343065\"},\n\t\t\t{[]string{\"922.3372036854775807\", \"2\", \"-3000000000\"}, \"-999999691.8875987715\"},\n\t\t\t{[]string{\"0.5\", \"0.3\", \"0.2\"}, \"0.3333333333333333333\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := make([]Decimal, len(tt.d))\n\t\t\tfor i, s := range tt.d {\n\t\t\t\td[i] = MustParse(s)\n\t\t\t}\n\t\t\tgot, err := Mean(d...)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"Mean(%v) failed: %v\", d, err)\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"Mean(%v) = %q, want %q\", d, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string][]string{\n\t\t\t\"no arguments\": {},\n\t\t}\n\t\tfor name, ss := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\td := make([]Decimal, len(ss))\n\t\t\t\tfor i, s := range ss {\n\t\t\t\t\td[i] = MustParse(s)\n\t\t\t\t}\n\t\t\t\t_, err := Mean(d...)\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"Mean(%v) did not fail\", d)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestDecimal_Mul(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, e, want string\n\t\t}{\n\t\t\t{\"2\", \"2\", \"4\"},\n\t\t\t{\"2\", \"3\", \"6\"},\n\t\t\t{\"5\", \"1\", \"5\"},\n\t\t\t{\"5\", \"2\", \"10\"},\n\t\t\t{\"1.20\", \"2\", \"2.40\"},\n\t\t\t{\"1.20\", \"0\", \"0.00\"},\n\t\t\t{\"1.20\", \"-2\", \"-2.40\"},\n\t\t\t{\"-1.20\", \"2\", \"-2.40\"},\n\t\t\t{\"-1.20\", \"0\", \"0.00\"},\n\t\t\t{\"-1.20\", \"-2\", \"2.40\"},\n\t\t\t{\"5.09\", \"7.1\", \"36.139\"},\n\t\t\t{\"2.5\", \"4\", \"10.0\"},\n\t\t\t{\"2.50\", \"4\", \"10.00\"},\n\t\t\t{\"0.70\", \"1.05\", \"0.7350\"},\n\t\t\t{\"1.000000000\", \"1\", \"1.000000000\"},\n\t\t\t{\"1.23456789\", \"1.00000000\", \"1.2345678900000000\"},\n\t\t\t{\"1.000000000000000000\", \"1.000000000000000000\", \"1.000000000000000000\"},\n\t\t\t{\"1.000000000000000001\", \"1.000000000000000001\", \"1.000000000000000002\"},\n\t\t\t{\"9.999999999999999999\", \"9.999999999999999999\", \"99.99999999999999998\"},\n\t\t\t{\"0.0000000000000000001\", \"0.0000000000000000001\", \"0.0000000000000000000\"},\n\t\t\t{\"0.0000000000000000001\", \"0.9999999999999999999\", \"0.0000000000000000001\"},\n\t\t\t{\"0.0000000000000000003\", \"0.9999999999999999999\", \"0.0000000000000000003\"},\n\t\t\t{\"0.9999999999999999999\", \"0.9999999999999999999\", \"0.9999999999999999998\"},\n\t\t\t{\"6963.788300835654596\", \"0.001436\", \"10.00000000000000000\"},\n\n\t\t\t// Captured during fuzzing\n\t\t\t{\"92233720368547757.26\", \"0.0000000000000000002\", \"0.0184467440737095515\"},\n\t\t\t{\"9223372036854775.807\", \"-0.0000000000000000013\", \"-0.0119903836479112085\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\te := MustParse(tt.e)\n\t\t\tgot, err := d.Mul(e)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.Mul(%q) failed: %v\", d, e, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"%q.Mul(%q) = %q, want %q\", d, e, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]struct {\n\t\t\td, e  string\n\t\t\tscale int\n\t\t}{\n\t\t\t\"overflow 1\": {\"10000000000\", \"1000000000\", 0},\n\t\t\t\"overflow 2\": {\"1000000000000000000\", \"10\", 0},\n\t\t\t\"overflow 3\": {\"4999999999999999995\", \"-2.000000000000000002\", 0},\n\t\t\t\"scale 1\":    {\"1\", \"1\", MaxScale},\n\t\t\t\"scale 2\":    {\"0\", \"0\", MaxScale + 1},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\te := MustParse(tt.e)\n\t\t\t_, err := d.MulExact(e, tt.scale)\n\t\t\tif err == nil {\n\t\t\t\tt.Errorf(\"%q.MulExact(%q, %v) did not fail\", d, e, tt.scale)\n\t\t\t}\n\t\t}\n\t})\n}\n\nfunc TestDecimal_AddMul(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, e, f, want string\n\t\t}{\n\t\t\t// Signs\n\t\t\t{\"4\", \"2\", \"3\", \"10\"},\n\t\t\t{\"-4\", \"2\", \"3\", \"2\"},\n\t\t\t{\"4\", \"2\", \"-3\", \"-2\"},\n\t\t\t{\"-4\", \"2\", \"-3\", \"-10\"},\n\t\t\t{\"4\", \"-2\", \"3\", \"-2\"},\n\t\t\t{\"-4\", \"-2\", \"3\", \"-10\"},\n\t\t\t{\"4\", \"-2\", \"-3\", \"10\"},\n\t\t\t{\"-4\", \"-2\", \"-3\", \"2\"},\n\n\t\t\t// Addition tests\n\t\t\t{\"1\", \"1\", \"1\", \"2\"},\n\t\t\t{\"3\", \"1\", \"2\", \"5\"},\n\t\t\t{\"3.3\", \"1\", \"5.75\", \"9.05\"},\n\t\t\t{\"-3\", \"1\", \"5\", \"2\"},\n\t\t\t{\"-3\", \"1\", \"-5\", \"-8\"},\n\t\t\t{\"2.5\", \"1\", \"-7\", \"-4.5\"},\n\t\t\t{\"0.3\", \"1\", \"0.7\", \"1.0\"},\n\t\t\t{\"1.25\", \"1\", \"1.25\", \"2.50\"},\n\t\t\t{\"0.11\", \"1\", \"1.1\", \"1.21\"},\n\t\t\t{\"1.000000000\", \"1\", \"1.234567890\", \"2.234567890\"},\n\t\t\t{\"1.000000110\", \"1\", \"1.234567890\", \"2.234568000\"},\n\t\t\t{\"0.0000\", \"1\", \"0.9998\", \"0.9998\"},\n\t\t\t{\"0.0001\", \"1\", \"0.9998\", \"0.9999\"},\n\t\t\t{\"0.0002\", \"1\", \"0.9998\", \"1.0000\"},\n\t\t\t{\"0.0003\", \"1\", \"0.9998\", \"1.0001\"},\n\t\t\t{\"1\", \"1\", \"999999999999999999\", \"1000000000000000000\"},\n\t\t\t{\"1\", \"1\", \"99999999999999999\", \"100000000000000000\"},\n\t\t\t{\"1\", \"1\", \"9999999999999999\", \"10000000000000000\"},\n\t\t\t{\"1\", \"1\", \"999999999999999\", \"1000000000000000\"},\n\t\t\t{\"1\", \"1\", \"99999999999999\", \"100000000000000\"},\n\t\t\t{\"1\", \"1\", \"9999999999999\", \"10000000000000\"},\n\t\t\t{\"1\", \"1\", \"999999999999\", \"1000000000000\"},\n\t\t\t{\"1\", \"1\", \"99999999999\", \"100000000000\"},\n\t\t\t{\"1\", \"1\", \"9999999999\", \"10000000000\"},\n\t\t\t{\"1\", \"1\", \"999999999\", \"1000000000\"},\n\t\t\t{\"1\", \"1\", \"99999999\", \"100000000\"},\n\t\t\t{\"1\", \"1\", \"9999999\", \"10000000\"},\n\t\t\t{\"1\", \"1\", \"999999\", \"1000000\"},\n\t\t\t{\"1\", \"1\", \"99999\", \"100000\"},\n\t\t\t{\"1\", \"1\", \"9999\", \"10000\"},\n\t\t\t{\"1\", \"1\", \"999\", \"1000\"},\n\t\t\t{\"1\", \"1\", \"99\", \"100\"},\n\t\t\t{\"1\", \"1\", \"9\", \"10\"},\n\t\t\t{\"0.00000000\", \"1\", \"100000000000\", \"100000000000.0000000\"},\n\t\t\t{\"0.00000001\", \"1\", \"100000000000\", \"100000000000.0000000\"},\n\t\t\t{\"0\", \"1\", \"0.0\", \"0.0\"},\n\t\t\t{\"0\", \"1\", \"0.00\", \"0.00\"},\n\t\t\t{\"0\", \"1\", \"0.000\", \"0.000\"},\n\t\t\t{\"0\", \"1\", \"0.0000000\", \"0.0000000\"},\n\t\t\t{\"0.0\", \"1\", \"0\", \"0.0\"},\n\t\t\t{\"0.00\", \"1\", \"0\", \"0.00\"},\n\t\t\t{\"0.000\", \"1\", \"0\", \"0.000\"},\n\t\t\t{\"0.0000000\", \"1\", \"0\", \"0.0000000\"},\n\t\t\t{\"0.4\", \"1\", \"9999999999999999999\", \"9999999999999999999\"},\n\t\t\t{\"-0.4\", \"1\", \"-9999999999999999999\", \"-9999999999999999999\"},\n\t\t\t{\"-9999999999999999999\", \"1\", \"1\", \"-9999999999999999998\"},\n\t\t\t{\"-1\", \"1\", \"9999999999999999999\", \"9999999999999999998\"},\n\n\t\t\t// Multiplication tests\n\t\t\t{\"0\", \"2\", \"2\", \"4\"},\n\t\t\t{\"0\", \"2\", \"3\", \"6\"},\n\t\t\t{\"0\", \"5\", \"1\", \"5\"},\n\t\t\t{\"0\", \"5\", \"2\", \"10\"},\n\t\t\t{\"0\", \"1.20\", \"2\", \"2.40\"},\n\t\t\t{\"0\", \"1.20\", \"0\", \"0.00\"},\n\t\t\t{\"0\", \"1.20\", \"-2\", \"-2.40\"},\n\t\t\t{\"0\", \"-1.20\", \"2\", \"-2.40\"},\n\t\t\t{\"0\", \"-1.20\", \"0\", \"0.00\"},\n\t\t\t{\"0\", \"-1.20\", \"-2\", \"2.40\"},\n\t\t\t{\"0\", \"5.09\", \"7.1\", \"36.139\"},\n\t\t\t{\"0\", \"2.5\", \"4\", \"10.0\"},\n\t\t\t{\"0\", \"2.50\", \"4\", \"10.00\"},\n\t\t\t{\"0\", \"0.70\", \"1.05\", \"0.7350\"},\n\t\t\t{\"0\", \"1.000000000\", \"1\", \"1.000000000\"},\n\t\t\t{\"0\", \"1.23456789\", \"1.00000000\", \"1.2345678900000000\"},\n\t\t\t{\"0\", \"1.000000000000000000\", \"1.000000000000000000\", \"1.000000000000000000\"},\n\t\t\t{\"0\", \"1.000000000000000001\", \"1.000000000000000001\", \"1.000000000000000002\"},\n\t\t\t{\"0\", \"9.999999999999999999\", \"9.999999999999999999\", \"99.99999999999999998\"},\n\t\t\t{\"0\", \"0.0000000000000000001\", \"0.0000000000000000001\", \"0.0000000000000000000\"},\n\t\t\t{\"0\", \"0.0000000000000000001\", \"0.9999999999999999999\", \"0.0000000000000000001\"},\n\t\t\t{\"0\", \"0.0000000000000000003\", \"0.9999999999999999999\", \"0.0000000000000000003\"},\n\t\t\t{\"0\", \"0.9999999999999999999\", \"0.9999999999999999999\", \"0.9999999999999999998\"},\n\t\t\t{\"0\", \"6963.788300835654596\", \"0.001436\", \"10.00000000000000000\"},\n\n\t\t\t// Captured during fuzzing\n\t\t\t{\"0.0000000000000000121\", \"0.0000000000000000127\", \"12.5\", \"0.0000000000000001708\"},\n\t\t\t{\"-9.3\", \"0.0000000203\", \"-0.0000000116\", \"-9.300000000000000235\"},\n\t\t\t{\"5.8\", \"-0.0000000231\", \"0.0000000166\", \"5.799999999999999617\"},\n\n\t\t\t// Tests from GDA\n\t\t\t{\"2593183.42371\", \"27583489.6645\", \"2582471078.04\", \"71233564292579696.34\"},\n\t\t\t{\"2032.013252\", \"24280.355566\", \"939577.397653\", \"22813275328.80506589\"},\n\t\t\t{\"137903.517909\", \"7848976432\", \"-2586831.2281\", \"-20303977342780612.62\"},\n\t\t\t{\"339337.123410\", \"56890.388731\", \"35872030.4255\", \"2040774094814.077745\"},\n\t\t\t{\"5073392.31638\", \"7533543.57445\", \"360317763928\", \"2714469575205049785\"},\n\t\t\t{\"894450638.442\", \"437484.00601\", \"598906432790\", \"262011986336578659.5\"},\n\t\t\t{\"153127.446727\", \"203258304486\", \"-8628278.8066\", \"-1753769320861850379\"},\n\t\t\t{\"178277.96377\", \"42560533.1774\", \"-3643605282.86\", \"-155073783526334663.6\"},\n\t\t}\n\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\te := MustParse(tt.e)\n\t\t\tf := MustParse(tt.f)\n\t\t\tgot, err := d.AddMul(e, f)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.AddMul(%q, %q) failed: %v\", d, e, f, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"%q.AddMul(%q, %q) = %q, want %q\", d, e, f, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]struct {\n\t\t\td, f, e string\n\t\t\tscale   int\n\t\t}{\n\t\t\t\"overflow 1\": {\"1\", \"1\", \"9999999999999999999\", 0},\n\t\t\t\"overflow 2\": {\"0.6\", \"1\", \"9999999999999999999\", 0},\n\t\t\t\"overflow 3\": {\"-1\", \"1\", \"-9999999999999999999\", 0},\n\t\t\t\"overflow 4\": {\"-0.6\", \"1\", \"-9999999999999999999\", 0},\n\t\t\t\"overflow 5\": {\"0\", \"10000000000\", \"1000000000\", 0},\n\t\t\t\"overflow 6\": {\"0\", \"1000000000000000000\", \"10\", 0},\n\t\t\t\"scale 1\":    {\"1\", \"1\", \"1\", MaxScale},\n\t\t\t\"scale 2\":    {\"0\", \"0\", \"0\", MaxScale + 1},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\te := MustParse(tt.e)\n\t\t\tf := MustParse(tt.f)\n\t\t\t_, err := d.AddMulExact(e, f, tt.scale)\n\t\t\tif err == nil {\n\t\t\t\tt.Errorf(\"%q.AddMulExact(%q, %q, %v) did not fail\", d, e, f, tt.scale)\n\t\t\t}\n\t\t}\n\t})\n}\n\nfunc TestDecimal_AddQuo(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, e, f, want string\n\t\t}{\n\t\t\t// Signs\n\t\t\t{\"3\", \"4\", \"2\", \"5\"},\n\t\t\t{\"3\", \"-4\", \"2\", \"1\"},\n\t\t\t{\"-3\", \"4\", \"2\", \"-1\"},\n\t\t\t{\"-3\", \"-4\", \"2\", \"-5\"},\n\t\t\t{\"3\", \"4\", \"-2\", \"1\"},\n\t\t\t{\"3\", \"-4\", \"-2\", \"5\"},\n\t\t\t{\"-3\", \"4\", \"-2\", \"-5\"},\n\t\t\t{\"-3\", \"-4\", \"-2\", \"-1\"},\n\n\t\t\t// Addition tests\n\t\t\t{\"1\", \"1\", \"1\", \"2\"},\n\t\t\t{\"3\", \"2\", \"1\", \"5\"},\n\t\t\t{\"3.3\", \"5.75\", \"1\", \"9.05\"},\n\t\t\t{\"-3\", \"5\", \"1\", \"2\"},\n\t\t\t{\"-3\", \"-5\", \"1\", \"-8\"},\n\t\t\t{\"2.5\", \"-7\", \"1\", \"-4.5\"},\n\t\t\t{\"0.3\", \"0.7\", \"1\", \"1.0\"},\n\t\t\t{\"1.25\", \"1.25\", \"1\", \"2.50\"},\n\t\t\t{\"0.11\", \"1.1\", \"1\", \"1.21\"},\n\t\t\t{\"1.000000000\", \"1.234567890\", \"1\", \"2.234567890\"},\n\t\t\t{\"1.000000110\", \"1.234567890\", \"1\", \"2.234568000\"},\n\t\t\t{\"0.0000\", \"0.9998\", \"1\", \"0.9998\"},\n\t\t\t{\"0.0001\", \"0.9998\", \"1\", \"0.9999\"},\n\t\t\t{\"0.0002\", \"0.9998\", \"1\", \"1.0000\"},\n\t\t\t{\"0.0003\", \"0.9998\", \"1\", \"1.0001\"},\n\t\t\t{\"1\", \"999999999999999999\", \"1\", \"1000000000000000000\"},\n\t\t\t{\"1\", \"99999999999999999\", \"1\", \"100000000000000000\"},\n\t\t\t{\"1\", \"9999999999999999\", \"1\", \"10000000000000000\"},\n\t\t\t{\"1\", \"999999999999999\", \"1\", \"1000000000000000\"},\n\t\t\t{\"1\", \"99999999999999\", \"1\", \"100000000000000\"},\n\t\t\t{\"1\", \"9999999999999\", \"1\", \"10000000000000\"},\n\t\t\t{\"1\", \"999999999999\", \"1\", \"1000000000000\"},\n\t\t\t{\"1\", \"99999999999\", \"1\", \"100000000000\"},\n\t\t\t{\"1\", \"9999999999\", \"1\", \"10000000000\"},\n\t\t\t{\"1\", \"999999999\", \"1\", \"1000000000\"},\n\t\t\t{\"1\", \"99999999\", \"1\", \"100000000\"},\n\t\t\t{\"1\", \"9999999\", \"1\", \"10000000\"},\n\t\t\t{\"1\", \"999999\", \"1\", \"1000000\"},\n\t\t\t{\"1\", \"99999\", \"1\", \"100000\"},\n\t\t\t{\"1\", \"9999\", \"1\", \"10000\"},\n\t\t\t{\"1\", \"999\", \"1\", \"1000\"},\n\t\t\t{\"1\", \"99\", \"1\", \"100\"},\n\t\t\t{\"1\", \"9\", \"1\", \"10\"},\n\t\t\t{\"0.00000000\", \"100000000000\", \"1\", \"100000000000.0000000\"},\n\t\t\t{\"0.00000001\", \"100000000000\", \"1\", \"100000000000.0000000\"},\n\t\t\t{\"0\", \"0.0\", \"1\", \"0.0\"},\n\t\t\t{\"0\", \"0.00\", \"1\", \"0.00\"},\n\t\t\t{\"0\", \"0.000\", \"1\", \"0.000\"},\n\t\t\t{\"0\", \"0.0000000\", \"1\", \"0.0000000\"},\n\t\t\t{\"0.0\", \"0\", \"1\", \"0.0\"},\n\t\t\t{\"0.00\", \"0\", \"1\", \"0.00\"},\n\t\t\t{\"0.000\", \"0\", \"1\", \"0.000\"},\n\t\t\t{\"0.0000000\", \"0\", \"1\", \"0.0000000\"},\n\t\t\t{\"0.4\", \"9999999999999999999\", \"1\", \"9999999999999999999\"},\n\t\t\t{\"-0.4\", \"-9999999999999999999\", \"1\", \"-9999999999999999999\"},\n\t\t\t{\"-9999999999999999999\", \"1\", \"1\", \"-9999999999999999998\"},\n\t\t\t{\"-1\", \"9999999999999999999\", \"1\", \"9999999999999999998\"},\n\n\t\t\t// Division tests\n\t\t\t{\"0\", \"9223372036854775807\", \"-9223372036854775808\", \"-0.9999999999999999999\"},\n\t\t\t{\"0\", \"0.000000000000000001\", \"20\", \"0.000000000000000000\"},\n\t\t\t{\"0\", \"105\", \"0.999999999999999990\", \"105.0000000000000011\"},\n\t\t\t{\"0\", \"0.05\", \"999999999999999954\", \"0.0000000000000000001\"},\n\t\t\t{\"0\", \"9.99999999999999998\", \"185\", \"0.0540540540540540539\"},\n\t\t\t{\"0\", \"7\", \"2.000000000000000002\", \"3.499999999999999997\"},\n\t\t\t{\"0\", \"0.000000009\", \"999999999999999999\", \"0.000000000\"},\n\t\t\t{\"0\", \"0.0000000000000000001\", \"9999999999999999999\", \"0.0000000000000000000\"},\n\t\t\t{\"0\", \"9999999999999999999\", \"2\", \"5000000000000000000\"},\n\t\t\t{\"0\", \"9999999999999999999\", \"5000000000000000000\", \"2\"},\n\n\t\t\t// Captured during fuzzing\n\t\t\t{\"47\", \"-126\", \"110\", \"45.85454545454545455\"},\n\t\t\t{\"-92\", \"94\", \"76\", \"-90.76315789473684211\"},\n\t\t\t{\"5\", \"-40\", \"139\", \"4.712230215827338129\"},\n\t\t\t{\"-3\", \"3\", \"0.9999999999999999999\", \"0.0000000000000000003\"},\n\t\t\t{\"-0.0000000000000000001\", \"1\", \"0.9999999999999999999\", \"1.000000000000000000\"},\n\t\t\t{\"0.00000000053\", \"4.3\", \"0.00000000071\", \"6056338028.169014085\"},\n\t\t\t{\"8.9\", \"0.0000000000082\", \"-0.000000110\", \"8.899925454545454545\"},\n\t\t\t{\"0.000000000000000\", \"0.9999999999999999940\", \"1\", \"0.9999999999999999940\"},\n\t\t}\n\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\te := MustParse(tt.e)\n\t\t\tf := MustParse(tt.f)\n\t\t\tgot, err := d.AddQuo(e, f)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.AddQuo(%q, %q) failed: %v\", d, e, f, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got.CmpTotal(want) != 0 {\n\t\t\t\tt.Errorf(\"%q.AddQuo(%q, %q) = %q, want %q\", d, e, f, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]struct {\n\t\t\td, e, f string\n\t\t\tscale   int\n\t\t}{\n\t\t\t\"overflow 1\": {\"9999999999999999999\", \"1\", \"1\", 0},\n\t\t\t\"overflow 2\": {\"9999999999999999999\", \"0.6\", \"1\", 0},\n\t\t\t\"overflow 3\": {\"-9999999999999999999\", \"-1\", \"1\", 0},\n\t\t\t\"overflow 4\": {\"-9999999999999999999\", \"-0.6\", \"1\", 0},\n\t\t\t\"overflow 5\": {\"0\", \"10000000000\", \"0.000000001\", 0},\n\t\t\t\"overflow 6\": {\"0\", \"1000000000000000000\", \"0.1\", 0},\n\t\t\t\"zero 1\":     {\"1\", \"1\", \"0\", 0},\n\t\t\t\"scale 1\":    {\"1\", \"1\", \"1\", MaxScale},\n\t\t\t\"scale 2\":    {\"0\", \"0\", \"1\", MaxScale + 1},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\te := MustParse(tt.e)\n\t\t\tf := MustParse(tt.f)\n\t\t\t_, err := d.AddQuoExact(e, f, tt.scale)\n\t\t\tif err == nil {\n\t\t\t\tt.Errorf(\"%q.AddQuoExact(%q, %q, %v) did not fail\", d, e, f, tt.scale)\n\t\t\t}\n\t\t}\n\t})\n}\n\nfunc TestDecimal_Pow(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, e, want string\n\t\t}{\n\t\t\t//////////////////////\n\t\t\t// Fractional Powers\n\t\t\t//////////////////////\n\n\t\t\t{\"0.0\", \"0.0\", \"1\"},\n\t\t\t{\"0.0\", \"0.5\", \"0\"},\n\n\t\t\t{\"4.0\", \"-0.5\", \"0.5000000000000000000\"},\n\t\t\t{\"4.0\", \"0.0\", \"1\"},\n\t\t\t{\"4.0\", \"0.5\", \"2.000000000000000000\"},\n\n\t\t\t{\"0.0000001\", \"0.0000001\", \"0.9999983881917338685\"},\n\t\t\t{\"0.003\", \"0.0000001\", \"0.9999994190858696993\"},\n\t\t\t{\"0.7\", \"0.0000001\", \"0.9999999643325062422\"},\n\t\t\t{\"1.2\", \"0.0000001\", \"1.000000018232155846\"},\n\t\t\t{\"71\", \"0.0000001\", \"1.000000426268078556\"},\n\t\t\t{\"9000000000\", \"0.0000001\", \"1.000002292051668175\"},\n\n\t\t\t{\"0.0000001\", \"0.003\", \"0.9527961640236518859\"},\n\t\t\t{\"0.003\", \"0.003\", \"0.9827235503366796915\"},\n\t\t\t{\"0.7\", \"0.003\", \"0.9989305474406207158\"},\n\t\t\t{\"1.2\", \"0.003\", \"1.000547114282833519\"},\n\t\t\t{\"71\", \"0.003\", \"1.012870156273545212\"},\n\t\t\t{\"9000000000\", \"0.003\", \"1.071180671278787089\"},\n\n\t\t\t{\"0.0000001\", \"0.7\", \"0.0000125892541179417\"},\n\t\t\t{\"0.003\", \"0.7\", \"0.0171389763028103005\"},\n\t\t\t{\"0.7\", \"0.7\", \"0.7790559126704490940\"},\n\t\t\t{\"1.2\", \"0.7\", \"1.136126977198888691\"},\n\t\t\t{\"71\", \"0.7\", \"19.76427300093869501\"},\n\t\t\t{\"9000000000\", \"0.7\", \"9289016.976853710315\"},\n\n\t\t\t{\"0.0000001\", \"1.2\", \"0.0000000039810717055\"},\n\t\t\t{\"0.003\", \"1.2\", \"0.0009387403933595694\"},\n\t\t\t{\"0.7\", \"1.2\", \"0.6518049405663863819\"},\n\t\t\t{\"1.2\", \"1.2\", \"1.244564747203977722\"},\n\t\t\t{\"71\", \"1.2\", \"166.5367244638552138\"},\n\t\t\t{\"9000000000\", \"1.2\", \"881233526124.8791107\"},\n\n\t\t\t// Natural numbers\n\t\t\t{\"10\", \"0.0000000000000000000\", \"1\"},\n\t\t\t{\"10\", \"0.3010299956639811952\", \"2.000000000000000000\"},\n\t\t\t{\"10\", \"0.4771212547196624373\", \"3.000000000000000000\"},\n\t\t\t{\"10\", \"0.6020599913279623904\", \"4.000000000000000000\"},\n\t\t\t{\"10\", \"0.6989700043360188048\", \"5.000000000000000000\"},\n\t\t\t{\"10\", \"0.7781512503836436325\", \"6.000000000000000000\"},\n\t\t\t{\"10\", \"0.8450980400142568307\", \"7.000000000000000000\"},\n\t\t\t{\"10\", \"0.9030899869919435856\", \"7.999999999999999999\"},\n\t\t\t{\"10\", \"0.9542425094393248746\", \"9.000000000000000000\"},\n\t\t\t{\"10\", \"1\", \"10\"},\n\t\t\t{\"10\", \"1.041392685158225041\", \"11.00000000000000001\"},\n\t\t\t{\"10\", \"1.079181246047624828\", \"12.00000000000000001\"},\n\t\t\t{\"10\", \"1.113943352306836769\", \"12.99999999999999999\"},\n\t\t\t{\"10\", \"1.146128035678238026\", \"14.00000000000000000\"},\n\t\t\t{\"10\", \"1.176091259055681242\", \"15.00000000000000000\"},\n\t\t\t{\"10\", \"1.204119982655924781\", \"16.00000000000000001\"},\n\t\t\t{\"10\", \"1.230448921378273929\", \"17.00000000000000002\"},\n\t\t\t{\"10\", \"1.255272505103306070\", \"18.00000000000000001\"},\n\t\t\t{\"10\", \"1.278753600952828962\", \"19.00000000000000002\"},\n\t\t\t{\"10\", \"1.301029995663981195\", \"19.99999999999999999\"},\n\n\t\t\t// e^e\n\t\t\t{E.String(), E.String(), \"15.15426224147926418\"},\n\n\t\t\t// Closer and closer to e\n\t\t\t{\"10\", \"0.4342944819032518275\", \"2.718281828459045234\"},\n\t\t\t{\"10\", \"0.4342944819032518276\", \"2.718281828459045235\"},\n\t\t\t{\"10\", \"0.4342944819032518277\", \"2.718281828459045236\"},\n\t\t\t{\"10\", \"0.4342944819032518278\", \"2.718281828459045236\"},\n\t\t\t{\"10\", \"0.4342944819032518279\", \"2.718281828459045237\"},\n\n\t\t\t// Closer and closer to 1000\n\t\t\t{\"10\", \"2.999999999999999998\", \"999.9999999999999954\"},\n\t\t\t{\"10\", \"2.999999999999999999\", \"999.9999999999999977\"},\n\t\t\t{\"10\", \"3\", \"1000\"},\n\t\t\t{\"10\", \"3.000000000000000001\", \"1000.000000000000002\"},\n\t\t\t{\"10\", \"3.000000000000000002\", \"1000.000000000000005\"},\n\n\t\t\t// Captured during fuzzing\n\t\t\t{\"1.000000000000000001\", \"9223372036854775807\", \"10131.16947077036074\"},\n\t\t\t{\"1.000000000000000001\", \"922337203685477580.7\", \"2.515161971551883079\"},\n\t\t\t{\"1.000000000000000001\", \"92233720368547758.07\", \"1.096621094818009214\"},\n\t\t\t{\"999999999.999999999\", \"-999999999.999999999\", \"0.0000000000000000000\"},\n\t\t\t{\"0.060\", \"0.999999999999999944\", \"0.0600000000000000095\"},\n\t\t\t{\"0.0000000091\", \"0.23\", \"0.0141442368531557249\"},\n\n\t\t\t/////////////////\n\t\t\t// Square Roots\n\t\t\t/////////////////\n\n\t\t\t// Zeros\n\t\t\t{\"0.00000000\", \"0.5\", \"0\"},\n\t\t\t{\"0.0000000\", \"0.5\", \"0\"},\n\t\t\t{\"0.000000\", \"0.5\", \"0\"},\n\t\t\t{\"0.00000\", \"0.5\", \"0\"},\n\t\t\t{\"0.0000\", \"0.5\", \"0\"},\n\t\t\t{\"0.000\", \"0.5\", \"0\"},\n\t\t\t{\"0.00\", \"0.5\", \"0\"},\n\t\t\t{\"0.0\", \"0.5\", \"0\"},\n\t\t\t{\"0\", \"0.5\", \"0\"},\n\n\t\t\t// Trailing zeros\n\t\t\t{\"0.010000000\", \"0.5\", \"0.1000000000000000000\"},\n\t\t\t{\"0.01000000\", \"0.5\", \"0.1000000000000000000\"},\n\t\t\t{\"0.0100000\", \"0.5\", \"0.1000000000000000000\"},\n\t\t\t{\"0.010000\", \"0.5\", \"0.1000000000000000000\"},\n\t\t\t{\"0.01000\", \"0.5\", \"0.1000000000000000000\"},\n\t\t\t{\"0.0100\", \"0.5\", \"0.1000000000000000000\"},\n\t\t\t{\"0.010\", \"0.5\", \"0.1000000000000000000\"},\n\t\t\t{\"0.01\", \"0.5\", \"0.1000000000000000000\"},\n\n\t\t\t// Powers of ten\n\t\t\t{\"0.00000001\", \"0.5\", \"0.0001000000000000000\"},\n\t\t\t{\"0.0000001\", \"0.5\", \"0.0003162277660168379\"},\n\t\t\t{\"0.000001\", \"0.5\", \"0.0010000000000000000\"},\n\t\t\t{\"0.00001\", \"0.5\", \"0.0031622776601683793\"},\n\t\t\t{\"0.0001\", \"0.5\", \"0.0100000000000000000\"},\n\t\t\t{\"0.001\", \"0.5\", \"0.0316227766016837933\"},\n\t\t\t{\"0.01\", \"0.5\", \"0.1000000000000000000\"},\n\t\t\t{\"0.1\", \"0.5\", \"0.3162277660168379332\"},\n\t\t\t{\"1\", \"0.5\", \"1.00000000000000000000\"},\n\t\t\t{\"10\", \"0.5\", \"3.162277660168379332\"},\n\t\t\t{\"100\", \"0.5\", \"10.00000000000000000\"},\n\t\t\t{\"1000\", \"0.5\", \"31.62277660168379332\"},\n\t\t\t{\"10000\", \"0.5\", \"100.0000000000000000\"},\n\t\t\t{\"100000\", \"0.5\", \"316.2277660168379332\"},\n\t\t\t{\"1000000\", \"0.5\", \"1000.000000000000000\"},\n\t\t\t{\"10000000\", \"0.5\", \"3162.277660168379332\"},\n\t\t\t{\"100000000\", \"0.5\", \"10000.00000000000000\"},\n\n\t\t\t// Natural numbers\n\t\t\t{\"0\", \"0.5\", \"0\"},\n\t\t\t{\"1\", \"0.5\", \"1.000000000000000000\"},\n\t\t\t{\"2\", \"0.5\", \"1.414213562373095049\"},\n\t\t\t{\"3\", \"0.5\", \"1.732050807568877294\"},\n\t\t\t{\"4\", \"0.5\", \"2.000000000000000000\"},\n\t\t\t{\"5\", \"0.5\", \"2.236067977499789696\"},\n\t\t\t{\"6\", \"0.5\", \"2.449489742783178098\"},\n\t\t\t{\"7\", \"0.5\", \"2.645751311064590591\"},\n\t\t\t{\"8\", \"0.5\", \"2.828427124746190098\"},\n\t\t\t{\"9\", \"0.5\", \"3.000000000000000000\"},\n\t\t\t{\"10\", \"0.5\", \"3.162277660168379332\"},\n\t\t\t{\"11\", \"0.5\", \"3.316624790355399849\"},\n\t\t\t{\"12\", \"0.5\", \"3.464101615137754587\"},\n\t\t\t{\"13\", \"0.5\", \"3.605551275463989293\"},\n\t\t\t{\"14\", \"0.5\", \"3.741657386773941386\"},\n\t\t\t{\"15\", \"0.5\", \"3.872983346207416885\"},\n\t\t\t{\"16\", \"0.5\", \"4.000000000000000000\"},\n\t\t\t{\"17\", \"0.5\", \"4.123105625617660550\"},\n\t\t\t{\"18\", \"0.5\", \"4.242640687119285146\"},\n\t\t\t{\"19\", \"0.5\", \"4.358898943540673552\"},\n\t\t\t{\"20\", \"0.5\", \"4.472135954999579393\"},\n\t\t\t{\"21\", \"0.5\", \"4.582575694955840007\"},\n\t\t\t{\"22\", \"0.5\", \"4.690415759823429555\"},\n\t\t\t{\"23\", \"0.5\", \"4.795831523312719542\"},\n\t\t\t{\"24\", \"0.5\", \"4.898979485566356196\"},\n\t\t\t{\"25\", \"0.5\", \"5.000000000000000000\"},\n\n\t\t\t// Well-known squares\n\t\t\t{\"1\", \"0.5\", \"1.000000000000000000\"},\n\t\t\t{\"4\", \"0.5\", \"2.000000000000000000\"},\n\t\t\t{\"9\", \"0.5\", \"3.000000000000000000\"},\n\t\t\t{\"16\", \"0.5\", \"4.000000000000000000\"},\n\t\t\t{\"25\", \"0.5\", \"5.000000000000000000\"},\n\t\t\t{\"36\", \"0.5\", \"6.000000000000000000\"},\n\t\t\t{\"49\", \"0.5\", \"7.000000000000000000\"},\n\t\t\t{\"64\", \"0.5\", \"8.000000000000000000\"},\n\t\t\t{\"81\", \"0.5\", \"9.000000000000000000\"},\n\t\t\t{\"100\", \"0.5\", \"10.00000000000000000\"},\n\t\t\t{\"121\", \"0.5\", \"11.00000000000000000\"},\n\t\t\t{\"144\", \"0.5\", \"12.00000000000000000\"},\n\t\t\t{\"169\", \"0.5\", \"13.00000000000000000\"},\n\t\t\t{\"256\", \"0.5\", \"16.00000000000000000\"},\n\t\t\t{\"1024\", \"0.5\", \"32.00000000000000000\"},\n\t\t\t{\"4096\", \"0.5\", \"64.00000000000000000\"},\n\n\t\t\t{\"0.01\", \"0.5\", \"0.1000000000000000000\"},\n\t\t\t{\"0.04\", \"0.5\", \"0.2000000000000000000\"},\n\t\t\t{\"0.09\", \"0.5\", \"0.3000000000000000000\"},\n\t\t\t{\"0.16\", \"0.5\", \"0.4000000000000000000\"},\n\t\t\t{\"0.25\", \"0.5\", \"0.5000000000000000000\"},\n\t\t\t{\"0.36\", \"0.5\", \"0.6000000000000000000\"},\n\t\t\t{\"0.49\", \"0.5\", \"0.7000000000000000000\"},\n\t\t\t{\"0.64\", \"0.5\", \"0.8000000000000000000\"},\n\t\t\t{\"0.81\", \"0.5\", \"0.9000000000000000000\"},\n\t\t\t{\"1.00\", \"0.5\", \"1.000000000000000000\"},\n\t\t\t{\"1.21\", \"0.5\", \"1.100000000000000000\"},\n\t\t\t{\"1.44\", \"0.5\", \"1.200000000000000000\"},\n\t\t\t{\"1.69\", \"0.5\", \"1.300000000000000000\"},\n\t\t\t{\"2.56\", \"0.5\", \"1.600000000000000000\"},\n\t\t\t{\"10.24\", \"0.5\", \"3.200000000000000000\"},\n\t\t\t{\"40.96\", \"0.5\", \"6.400000000000000000\"},\n\n\t\t\t// Smallest and largest numbers\n\t\t\t{\"0.0000000000000000001\", \"0.5\", \"0.0000000003162277660\"},\n\t\t\t{\"9999999999999999999\", \"0.5\", \"3162277660.168379332\"},\n\n\t\t\t// Captured during fuzzing\n\t\t\t{\"1.000000000000000063\", \"0.5\", \"1.000000000000000031\"},\n\t\t\t{\"0.000000272\", \"0.5\", \"0.0005215361924162119\"},\n\t\t\t{\"0.9999999999999999999\", \"0.5\", \"0.9999999999999999999\"},\n\n\t\t\t///////////////////\n\t\t\t// Integer Powers\n\t\t\t///////////////////\n\n\t\t\t// Zeros\n\t\t\t{\"0\", \"0\", \"1\"},\n\t\t\t{\"0\", \"1\", \"0\"},\n\t\t\t{\"0\", \"2\", \"0\"},\n\n\t\t\t// Ones\n\t\t\t{\"-1\", \"-2\", \"1\"},\n\t\t\t{\"-1\", \"-1\", \"-1\"},\n\t\t\t{\"-1\", \"0\", \"1\"},\n\t\t\t{\"-1\", \"1\", \"-1\"},\n\t\t\t{\"-1\", \"2\", \"1\"},\n\n\t\t\t// One tenths\n\t\t\t{\"0.1\", \"-18\", \"1000000000000000000\"},\n\t\t\t{\"0.1\", \"-10\", \"10000000000\"},\n\t\t\t{\"0.1\", \"-9\", \"1000000000\"},\n\t\t\t{\"0.1\", \"-8\", \"100000000\"},\n\t\t\t{\"0.1\", \"-7\", \"10000000\"},\n\t\t\t{\"0.1\", \"-6\", \"1000000\"},\n\t\t\t{\"0.1\", \"-5\", \"100000\"},\n\t\t\t{\"0.1\", \"-4\", \"10000\"},\n\t\t\t{\"0.1\", \"-3\", \"1000\"},\n\t\t\t{\"0.1\", \"-2\", \"100\"},\n\t\t\t{\"0.1\", \"-1\", \"10\"},\n\t\t\t{\"0.1\", \"0\", \"1\"},\n\t\t\t{\"0.1\", \"1\", \"0.1\"},\n\t\t\t{\"0.1\", \"2\", \"0.01\"},\n\t\t\t{\"0.1\", \"3\", \"0.001\"},\n\t\t\t{\"0.1\", \"4\", \"0.0001\"},\n\t\t\t{\"0.1\", \"5\", \"0.00001\"},\n\t\t\t{\"0.1\", \"6\", \"0.000001\"},\n\t\t\t{\"0.1\", \"7\", \"0.0000001\"},\n\t\t\t{\"0.1\", \"8\", \"0.00000001\"},\n\t\t\t{\"0.1\", \"9\", \"0.000000001\"},\n\t\t\t{\"0.1\", \"10\", \"0.0000000001\"},\n\t\t\t{\"0.1\", \"18\", \"0.000000000000000001\"},\n\t\t\t{\"0.1\", \"19\", \"0.0000000000000000001\"},\n\t\t\t{\"0.1\", \"20\", \"0.0000000000000000000\"},\n\t\t\t{\"0.1\", \"40\", \"0.0000000000000000000\"},\n\n\t\t\t// Negative one tenths\n\t\t\t{\"-0.1\", \"-18\", \"1000000000000000000\"},\n\t\t\t{\"-0.1\", \"-10\", \"10000000000\"},\n\t\t\t{\"-0.1\", \"-9\", \"-1000000000\"},\n\t\t\t{\"-0.1\", \"-8\", \"100000000\"},\n\t\t\t{\"-0.1\", \"-7\", \"-10000000\"},\n\t\t\t{\"-0.1\", \"-6\", \"1000000\"},\n\t\t\t{\"-0.1\", \"-5\", \"-100000\"},\n\t\t\t{\"-0.1\", \"-4\", \"10000\"},\n\t\t\t{\"-0.1\", \"-3\", \"-1000\"},\n\t\t\t{\"-0.1\", \"-2\", \"100\"},\n\t\t\t{\"-0.1\", \"-1\", \"-10\"},\n\t\t\t{\"-0.1\", \"0\", \"1\"},\n\t\t\t{\"-0.1\", \"1\", \"-0.1\"},\n\t\t\t{\"-0.1\", \"2\", \"0.01\"},\n\t\t\t{\"-0.1\", \"3\", \"-0.001\"},\n\t\t\t{\"-0.1\", \"4\", \"0.0001\"},\n\t\t\t{\"-0.1\", \"5\", \"-0.00001\"},\n\t\t\t{\"-0.1\", \"6\", \"0.000001\"},\n\t\t\t{\"-0.1\", \"7\", \"-0.0000001\"},\n\t\t\t{\"-0.1\", \"8\", \"0.00000001\"},\n\t\t\t{\"-0.1\", \"9\", \"-0.000000001\"},\n\t\t\t{\"-0.1\", \"10\", \"0.0000000001\"},\n\t\t\t{\"-0.1\", \"18\", \"0.000000000000000001\"},\n\t\t\t{\"-0.1\", \"19\", \"-0.0000000000000000001\"},\n\t\t\t{\"-0.1\", \"20\", \"0.0000000000000000000\"},\n\t\t\t{\"-0.1\", \"40\", \"0.0000000000000000000\"},\n\n\t\t\t// Twos\n\t\t\t{\"2\", \"-64\", \"0.0000000000000000001\"},\n\t\t\t{\"2\", \"-63\", \"0.0000000000000000001\"},\n\t\t\t{\"2\", \"-32\", \"0.0000000002328306437\"},\n\t\t\t{\"2\", \"-16\", \"0.0000152587890625\"},\n\t\t\t{\"2\", \"-9\", \"0.001953125\"},\n\t\t\t{\"2\", \"-8\", \"0.00390625\"},\n\t\t\t{\"2\", \"-7\", \"0.0078125\"},\n\t\t\t{\"2\", \"-6\", \"0.015625\"},\n\t\t\t{\"2\", \"-5\", \"0.03125\"},\n\t\t\t{\"2\", \"-4\", \"0.0625\"},\n\t\t\t{\"2\", \"-3\", \"0.125\"},\n\t\t\t{\"2\", \"-2\", \"0.25\"},\n\t\t\t{\"2\", \"-1\", \"0.5\"},\n\t\t\t{\"2\", \"0\", \"1\"},\n\t\t\t{\"2\", \"1\", \"2\"},\n\t\t\t{\"2\", \"2\", \"4\"},\n\t\t\t{\"2\", \"3\", \"8\"},\n\t\t\t{\"2\", \"4\", \"16\"},\n\t\t\t{\"2\", \"5\", \"32\"},\n\t\t\t{\"2\", \"6\", \"64\"},\n\t\t\t{\"2\", \"7\", \"128\"},\n\t\t\t{\"2\", \"8\", \"256\"},\n\t\t\t{\"2\", \"9\", \"512\"},\n\t\t\t{\"2\", \"16\", \"65536\"},\n\t\t\t{\"2\", \"32\", \"4294967296\"},\n\t\t\t{\"2\", \"63\", \"9223372036854775808\"},\n\n\t\t\t// Negative twos\n\t\t\t{\"-2\", \"-64\", \"0.0000000000000000001\"},\n\t\t\t{\"-2\", \"-63\", \"-0.0000000000000000001\"},\n\t\t\t{\"-2\", \"-32\", \"0.0000000002328306437\"},\n\t\t\t{\"-2\", \"-16\", \"0.0000152587890625\"},\n\t\t\t{\"-2\", \"-9\", \"-0.001953125\"},\n\t\t\t{\"-2\", \"-8\", \"0.00390625\"},\n\t\t\t{\"-2\", \"-7\", \"-0.0078125\"},\n\t\t\t{\"-2\", \"-6\", \"0.015625\"},\n\t\t\t{\"-2\", \"-5\", \"-0.03125\"},\n\t\t\t{\"-2\", \"-4\", \"0.0625\"},\n\t\t\t{\"-2\", \"-3\", \"-0.125\"},\n\t\t\t{\"-2\", \"-2\", \"0.25\"},\n\t\t\t{\"-2\", \"-1\", \"-0.5\"},\n\t\t\t{\"-2\", \"0\", \"1\"},\n\t\t\t{\"-2\", \"1\", \"-2\"},\n\t\t\t{\"-2\", \"2\", \"4\"},\n\t\t\t{\"-2\", \"3\", \"-8\"},\n\t\t\t{\"-2\", \"4\", \"16\"},\n\t\t\t{\"-2\", \"5\", \"-32\"},\n\t\t\t{\"-2\", \"6\", \"64\"},\n\t\t\t{\"-2\", \"7\", \"-128\"},\n\t\t\t{\"-2\", \"8\", \"256\"},\n\t\t\t{\"-2\", \"9\", \"-512\"},\n\t\t\t{\"-2\", \"16\", \"65536\"},\n\t\t\t{\"-2\", \"32\", \"4294967296\"},\n\t\t\t{\"-2\", \"63\", \"-9223372036854775808\"},\n\n\t\t\t// Squares\n\t\t\t{\"-3\", \"2\", \"9\"},\n\t\t\t{\"-2\", \"2\", \"4\"},\n\t\t\t{\"-1\", \"2\", \"1\"},\n\t\t\t{\"0\", \"2\", \"0\"},\n\t\t\t{\"1\", \"2\", \"1\"},\n\t\t\t{\"2\", \"2\", \"4\"},\n\t\t\t{\"3\", \"2\", \"9\"},\n\t\t\t{\"4\", \"2\", \"16\"},\n\t\t\t{\"5\", \"2\", \"25\"},\n\t\t\t{\"6\", \"2\", \"36\"},\n\t\t\t{\"7\", \"2\", \"49\"},\n\t\t\t{\"8\", \"2\", \"64\"},\n\t\t\t{\"9\", \"2\", \"81\"},\n\t\t\t{\"10\", \"2\", \"100\"},\n\t\t\t{\"11\", \"2\", \"121\"},\n\t\t\t{\"12\", \"2\", \"144\"},\n\t\t\t{\"13\", \"2\", \"169\"},\n\t\t\t{\"14\", \"2\", \"196\"},\n\n\t\t\t{\"-0.3\", \"2\", \"0.09\"},\n\t\t\t{\"-0.2\", \"2\", \"0.04\"},\n\t\t\t{\"-0.1\", \"2\", \"0.01\"},\n\t\t\t{\"0.0\", \"2\", \"0.00\"},\n\t\t\t{\"0.1\", \"2\", \"0.01\"},\n\t\t\t{\"0.2\", \"2\", \"0.04\"},\n\t\t\t{\"0.3\", \"2\", \"0.09\"},\n\t\t\t{\"0.4\", \"2\", \"0.16\"},\n\t\t\t{\"0.5\", \"2\", \"0.25\"},\n\t\t\t{\"0.6\", \"2\", \"0.36\"},\n\t\t\t{\"0.7\", \"2\", \"0.49\"},\n\t\t\t{\"0.8\", \"2\", \"0.64\"},\n\t\t\t{\"0.9\", \"2\", \"0.81\"},\n\t\t\t{\"1.0\", \"2\", \"1.00\"},\n\t\t\t{\"1.1\", \"2\", \"1.21\"},\n\t\t\t{\"1.2\", \"2\", \"1.44\"},\n\t\t\t{\"1.3\", \"2\", \"1.69\"},\n\t\t\t{\"1.4\", \"2\", \"1.96\"},\n\n\t\t\t{\"0.000000000316227766\", \"2\", \"0.0000000000000000001\"},\n\t\t\t{\"3162277660.168379331\", \"2\", \"9999999999999999994\"},\n\n\t\t\t// Cubes\n\t\t\t{\"-3\", \"3\", \"-27\"},\n\t\t\t{\"-2\", \"3\", \"-8\"},\n\t\t\t{\"-1\", \"3\", \"-1\"},\n\t\t\t{\"0\", \"3\", \"0\"},\n\t\t\t{\"1\", \"3\", \"1\"},\n\t\t\t{\"2\", \"3\", \"8\"},\n\t\t\t{\"3\", \"3\", \"27\"},\n\t\t\t{\"4\", \"3\", \"64\"},\n\t\t\t{\"5\", \"3\", \"125\"},\n\t\t\t{\"6\", \"3\", \"216\"},\n\t\t\t{\"7\", \"3\", \"343\"},\n\t\t\t{\"8\", \"3\", \"512\"},\n\t\t\t{\"9\", \"3\", \"729\"},\n\t\t\t{\"10\", \"3\", \"1000\"},\n\t\t\t{\"11\", \"3\", \"1331\"},\n\t\t\t{\"12\", \"3\", \"1728\"},\n\t\t\t{\"13\", \"3\", \"2197\"},\n\t\t\t{\"14\", \"3\", \"2744\"},\n\n\t\t\t{\"-0.3\", \"3\", \"-0.027\"},\n\t\t\t{\"-0.2\", \"3\", \"-0.008\"},\n\t\t\t{\"-0.1\", \"3\", \"-0.001\"},\n\t\t\t{\"0.0\", \"3\", \"0.000\"},\n\t\t\t{\"0.1\", \"3\", \"0.001\"},\n\t\t\t{\"0.2\", \"3\", \"0.008\"},\n\t\t\t{\"0.3\", \"3\", \"0.027\"},\n\t\t\t{\"0.4\", \"3\", \"0.064\"},\n\t\t\t{\"0.5\", \"3\", \"0.125\"},\n\t\t\t{\"0.6\", \"3\", \"0.216\"},\n\t\t\t{\"0.7\", \"3\", \"0.343\"},\n\t\t\t{\"0.8\", \"3\", \"0.512\"},\n\t\t\t{\"0.9\", \"3\", \"0.729\"},\n\t\t\t{\"1.0\", \"3\", \"1.000\"},\n\t\t\t{\"1.1\", \"3\", \"1.331\"},\n\t\t\t{\"1.2\", \"3\", \"1.728\"},\n\t\t\t{\"1.3\", \"3\", \"2.197\"},\n\t\t\t{\"1.4\", \"3\", \"2.744\"},\n\n\t\t\t{\"0.000000464158883361\", \"3\", \"0.0000000000000000001\"},\n\t\t\t{\"2154434.690031883721\", \"3\", \"9999999999999999989\"},\n\n\t\t\t// Interest accrual\n\t\t\t{\"1.1\", \"60\", \"304.4816395414180996\"},         // no error\n\t\t\t{\"1.01\", \"600\", \"391.5833969993197743\"},       // no error\n\t\t\t{\"1.001\", \"6000\", \"402.2211245663552923\"},     // no error\n\t\t\t{\"1.0001\", \"60000\", \"403.3077910727185433\"},   // no error\n\t\t\t{\"1.00001\", \"600000\", \"403.4166908911542153\"}, // no error\n\n\t\t\t// Captured during fuzzing\n\t\t\t{\"0.85\", \"-267\", \"7000786514887173012\"},\n\t\t\t{\"0.066\", \"-16\", \"7714309010612096020\"},\n\t\t\t{\"-0.9223372036854775808\", \"-128\", \"31197.15320234751783\"},\n\t\t\t{\"999999999.999999999\", \"-9223372036854775808\", \"0\"},\n\t\t\t{\"-0.9223372036854775807\", \"-541\", \"-9877744411719625497\"},\n\t\t\t{\"0.9223372036854775702\", \"-540\", \"9110611159425388150\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\te := MustParse(tt.e)\n\t\t\tgot, err := d.Pow(e)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.Pow(%q) failed: %v\", d, e, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"%q.Pow(%q) = %q, want %q\", d, e, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]struct {\n\t\t\td, e string\n\t\t}{\n\t\t\t\"overflow 1\": {\"2\", \"64\"},\n\t\t\t\"overflow 2\": {\"0.5\", \"-64\"},\n\t\t\t\"overflow 3\": {\"10\", \"19\"},\n\t\t\t\"overflow 4\": {\"0.1\", \"-19\"},\n\t\t\t\"overflow 5\": {\"0.0000000000000000001\", \"-3\"},\n\t\t\t\"overflow 6\": {\"999999999.999999999\", \"999999999.999999999\"},\n\t\t\t\"zero 1\":     {\"0\", \"-1\"},\n\t\t\t\"negative 1\": {\"-1\", \"0.1\"},\n\t\t}\n\t\tfor name, tt := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\td := MustParse(tt.d)\n\t\t\t\te := MustParse(tt.e)\n\t\t\t\t_, err := d.Pow(e)\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"%q.Pow(%d) did not fail\", d, e)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestDecimal_PowInt(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td     string\n\t\t\tpower int\n\t\t\twant  string\n\t\t}{\n\t\t\t// Zeros\n\t\t\t{\"0\", 0, \"1\"},\n\t\t\t{\"0\", 1, \"0\"},\n\t\t\t{\"0\", 2, \"0\"},\n\n\t\t\t// Ones\n\t\t\t{\"-1\", -2, \"1\"},\n\t\t\t{\"-1\", -1, \"-1\"},\n\t\t\t{\"-1\", 0, \"1\"},\n\t\t\t{\"-1\", 1, \"-1\"},\n\t\t\t{\"-1\", 2, \"1\"},\n\n\t\t\t// One tenths\n\t\t\t{\"0.1\", -18, \"1000000000000000000\"},\n\t\t\t{\"0.1\", -10, \"10000000000\"},\n\t\t\t{\"0.1\", -9, \"1000000000\"},\n\t\t\t{\"0.1\", -8, \"100000000\"},\n\t\t\t{\"0.1\", -7, \"10000000\"},\n\t\t\t{\"0.1\", -6, \"1000000\"},\n\t\t\t{\"0.1\", -5, \"100000\"},\n\t\t\t{\"0.1\", -4, \"10000\"},\n\t\t\t{\"0.1\", -3, \"1000\"},\n\t\t\t{\"0.1\", -2, \"100\"},\n\t\t\t{\"0.1\", -1, \"10\"},\n\t\t\t{\"0.1\", 0, \"1\"},\n\t\t\t{\"0.1\", 1, \"0.1\"},\n\t\t\t{\"0.1\", 2, \"0.01\"},\n\t\t\t{\"0.1\", 3, \"0.001\"},\n\t\t\t{\"0.1\", 4, \"0.0001\"},\n\t\t\t{\"0.1\", 5, \"0.00001\"},\n\t\t\t{\"0.1\", 6, \"0.000001\"},\n\t\t\t{\"0.1\", 7, \"0.0000001\"},\n\t\t\t{\"0.1\", 8, \"0.00000001\"},\n\t\t\t{\"0.1\", 9, \"0.000000001\"},\n\t\t\t{\"0.1\", 10, \"0.0000000001\"},\n\t\t\t{\"0.1\", 18, \"0.000000000000000001\"},\n\t\t\t{\"0.1\", 19, \"0.0000000000000000001\"},\n\t\t\t{\"0.1\", 20, \"0.0000000000000000000\"},\n\t\t\t{\"0.1\", 40, \"0.0000000000000000000\"},\n\n\t\t\t// Negative one tenths\n\t\t\t{\"-0.1\", -18, \"1000000000000000000\"},\n\t\t\t{\"-0.1\", -10, \"10000000000\"},\n\t\t\t{\"-0.1\", -9, \"-1000000000\"},\n\t\t\t{\"-0.1\", -8, \"100000000\"},\n\t\t\t{\"-0.1\", -7, \"-10000000\"},\n\t\t\t{\"-0.1\", -6, \"1000000\"},\n\t\t\t{\"-0.1\", -5, \"-100000\"},\n\t\t\t{\"-0.1\", -4, \"10000\"},\n\t\t\t{\"-0.1\", -3, \"-1000\"},\n\t\t\t{\"-0.1\", -2, \"100\"},\n\t\t\t{\"-0.1\", -1, \"-10\"},\n\t\t\t{\"-0.1\", 0, \"1\"},\n\t\t\t{\"-0.1\", 1, \"-0.1\"},\n\t\t\t{\"-0.1\", 2, \"0.01\"},\n\t\t\t{\"-0.1\", 3, \"-0.001\"},\n\t\t\t{\"-0.1\", 4, \"0.0001\"},\n\t\t\t{\"-0.1\", 5, \"-0.00001\"},\n\t\t\t{\"-0.1\", 6, \"0.000001\"},\n\t\t\t{\"-0.1\", 7, \"-0.0000001\"},\n\t\t\t{\"-0.1\", 8, \"0.00000001\"},\n\t\t\t{\"-0.1\", 9, \"-0.000000001\"},\n\t\t\t{\"-0.1\", 10, \"0.0000000001\"},\n\t\t\t{\"-0.1\", 18, \"0.000000000000000001\"},\n\t\t\t{\"-0.1\", 19, \"-0.0000000000000000001\"},\n\t\t\t{\"-0.1\", 20, \"0.0000000000000000000\"},\n\t\t\t{\"-0.1\", 40, \"0.0000000000000000000\"},\n\n\t\t\t// Twos\n\t\t\t{\"2\", -64, \"0.0000000000000000001\"},\n\t\t\t{\"2\", -63, \"0.0000000000000000001\"},\n\t\t\t{\"2\", -32, \"0.0000000002328306437\"},\n\t\t\t{\"2\", -16, \"0.0000152587890625\"},\n\t\t\t{\"2\", -9, \"0.001953125\"},\n\t\t\t{\"2\", -8, \"0.00390625\"},\n\t\t\t{\"2\", -7, \"0.0078125\"},\n\t\t\t{\"2\", -6, \"0.015625\"},\n\t\t\t{\"2\", -5, \"0.03125\"},\n\t\t\t{\"2\", -4, \"0.0625\"},\n\t\t\t{\"2\", -3, \"0.125\"},\n\t\t\t{\"2\", -2, \"0.25\"},\n\t\t\t{\"2\", -1, \"0.5\"},\n\t\t\t{\"2\", 0, \"1\"},\n\t\t\t{\"2\", 1, \"2\"},\n\t\t\t{\"2\", 2, \"4\"},\n\t\t\t{\"2\", 3, \"8\"},\n\t\t\t{\"2\", 4, \"16\"},\n\t\t\t{\"2\", 5, \"32\"},\n\t\t\t{\"2\", 6, \"64\"},\n\t\t\t{\"2\", 7, \"128\"},\n\t\t\t{\"2\", 8, \"256\"},\n\t\t\t{\"2\", 9, \"512\"},\n\t\t\t{\"2\", 16, \"65536\"},\n\t\t\t{\"2\", 32, \"4294967296\"},\n\t\t\t{\"2\", 63, \"9223372036854775808\"},\n\n\t\t\t// Negative twos\n\t\t\t{\"-2\", -64, \"0.0000000000000000001\"},\n\t\t\t{\"-2\", -63, \"-0.0000000000000000001\"},\n\t\t\t{\"-2\", -32, \"0.0000000002328306437\"},\n\t\t\t{\"-2\", -16, \"0.0000152587890625\"},\n\t\t\t{\"-2\", -9, \"-0.001953125\"},\n\t\t\t{\"-2\", -8, \"0.00390625\"},\n\t\t\t{\"-2\", -7, \"-0.0078125\"},\n\t\t\t{\"-2\", -6, \"0.015625\"},\n\t\t\t{\"-2\", -5, \"-0.03125\"},\n\t\t\t{\"-2\", -4, \"0.0625\"},\n\t\t\t{\"-2\", -3, \"-0.125\"},\n\t\t\t{\"-2\", -2, \"0.25\"},\n\t\t\t{\"-2\", -1, \"-0.5\"},\n\t\t\t{\"-2\", 0, \"1\"},\n\t\t\t{\"-2\", 1, \"-2\"},\n\t\t\t{\"-2\", 2, \"4\"},\n\t\t\t{\"-2\", 3, \"-8\"},\n\t\t\t{\"-2\", 4, \"16\"},\n\t\t\t{\"-2\", 5, \"-32\"},\n\t\t\t{\"-2\", 6, \"64\"},\n\t\t\t{\"-2\", 7, \"-128\"},\n\t\t\t{\"-2\", 8, \"256\"},\n\t\t\t{\"-2\", 9, \"-512\"},\n\t\t\t{\"-2\", 16, \"65536\"},\n\t\t\t{\"-2\", 32, \"4294967296\"},\n\t\t\t{\"-2\", 63, \"-9223372036854775808\"},\n\n\t\t\t// Squares\n\t\t\t{\"-3\", 2, \"9\"},\n\t\t\t{\"-2\", 2, \"4\"},\n\t\t\t{\"-1\", 2, \"1\"},\n\t\t\t{\"0\", 2, \"0\"},\n\t\t\t{\"1\", 2, \"1\"},\n\t\t\t{\"2\", 2, \"4\"},\n\t\t\t{\"3\", 2, \"9\"},\n\t\t\t{\"4\", 2, \"16\"},\n\t\t\t{\"5\", 2, \"25\"},\n\t\t\t{\"6\", 2, \"36\"},\n\t\t\t{\"7\", 2, \"49\"},\n\t\t\t{\"8\", 2, \"64\"},\n\t\t\t{\"9\", 2, \"81\"},\n\t\t\t{\"10\", 2, \"100\"},\n\t\t\t{\"11\", 2, \"121\"},\n\t\t\t{\"12\", 2, \"144\"},\n\t\t\t{\"13\", 2, \"169\"},\n\t\t\t{\"14\", 2, \"196\"},\n\n\t\t\t{\"-0.3\", 2, \"0.09\"},\n\t\t\t{\"-0.2\", 2, \"0.04\"},\n\t\t\t{\"-0.1\", 2, \"0.01\"},\n\t\t\t{\"0.0\", 2, \"0.00\"},\n\t\t\t{\"0.1\", 2, \"0.01\"},\n\t\t\t{\"0.2\", 2, \"0.04\"},\n\t\t\t{\"0.3\", 2, \"0.09\"},\n\t\t\t{\"0.4\", 2, \"0.16\"},\n\t\t\t{\"0.5\", 2, \"0.25\"},\n\t\t\t{\"0.6\", 2, \"0.36\"},\n\t\t\t{\"0.7\", 2, \"0.49\"},\n\t\t\t{\"0.8\", 2, \"0.64\"},\n\t\t\t{\"0.9\", 2, \"0.81\"},\n\t\t\t{\"1.0\", 2, \"1.00\"},\n\t\t\t{\"1.1\", 2, \"1.21\"},\n\t\t\t{\"1.2\", 2, \"1.44\"},\n\t\t\t{\"1.3\", 2, \"1.69\"},\n\t\t\t{\"1.4\", 2, \"1.96\"},\n\n\t\t\t{\"0.000000000316227766\", 2, \"0.0000000000000000001\"},\n\t\t\t{\"3162277660.168379331\", 2, \"9999999999999999994\"},\n\n\t\t\t// Cubes\n\t\t\t{\"-3\", 3, \"-27\"},\n\t\t\t{\"-2\", 3, \"-8\"},\n\t\t\t{\"-1\", 3, \"-1\"},\n\t\t\t{\"0\", 3, \"0\"},\n\t\t\t{\"1\", 3, \"1\"},\n\t\t\t{\"2\", 3, \"8\"},\n\t\t\t{\"3\", 3, \"27\"},\n\t\t\t{\"4\", 3, \"64\"},\n\t\t\t{\"5\", 3, \"125\"},\n\t\t\t{\"6\", 3, \"216\"},\n\t\t\t{\"7\", 3, \"343\"},\n\t\t\t{\"8\", 3, \"512\"},\n\t\t\t{\"9\", 3, \"729\"},\n\t\t\t{\"10\", 3, \"1000\"},\n\t\t\t{\"11\", 3, \"1331\"},\n\t\t\t{\"12\", 3, \"1728\"},\n\t\t\t{\"13\", 3, \"2197\"},\n\t\t\t{\"14\", 3, \"2744\"},\n\n\t\t\t{\"-0.3\", 3, \"-0.027\"},\n\t\t\t{\"-0.2\", 3, \"-0.008\"},\n\t\t\t{\"-0.1\", 3, \"-0.001\"},\n\t\t\t{\"0.0\", 3, \"0.000\"},\n\t\t\t{\"0.1\", 3, \"0.001\"},\n\t\t\t{\"0.2\", 3, \"0.008\"},\n\t\t\t{\"0.3\", 3, \"0.027\"},\n\t\t\t{\"0.4\", 3, \"0.064\"},\n\t\t\t{\"0.5\", 3, \"0.125\"},\n\t\t\t{\"0.6\", 3, \"0.216\"},\n\t\t\t{\"0.7\", 3, \"0.343\"},\n\t\t\t{\"0.8\", 3, \"0.512\"},\n\t\t\t{\"0.9\", 3, \"0.729\"},\n\t\t\t{\"1.0\", 3, \"1.000\"},\n\t\t\t{\"1.1\", 3, \"1.331\"},\n\t\t\t{\"1.2\", 3, \"1.728\"},\n\t\t\t{\"1.3\", 3, \"2.197\"},\n\t\t\t{\"1.4\", 3, \"2.744\"},\n\n\t\t\t{\"0.000000464158883361\", 3, \"0.0000000000000000001\"},\n\t\t\t{\"2154434.690031883721\", 3, \"9999999999999999989\"},\n\n\t\t\t// Interest accrual\n\t\t\t{\"1.1\", 60, \"304.4816395414180996\"},         // no error\n\t\t\t{\"1.01\", 600, \"391.5833969993197743\"},       // no error\n\t\t\t{\"1.001\", 6000, \"402.2211245663552923\"},     // no error\n\t\t\t{\"1.0001\", 60000, \"403.3077910727185433\"},   // no error\n\t\t\t{\"1.00001\", 600000, \"403.4166908911542153\"}, // no error\n\n\t\t\t// Captured during fuzzing\n\t\t\t{\"-0.9223372036854775807\", -541, \"-9877744411719625497\"},\n\t\t\t{\"999999999.999999999\", math.MinInt, \"0\"},\n\t\t\t{\"-0.9223372036854775808\", -128, \"31197.15320234751783\"},\n\t\t\t{\"0.85\", -267, \"7000786514887173012\"},\n\t\t\t{\"0.066\", -16, \"7714309010612096020\"},\n\t\t\t{\"0.9223372036854775702\", -540, \"9110611159425388150\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\tgot, err := d.PowInt(tt.power)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.PowInt(%d) failed: %v\", d, tt.power, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"%q.PowInt(%d) = %q, want %q\", d, tt.power, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]struct {\n\t\t\td     string\n\t\t\tpower int\n\t\t}{\n\t\t\t\"overflow 1\": {\"2\", 64},\n\t\t\t\"overflow 2\": {\"0.5\", -64},\n\t\t\t\"overflow 3\": {\"10\", 19},\n\t\t\t\"overflow 4\": {\"0.1\", -19},\n\t\t\t\"overflow 5\": {\"0.0000000000000000001\", -3},\n\t\t\t\"overflow 6\": {\"999999999.999999999\", math.MaxInt},\n\t\t\t\"zero 1\":     {\"0\", -1},\n\t\t}\n\t\tfor name, tt := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\td := MustParse(tt.d)\n\t\t\t\t_, err := d.PowInt(tt.power)\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"%q.PowInt(%d) did not fail\", d, tt.power)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestDecimal_Sqrt(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, want string\n\t\t}{\n\t\t\t// Zeros\n\t\t\t{\"0.00000000\", \"0.0000\"},\n\t\t\t{\"0.0000000\", \"0.000\"},\n\t\t\t{\"0.000000\", \"0.000\"},\n\t\t\t{\"0.00000\", \"0.00\"},\n\t\t\t{\"0.0000\", \"0.00\"},\n\t\t\t{\"0.000\", \"0.0\"},\n\t\t\t{\"0.00\", \"0.0\"},\n\t\t\t{\"0.0\", \"0\"},\n\t\t\t{\"0\", \"0\"},\n\n\t\t\t// Trailing zeros\n\t\t\t{\"0.010000000\", \"0.1000\"},\n\t\t\t{\"0.01000000\", \"0.1000\"},\n\t\t\t{\"0.0100000\", \"0.100\"},\n\t\t\t{\"0.010000\", \"0.100\"},\n\t\t\t{\"0.01000\", \"0.10\"},\n\t\t\t{\"0.0100\", \"0.10\"},\n\t\t\t{\"0.010\", \"0.1\"},\n\t\t\t{\"0.01\", \"0.1\"},\n\n\t\t\t// Powers of ten\n\t\t\t{\"0.00000001\", \"0.0001\"},\n\t\t\t{\"0.0000001\", \"0.0003162277660168379\"},\n\t\t\t{\"0.000001\", \"0.001\"},\n\t\t\t{\"0.00001\", \"0.0031622776601683793\"},\n\t\t\t{\"0.0001\", \"0.01\"},\n\t\t\t{\"0.001\", \"0.0316227766016837933\"},\n\t\t\t{\"0.01\", \"0.1\"},\n\t\t\t{\"0.1\", \"0.3162277660168379332\"},\n\t\t\t{\"1\", \"1\"},\n\t\t\t{\"10\", \"3.162277660168379332\"},\n\t\t\t{\"100\", \"10\"},\n\t\t\t{\"1000\", \"31.62277660168379332\"},\n\t\t\t{\"10000\", \"100\"},\n\t\t\t{\"100000\", \"316.2277660168379332\"},\n\t\t\t{\"1000000\", \"1000\"},\n\t\t\t{\"10000000\", \"3162.277660168379332\"},\n\t\t\t{\"100000000\", \"10000\"},\n\n\t\t\t// Natural numbers\n\t\t\t{\"0\", \"0\"},\n\t\t\t{\"1\", \"1\"},\n\t\t\t{\"2\", \"1.414213562373095049\"},\n\t\t\t{\"3\", \"1.732050807568877294\"},\n\t\t\t{\"4\", \"2\"},\n\t\t\t{\"5\", \"2.236067977499789696\"},\n\t\t\t{\"6\", \"2.449489742783178098\"},\n\t\t\t{\"7\", \"2.645751311064590591\"},\n\t\t\t{\"8\", \"2.828427124746190098\"},\n\t\t\t{\"9\", \"3\"},\n\t\t\t{\"10\", \"3.162277660168379332\"},\n\t\t\t{\"11\", \"3.316624790355399849\"},\n\t\t\t{\"12\", \"3.464101615137754587\"},\n\t\t\t{\"13\", \"3.605551275463989293\"},\n\t\t\t{\"14\", \"3.741657386773941386\"},\n\t\t\t{\"15\", \"3.872983346207416885\"},\n\t\t\t{\"16\", \"4\"},\n\t\t\t{\"17\", \"4.12310562561766055\"},\n\t\t\t{\"18\", \"4.242640687119285146\"},\n\t\t\t{\"19\", \"4.358898943540673552\"},\n\t\t\t{\"20\", \"4.472135954999579393\"},\n\t\t\t{\"21\", \"4.582575694955840007\"},\n\t\t\t{\"22\", \"4.690415759823429555\"},\n\t\t\t{\"23\", \"4.795831523312719542\"},\n\t\t\t{\"24\", \"4.898979485566356196\"},\n\t\t\t{\"25\", \"5\"},\n\n\t\t\t// Well-known squares\n\t\t\t{\"1\", \"1\"},\n\t\t\t{\"4\", \"2\"},\n\t\t\t{\"9\", \"3\"},\n\t\t\t{\"16\", \"4\"},\n\t\t\t{\"25\", \"5\"},\n\t\t\t{\"36\", \"6\"},\n\t\t\t{\"49\", \"7\"},\n\t\t\t{\"64\", \"8\"},\n\t\t\t{\"81\", \"9\"},\n\t\t\t{\"100\", \"10\"},\n\t\t\t{\"121\", \"11\"},\n\t\t\t{\"144\", \"12\"},\n\t\t\t{\"169\", \"13\"},\n\t\t\t{\"256\", \"16\"},\n\t\t\t{\"1024\", \"32\"},\n\t\t\t{\"4096\", \"64\"},\n\n\t\t\t{\"0.01\", \"0.1\"},\n\t\t\t{\"0.04\", \"0.2\"},\n\t\t\t{\"0.09\", \"0.3\"},\n\t\t\t{\"0.16\", \"0.4\"},\n\t\t\t{\"0.25\", \"0.5\"},\n\t\t\t{\"0.36\", \"0.6\"},\n\t\t\t{\"0.49\", \"0.7\"},\n\t\t\t{\"0.64\", \"0.8\"},\n\t\t\t{\"0.81\", \"0.9\"},\n\t\t\t{\"1.00\", \"1.0\"},\n\t\t\t{\"1.21\", \"1.1\"},\n\t\t\t{\"1.44\", \"1.2\"},\n\t\t\t{\"1.69\", \"1.3\"},\n\t\t\t{\"2.56\", \"1.6\"},\n\t\t\t{\"10.24\", \"3.2\"},\n\t\t\t{\"40.96\", \"6.4\"},\n\n\t\t\t// Smallest and largest numbers\n\t\t\t{\"0.0000000000000000001\", \"0.000000000316227766\"},\n\t\t\t{\"9999999999999999999\", \"3162277660.168379332\"},\n\n\t\t\t// Captured during fuzzing\n\t\t\t{\"1.000000000000000063\", \"1.000000000000000031\"},\n\t\t\t{\"0.000000272\", \"0.0005215361924162119\"},\n\t\t\t{\"0.9999999999999999999\", \"0.9999999999999999999\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\tgot, err := d.Sqrt()\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.Sqrt() failed: %v\", d, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"%q.Sqrt() = %q, want %q\", d, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]string{\n\t\t\t\"negative\": \"-1\",\n\t\t}\n\t\tfor name, d := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\td := MustParse(d)\n\t\t\t\t_, err := d.Sqrt()\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"%q.Sqrt() did not fail\", d)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestDecimal_Exp(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, want string\n\t\t}{\n\t\t\t// Zeros\n\t\t\t{\"0\", \"1\"},\n\t\t\t{\"0.0\", \"1\"},\n\t\t\t{\"0.00\", \"1\"},\n\t\t\t{\"0.000\", \"1\"},\n\t\t\t{\"0.0000\", \"1\"},\n\t\t\t{\"0.00000\", \"1\"},\n\n\t\t\t// Ones\n\t\t\t{\"1\", E.String()},\n\t\t\t{\"1.0\", E.String()},\n\t\t\t{\"1.00\", E.String()},\n\t\t\t{\"1.000\", E.String()},\n\t\t\t{\"1.0000\", E.String()},\n\t\t\t{\"1.00000\", E.String()},\n\n\t\t\t// Closer and closer to negative one\n\t\t\t{\"-0.9\", \"0.4065696597405991119\"},\n\t\t\t{\"-0.99\", \"0.3715766910220456905\"},\n\t\t\t{\"-0.999\", \"0.3682475046136629212\"},\n\t\t\t{\"-0.9999\", \"0.3679162309550179865\"},\n\t\t\t{\"-0.99999\", \"0.3678831199842480694\"},\n\t\t\t{\"-0.999999\", \"0.3678798090510674328\"},\n\t\t\t{\"-0.9999999\", \"0.3678794779593882781\"},\n\t\t\t{\"-0.99999999\", \"0.3678794448502367517\"},\n\t\t\t{\"-0.999999999\", \"0.3678794415393217630\"},\n\t\t\t{\"-0.9999999999\", \"0.3678794412082302657\"},\n\t\t\t{\"-0.99999999999\", \"0.3678794411751211160\"},\n\t\t\t{\"-0.999999999999\", \"0.3678794411718102010\"},\n\t\t\t{\"-0.9999999999999\", \"0.3678794411714791095\"},\n\t\t\t{\"-0.99999999999999\", \"0.3678794411714460004\"},\n\t\t\t{\"-0.999999999999999\", \"0.3678794411714426895\"},\n\t\t\t{\"-0.9999999999999999\", \"0.3678794411714423584\"},\n\t\t\t{\"-0.99999999999999999\", \"0.3678794411714423253\"},\n\t\t\t{\"-0.999999999999999999\", \"0.3678794411714423220\"},\n\t\t\t{\"-1\", \"0.3678794411714423216\"},\n\t\t\t{\"-1.000000000000000001\", \"0.3678794411714423212\"},\n\t\t\t{\"-1.00000000000000001\", \"0.3678794411714423179\"},\n\t\t\t{\"-1.0000000000000001\", \"0.3678794411714422848\"},\n\t\t\t{\"-1.000000000000001\", \"0.3678794411714419537\"},\n\t\t\t{\"-1.00000000000001\", \"0.3678794411714386428\"},\n\t\t\t{\"-1.0000000000001\", \"0.3678794411714055337\"},\n\t\t\t{\"-1.000000000001\", \"0.3678794411710744422\"},\n\t\t\t{\"-1.00000000001\", \"0.3678794411677635272\"},\n\t\t\t{\"-1.0000000001\", \"0.3678794411346543775\"},\n\t\t\t{\"-1.000000001\", \"0.3678794408035628806\"},\n\t\t\t{\"-1.00000001\", \"0.3678794374926479283\"},\n\t\t\t{\"-1.0000001\", \"0.3678794043835000438\"},\n\t\t\t{\"-1.000001\", \"0.3678790732921850898\"},\n\t\t\t{\"-1.00001\", \"0.3678757623954245179\"},\n\t\t\t{\"-1.0001\", \"0.3678426550666610715\"},\n\t\t\t{\"-1.001\", \"0.3675117456086935500\"},\n\t\t\t{\"-1.01\", \"0.3642189795715233198\"},\n\t\t\t{\"-1.1\", \"0.3328710836980795533\"},\n\n\t\t\t// Closer and closer to zero\n\t\t\t{\"-0.1\", \"0.9048374180359595732\"},\n\t\t\t{\"-0.01\", \"0.9900498337491680536\"},\n\t\t\t{\"-0.001\", \"0.9990004998333749917\"},\n\t\t\t{\"-0.0001\", \"0.9999000049998333375\"},\n\t\t\t{\"-0.00001\", \"0.9999900000499998333\"},\n\t\t\t{\"-0.000001\", \"0.9999990000004999998\"},\n\t\t\t{\"-0.0000001\", \"0.9999999000000050000\"},\n\t\t\t{\"-0.00000001\", \"0.9999999900000000500\"},\n\t\t\t{\"-0.000000001\", \"0.9999999990000000005\"},\n\t\t\t{\"-0.0000000001\", \"0.9999999999000000000\"},\n\t\t\t{\"-0.00000000001\", \"0.9999999999900000000\"},\n\t\t\t{\"-0.000000000001\", \"0.9999999999990000000\"},\n\t\t\t{\"-0.0000000000001\", \"0.9999999999999000000\"},\n\t\t\t{\"-0.00000000000001\", \"0.9999999999999900000\"},\n\t\t\t{\"-0.000000000000001\", \"0.9999999999999990000\"},\n\t\t\t{\"-0.0000000000000001\", \"0.9999999999999999000\"},\n\t\t\t{\"-0.00000000000000001\", \"0.9999999999999999900\"},\n\t\t\t{\"-0.000000000000000001\", \"0.9999999999999999990\"},\n\t\t\t{\"-0.0000000000000000001\", \"0.9999999999999999999\"},\n\t\t\t{\"0\", \"1\"},\n\t\t\t{\"0.0000000000000000001\", \"1.000000000000000000\"},\n\t\t\t{\"0.000000000000000001\", \"1.000000000000000001\"},\n\t\t\t{\"0.00000000000000001\", \"1.000000000000000010\"},\n\t\t\t{\"0.0000000000000001\", \"1.000000000000000100\"},\n\t\t\t{\"0.000000000000001\", \"1.000000000000001000\"},\n\t\t\t{\"0.00000000000001\", \"1.000000000000010000\"},\n\t\t\t{\"0.0000000000001\", \"1.000000000000100000\"},\n\t\t\t{\"0.000000000001\", \"1.000000000001000000\"},\n\t\t\t{\"0.00000000001\", \"1.000000000010000000\"},\n\t\t\t{\"0.0000000001\", \"1.000000000100000000\"},\n\t\t\t{\"0.000000001\", \"1.000000001000000001\"},\n\t\t\t{\"0.00000001\", \"1.000000010000000050\"},\n\t\t\t{\"0.0000001\", \"1.000000100000005000\"},\n\t\t\t{\"0.000001\", \"1.000001000000500000\"},\n\t\t\t{\"0.00001\", \"1.000010000050000167\"},\n\t\t\t{\"0.0001\", \"1.000100005000166671\"},\n\t\t\t{\"0.001\", \"1.001000500166708342\"},\n\t\t\t{\"0.01\", \"1.010050167084168058\"},\n\t\t\t{\"0.1\", \"1.105170918075647625\"},\n\n\t\t\t// Closer and closer to one\n\t\t\t{\"0.9\", \"2.459603111156949664\"},\n\t\t\t{\"0.99\", \"2.691234472349262289\"},\n\t\t\t{\"0.999\", \"2.715564905318566687\"},\n\t\t\t{\"0.9999\", \"2.718010013867155437\"},\n\t\t\t{\"0.99999\", \"2.718254645776674283\"},\n\t\t\t{\"0.999999\", \"2.718279110178575917\"},\n\t\t\t{\"0.9999999\", \"2.718281556630875981\"},\n\t\t\t{\"0.99999999\", \"2.718281801276227087\"},\n\t\t\t{\"0.999999999\", \"2.718281825740763408\"},\n\t\t\t{\"0.9999999999\", \"2.718281828187217053\"},\n\t\t\t{\"0.99999999999\", \"2.718281828431862417\"},\n\t\t\t{\"0.999999999999\", \"2.718281828456326954\"},\n\t\t\t{\"0.9999999999999\", \"2.718281828458773407\"},\n\t\t\t{\"0.99999999999999\", \"2.718281828459018053\"},\n\t\t\t{\"0.999999999999999\", \"2.718281828459042517\"},\n\t\t\t{\"0.9999999999999999\", \"2.718281828459044964\"},\n\t\t\t{\"0.99999999999999999\", \"2.718281828459045208\"},\n\t\t\t{\"0.999999999999999999\", \"2.718281828459045233\"},\n\t\t\t{\"0.9999999999999999999\", \"2.718281828459045235\"},\n\t\t\t{\"1\", E.String()},\n\t\t\t{\"1.000000000000000001\", \"2.718281828459045238\"},\n\t\t\t{\"1.00000000000000001\", \"2.718281828459045263\"},\n\t\t\t{\"1.0000000000000001\", \"2.718281828459045507\"},\n\t\t\t{\"1.000000000000001\", \"2.718281828459047954\"},\n\t\t\t{\"1.00000000000001\", \"2.718281828459072418\"},\n\t\t\t{\"1.0000000000001\", \"2.718281828459317064\"},\n\t\t\t{\"1.000000000001\", \"2.718281828461763517\"},\n\t\t\t{\"1.00000000001\", \"2.718281828486228054\"},\n\t\t\t{\"1.0000000001\", \"2.718281828730873418\"},\n\t\t\t{\"1.000000001\", \"2.718281831177327065\"},\n\t\t\t{\"1.00000001\", \"2.718281855641863656\"},\n\t\t\t{\"1.0000001\", \"2.718282100287241673\"},\n\t\t\t{\"1.000001\", \"2.718284546742232836\"},\n\t\t\t{\"1.00001\", \"2.718309011413244370\"},\n\t\t\t{\"1.0001\", \"2.718553670233753340\"},\n\t\t\t{\"1.001\", \"2.721001469881578766\"},\n\t\t\t{\"1.01\", \"2.745601015016916494\"},\n\t\t\t{\"1.1\", \"3.004166023946433112\"},\n\n\t\t\t// Negated powers of ten\n\t\t\t{\"-10000\", \"0.0000000000000000000\"},\n\t\t\t{\"-1000\", \"0.0000000000000000000\"},\n\t\t\t{\"-100\", \"0.0000000000000000000\"},\n\t\t\t{\"-10\", \"0.00004539992976248489\"},\n\t\t\t{\"-1\", \"0.3678794411714423216\"},\n\t\t\t{\"-0.1\", \"0.9048374180359595732\"},\n\t\t\t{\"-0.01\", \"0.9900498337491680536\"},\n\t\t\t{\"-0.001\", \"0.9990004998333749917\"},\n\t\t\t{\"-0.0001\", \"0.9999000049998333375\"},\n\t\t\t{\"-0.00001\", \"0.9999900000499998333\"},\n\t\t\t{\"-0.000001\", \"0.9999990000004999998\"},\n\t\t\t{\"-0.0000001\", \"0.9999999000000050000\"},\n\t\t\t{\"-0.00000001\", \"0.9999999900000000500\"},\n\t\t\t{\"-0.000000001\", \"0.9999999990000000005\"},\n\t\t\t{\"-0.0000000001\", \"0.9999999999000000000\"},\n\t\t\t{\"-0.00000000001\", \"0.9999999999900000000\"},\n\t\t\t{\"-0.000000000001\", \"0.9999999999990000000\"},\n\t\t\t{\"-0.0000000000001\", \"0.9999999999999000000\"},\n\t\t\t{\"-0.00000000000001\", \"0.9999999999999900000\"},\n\t\t\t{\"-0.000000000000001\", \"0.9999999999999990000\"},\n\t\t\t{\"-0.0000000000000001\", \"0.9999999999999999000\"},\n\t\t\t{\"-0.00000000000000001\", \"0.9999999999999999900\"},\n\t\t\t{\"-0.000000000000000001\", \"0.9999999999999999990\"},\n\t\t\t{\"-0.0000000000000000001\", \"0.9999999999999999999\"},\n\n\t\t\t// Powers of ten\n\t\t\t{\"0.0000000000000000001\", \"1.000000000000000000\"},\n\t\t\t{\"0.000000000000000001\", \"1.000000000000000001\"},\n\t\t\t{\"0.00000000000000001\", \"1.000000000000000010\"},\n\t\t\t{\"0.0000000000000001\", \"1.000000000000000100\"},\n\t\t\t{\"0.000000000000001\", \"1.000000000000001000\"},\n\t\t\t{\"0.00000000000001\", \"1.000000000000010000\"},\n\t\t\t{\"0.0000000000001\", \"1.000000000000100000\"},\n\t\t\t{\"0.000000000001\", \"1.000000000001000000\"},\n\t\t\t{\"0.00000000001\", \"1.000000000010000000\"},\n\t\t\t{\"0.0000000001\", \"1.000000000100000000\"},\n\t\t\t{\"0.000000001\", \"1.000000001000000001\"},\n\t\t\t{\"0.00000001\", \"1.000000010000000050\"},\n\t\t\t{\"0.0000001\", \"1.000000100000005000\"},\n\t\t\t{\"0.000001\", \"1.000001000000500000\"},\n\t\t\t{\"0.00001\", \"1.000010000050000167\"},\n\t\t\t{\"0.0001\", \"1.000100005000166671\"},\n\t\t\t{\"0.001\", \"1.001000500166708342\"},\n\t\t\t{\"0.01\", \"1.010050167084168058\"},\n\t\t\t{\"0.1\", \"1.105170918075647625\"},\n\t\t\t{\"1\", E.String()},\n\t\t\t{\"10\", \"22026.46579480671652\"},\n\n\t\t\t// Logarithms of powers of ten\n\t\t\t{\"-50.65687204586900505\", \"0.0000000000000000000\"},\n\t\t\t{\"-48.35428695287495936\", \"0.0000000000000000000\"},\n\t\t\t{\"-46.05170185988091368\", \"0.0000000000000000000\"},\n\t\t\t{\"-43.74911676688686799\", \"0.0000000000000000001\"},\n\t\t\t{\"-41.44653167389282231\", \"0.0000000000000000010\"},\n\t\t\t{\"-39.14394658089877663\", \"0.0000000000000000100\"},\n\t\t\t{\"-36.84136148790473094\", \"0.0000000000000001000\"},\n\t\t\t{\"-34.53877639491068526\", \"0.0000000000000010000\"},\n\t\t\t{\"-32.23619130191663958\", \"0.0000000000000100000\"},\n\t\t\t{\"-29.93360620892259389\", \"0.0000000000001000000\"},\n\t\t\t{\"-27.63102111592854821\", \"0.0000000000010000000\"},\n\t\t\t{\"-25.32843602293450252\", \"0.0000000000100000000\"},\n\t\t\t{\"-23.02585092994045684\", \"0.0000000001000000000\"},\n\t\t\t{\"-20.72326583694641116\", \"0.0000000010000000000\"},\n\t\t\t{\"-18.42068074395236547\", \"0.0000000100000000000\"},\n\t\t\t{\"-16.11809565095831979\", \"0.0000001000000000000\"},\n\t\t\t{\"-13.81551055796427410\", \"0.0000010000000000000\"},\n\t\t\t{\"-11.51292546497022842\", \"0.0000100000000000000\"},\n\t\t\t{\"-9.210340371976182736\", \"0.0001000000000000000\"},\n\t\t\t{\"-6.907755278982137052\", \"0.0010000000000000000\"},\n\t\t\t{\"-4.605170185988091368\", \"0.0100000000000000000\"},\n\t\t\t{\"-2.302585092994045684\", \"0.1000000000000000000\"},\n\t\t\t{\"0\", \"1\"},\n\t\t\t{\"2.302585092994045684\", \"10.00000000000000000\"},\n\t\t\t{\"4.605170185988091368\", \"100.0000000000000000\"},\n\t\t\t{\"6.907755278982137052\", \"999.9999999999999999\"},\n\t\t\t{\"9.210340371976182736\", \"9999.999999999999999\"},\n\t\t\t{\"11.51292546497022842\", \"99999.99999999999999\"},\n\t\t\t{\"13.81551055796427410\", \"999999.9999999999959\"},\n\t\t\t{\"16.11809565095831979\", \"10000000.00000000002\"},\n\t\t\t{\"18.42068074395236547\", \"99999999.99999999979\"},\n\t\t\t{\"20.72326583694641116\", \"1000000000.000000004\"},\n\t\t\t{\"23.02585092994045684\", \"9999999999.999999998\"},\n\t\t\t{\"25.32843602293450252\", \"99999999999.99999958\"},\n\t\t\t{\"27.63102111592854821\", \"1000000000000.000002\"},\n\t\t\t{\"29.93360620892259389\", \"9999999999999.999978\"},\n\t\t\t{\"32.23619130191663958\", \"100000000000000.0004\"},\n\t\t\t{\"34.53877639491068526\", \"999999999999999.9997\"},\n\t\t\t{\"36.84136148790473094\", \"9999999999999999.957\"},\n\t\t\t{\"39.14394658089877663\", \"100000000000000000.2\"},\n\t\t\t{\"41.44653167389282231\", \"999999999999999997.7\"},\n\t\t\t{\"43.74911676688686799\", \"9999999999999999937\"},\n\n\t\t\t// Negative numbers\n\t\t\t{\"-101\", \"0.0000000000000000000\"},\n\t\t\t{\"-100\", \"0.0000000000000000000\"},\n\t\t\t{\"-99\", \"0.0000000000000000000\"},\n\t\t\t{\"-50\", \"0.0000000000000000000\"},\n\t\t\t{\"-45\", \"0.0000000000000000000\"},\n\t\t\t{\"-44\", \"0.0000000000000000001\"},\n\t\t\t{\"-43\", \"0.0000000000000000002\"},\n\n\t\t\t// Natural numbers\n\t\t\t{\"1\", E.String()},\n\t\t\t{\"2\", \"7.389056098930650227\"},\n\t\t\t{\"3\", \"20.08553692318766774\"},\n\t\t\t{\"4\", \"54.59815003314423908\"},\n\t\t\t{\"5\", \"148.4131591025766034\"},\n\t\t\t{\"6\", \"403.4287934927351226\"},\n\t\t\t{\"7\", \"1096.633158428458599\"},\n\t\t\t{\"8\", \"2980.957987041728275\"},\n\t\t\t{\"9\", \"8103.083927575384008\"},\n\t\t\t{\"10\", \"22026.46579480671652\"},\n\t\t\t{\"11\", \"59874.14171519781846\"},\n\t\t\t{\"12\", \"162754.7914190039208\"},\n\t\t\t{\"13\", \"442413.3920089205033\"},\n\t\t\t{\"14\", \"1202604.284164776778\"},\n\t\t\t{\"15\", \"3269017.372472110639\"},\n\t\t\t{\"16\", \"8886110.520507872637\"},\n\t\t\t{\"17\", \"24154952.75357529821\"},\n\t\t\t{\"18\", \"65659969.13733051114\"},\n\t\t\t{\"19\", \"178482300.9631872608\"},\n\t\t\t{\"20\", \"485165195.4097902780\"},\n\t\t\t{\"21\", \"1318815734.483214697\"},\n\t\t\t{\"22\", \"3584912846.131591562\"},\n\t\t\t{\"23\", \"9744803446.248902600\"},\n\t\t\t{\"24\", \"26489122129.84347229\"},\n\t\t\t{\"25\", \"72004899337.38587252\"},\n\t\t\t{\"26\", \"195729609428.8387643\"},\n\t\t\t{\"27\", \"532048240601.7986167\"},\n\t\t\t{\"28\", \"1446257064291.475174\"},\n\t\t\t{\"29\", \"3931334297144.042074\"},\n\t\t\t{\"30\", \"10686474581524.46215\"},\n\t\t\t{\"31\", \"29048849665247.42523\"},\n\t\t\t{\"32\", \"78962960182680.69516\"},\n\t\t\t{\"33\", \"214643579785916.0646\"},\n\t\t\t{\"34\", \"583461742527454.8814\"},\n\t\t\t{\"35\", \"1586013452313430.728\"},\n\t\t\t{\"36\", \"4311231547115195.227\"},\n\t\t\t{\"37\", \"11719142372802611.31\"},\n\t\t\t{\"38\", \"31855931757113756.22\"},\n\t\t\t{\"39\", \"86593400423993746.95\"},\n\t\t\t{\"40\", \"235385266837019985.4\"},\n\t\t\t{\"41\", \"639843493530054949.2\"},\n\t\t\t{\"42\", \"1739274941520501047\"},\n\t\t\t{\"43\", \"4727839468229346561\"},\n\n\t\t\t// Captured during fuzzing\n\t\t\t{\"-2.999999999999999852\", \"0.0497870683678639503\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\tgot, err := d.Exp()\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.Exp() failed: %v\", d, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"%q.Exp() = %q, want %q\", d, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]string{\n\t\t\t\"overflow 1\": \"49\",\n\t\t\t\"overflow 2\": \"50\",\n\t\t}\n\t\tfor name, d := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\td := MustParse(d)\n\t\t\t\t_, err := d.Exp()\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"%q.Exp() did not fail\", d)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestDecimal_Expm1(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, want string\n\t\t}{\n\t\t\t// Zeros\n\t\t\t{\"0\", \"0\"},\n\t\t\t{\"0.0\", \"0\"},\n\t\t\t{\"0.00\", \"0\"},\n\t\t\t{\"0.000\", \"0\"},\n\t\t\t{\"0.0000\", \"0\"},\n\t\t\t{\"0.00000\", \"0\"},\n\n\t\t\t// Ones\n\t\t\t{\"1\", \"1.718281828459045235\"},\n\t\t\t{\"1.0\", \"1.718281828459045235\"},\n\t\t\t{\"1.00\", \"1.718281828459045235\"},\n\t\t\t{\"1.000\", \"1.718281828459045235\"},\n\t\t\t{\"1.0000\", \"1.718281828459045235\"},\n\t\t\t{\"1.00000\", \"1.718281828459045235\"},\n\n\t\t\t// Closer and closer to negative one\n\t\t\t{\"-0.9\", \"-0.5934303402594008881\"},\n\t\t\t{\"-0.99\", \"-0.6284233089779543095\"},\n\t\t\t{\"-0.999\", \"-0.6317524953863370788\"},\n\t\t\t{\"-0.9999\", \"-0.6320837690449820135\"},\n\t\t\t{\"-0.99999\", \"-0.6321168800157519306\"},\n\t\t\t{\"-0.999999\", \"-0.6321201909489325672\"},\n\t\t\t{\"-0.9999999\", \"-0.6321205220406117219\"},\n\t\t\t{\"-0.99999999\", \"-0.6321205551497632483\"},\n\t\t\t{\"-0.999999999\", \"-0.6321205584606782370\"},\n\t\t\t{\"-0.9999999999\", \"-0.6321205587917697343\"},\n\t\t\t{\"-0.99999999999\", \"-0.6321205588248788840\"},\n\t\t\t{\"-0.999999999999\", \"-0.6321205588281897990\"},\n\t\t\t{\"-0.9999999999999\", \"-0.6321205588285208905\"},\n\t\t\t{\"-0.99999999999999\", \"-0.6321205588285539996\"},\n\t\t\t{\"-0.999999999999999\", \"-0.6321205588285573105\"},\n\t\t\t{\"-0.9999999999999999\", \"-0.6321205588285576416\"},\n\t\t\t{\"-0.99999999999999999\", \"-0.6321205588285576747\"},\n\t\t\t{\"-0.999999999999999999\", \"-0.6321205588285576780\"},\n\t\t\t{\"-1\", \"-0.6321205588285576784\"},\n\t\t\t{\"-1.000000000000000001\", \"-0.6321205588285576788\"},\n\t\t\t{\"-1.00000000000000001\", \"-0.6321205588285576821\"},\n\t\t\t{\"-1.0000000000000001\", \"-0.6321205588285577152\"},\n\t\t\t{\"-1.000000000000001\", \"-0.6321205588285580463\"},\n\t\t\t{\"-1.00000000000001\", \"-0.6321205588285613572\"},\n\t\t\t{\"-1.0000000000001\", \"-0.6321205588285944663\"},\n\t\t\t{\"-1.000000000001\", \"-0.6321205588289255578\"},\n\t\t\t{\"-1.00000000001\", \"-0.6321205588322364728\"},\n\t\t\t{\"-1.0000000001\", \"-0.6321205588653456225\"},\n\t\t\t{\"-1.000000001\", \"-0.6321205591964371194\"},\n\t\t\t{\"-1.00000001\", \"-0.6321205625073520717\"},\n\t\t\t{\"-1.0000001\", \"-0.6321205956164999562\"},\n\t\t\t{\"-1.000001\", \"-0.6321209267078149102\"},\n\t\t\t{\"-1.00001\", \"-0.6321242376045754821\"},\n\t\t\t{\"-1.0001\", \"-0.6321573449333389285\"},\n\t\t\t{\"-1.001\", \"-0.6324882543913064500\"},\n\t\t\t{\"-1.01\", \"-0.6357810204284766802\"},\n\t\t\t{\"-1.1\", \"-0.6671289163019204467\"},\n\n\t\t\t// Closer and closer to zero\n\t\t\t{\"-0.1\", \"-0.0951625819640404268\"},\n\t\t\t{\"-0.01\", \"-0.0099501662508319464\"},\n\t\t\t{\"-0.001\", \"-0.0009995001666250083\"},\n\t\t\t{\"-0.0001\", \"-0.0000999950001666625\"},\n\t\t\t{\"-0.00001\", \"-0.0000099999500001667\"},\n\t\t\t{\"-0.000001\", \"-0.0000009999995000002\"},\n\t\t\t{\"-0.0000001\", \"-0.0000000999999950000\"},\n\t\t\t{\"-0.00000001\", \"-0.0000000099999999500\"},\n\t\t\t{\"-0.000000001\", \"-0.0000000009999999995\"},\n\t\t\t{\"-0.0000000001\", \"-0.0000000001000000000\"},\n\t\t\t{\"-0.00000000001\", \"-0.0000000000100000000\"},\n\t\t\t{\"-0.000000000001\", \"-0.0000000000010000000\"},\n\t\t\t{\"-0.0000000000001\", \"-0.0000000000001000000\"},\n\t\t\t{\"-0.00000000000001\", \"-0.0000000000000100000\"},\n\t\t\t{\"-0.000000000000001\", \"-0.0000000000000010000\"},\n\t\t\t{\"-0.0000000000000001\", \"-0.0000000000000001000\"},\n\t\t\t{\"-0.00000000000000001\", \"-0.0000000000000000100\"},\n\t\t\t{\"-0.000000000000000001\", \"-0.0000000000000000010\"},\n\t\t\t{\"-0.0000000000000000001\", \"-0.0000000000000000001\"},\n\t\t\t{\"0\", \"0\"},\n\t\t\t{\"0.0000000000000000001\", \"0.0000000000000000001\"},\n\t\t\t{\"0.000000000000000001\", \"0.0000000000000000010\"},\n\t\t\t{\"0.00000000000000001\", \"0.0000000000000000100\"},\n\t\t\t{\"0.0000000000000001\", \"0.0000000000000001000\"},\n\t\t\t{\"0.000000000000001\", \"0.0000000000000010000\"},\n\t\t\t{\"0.00000000000001\", \"0.0000000000000100000\"},\n\t\t\t{\"0.0000000000001\", \"0.0000000000001000000\"},\n\t\t\t{\"0.000000000001\", \"0.0000000000010000000\"},\n\t\t\t{\"0.00000000001\", \"0.0000000000100000000\"},\n\t\t\t{\"0.0000000001\", \"0.0000000001000000000\"},\n\t\t\t{\"0.000000001\", \"0.0000000010000000005\"},\n\t\t\t{\"0.00000001\", \"0.0000000100000000500\"},\n\t\t\t{\"0.0000001\", \"0.0000001000000050000\"},\n\t\t\t{\"0.000001\", \"0.0000010000005000002\"},\n\t\t\t{\"0.00001\", \"0.0000100000500001667\"},\n\t\t\t{\"0.0001\", \"0.0001000050001666708\"},\n\t\t\t{\"0.001\", \"0.0010005001667083417\"},\n\t\t\t{\"0.01\", \"0.0100501670841680575\"},\n\t\t\t{\"0.1\", \"0.1051709180756476248\"},\n\n\t\t\t// Closer and closer to one\n\t\t\t{\"0.9\", \"1.459603111156949664\"},\n\t\t\t{\"0.99\", \"1.691234472349262289\"},\n\t\t\t{\"0.999\", \"1.715564905318566687\"},\n\t\t\t{\"0.9999\", \"1.718010013867155437\"},\n\t\t\t{\"0.99999\", \"1.718254645776674283\"},\n\t\t\t{\"0.999999\", \"1.718279110178575917\"},\n\t\t\t{\"0.9999999\", \"1.718281556630875981\"},\n\t\t\t{\"0.99999999\", \"1.718281801276227087\"},\n\t\t\t{\"0.999999999\", \"1.718281825740763408\"},\n\t\t\t{\"0.9999999999\", \"1.718281828187217053\"},\n\t\t\t{\"0.99999999999\", \"1.718281828431862417\"},\n\t\t\t{\"0.999999999999\", \"1.718281828456326954\"},\n\t\t\t{\"0.9999999999999\", \"1.718281828458773407\"},\n\t\t\t{\"0.99999999999999\", \"1.718281828459018053\"},\n\t\t\t{\"0.999999999999999\", \"1.718281828459042517\"},\n\t\t\t{\"0.9999999999999999\", \"1.718281828459044964\"},\n\t\t\t{\"0.99999999999999999\", \"1.718281828459045208\"},\n\t\t\t{\"0.999999999999999999\", \"1.718281828459045233\"},\n\t\t\t{\"0.9999999999999999999\", \"1.718281828459045235\"},\n\t\t\t{\"1\", \"1.718281828459045235\"},\n\t\t\t{\"1.000000000000000001\", \"1.718281828459045238\"},\n\t\t\t{\"1.00000000000000001\", \"1.718281828459045263\"},\n\t\t\t{\"1.0000000000000001\", \"1.718281828459045507\"},\n\t\t\t{\"1.000000000000001\", \"1.718281828459047954\"},\n\t\t\t{\"1.00000000000001\", \"1.718281828459072418\"},\n\t\t\t{\"1.0000000000001\", \"1.718281828459317064\"},\n\t\t\t{\"1.000000000001\", \"1.718281828461763517\"},\n\t\t\t{\"1.00000000001\", \"1.718281828486228054\"},\n\t\t\t{\"1.0000000001\", \"1.718281828730873418\"},\n\t\t\t{\"1.000000001\", \"1.718281831177327065\"},\n\t\t\t{\"1.00000001\", \"1.718281855641863656\"},\n\t\t\t{\"1.0000001\", \"1.718282100287241673\"},\n\t\t\t{\"1.000001\", \"1.718284546742232836\"},\n\t\t\t{\"1.00001\", \"1.718309011413244370\"},\n\t\t\t{\"1.0001\", \"1.718553670233753340\"},\n\t\t\t{\"1.001\", \"1.721001469881578766\"},\n\t\t\t{\"1.01\", \"1.745601015016916494\"},\n\t\t\t{\"1.1\", \"2.004166023946433112\"},\n\n\t\t\t// Negated powers of ten\n\t\t\t{\"-10000\", \"-1.000000000000000000\"},\n\t\t\t{\"-1000\", \"-1.000000000000000000\"},\n\t\t\t{\"-100\", \"-1.000000000000000000\"},\n\t\t\t{\"-10\", \"-0.9999546000702375151\"},\n\t\t\t{\"-1\", \"-0.6321205588285576784\"},\n\t\t\t{\"-0.1\", \"-0.0951625819640404268\"},\n\t\t\t{\"-0.01\", \"-0.0099501662508319464\"},\n\t\t\t{\"-0.001\", \"-0.0009995001666250083\"},\n\t\t\t{\"-0.0001\", \"-0.0000999950001666625\"},\n\t\t\t{\"-0.00001\", \"-0.0000099999500001667\"},\n\t\t\t{\"-0.000001\", \"-0.0000009999995000002\"},\n\t\t\t{\"-0.0000001\", \"-0.0000000999999950000\"},\n\t\t\t{\"-0.00000001\", \"-0.0000000099999999500\"},\n\t\t\t{\"-0.000000001\", \"-0.0000000009999999995\"},\n\t\t\t{\"-0.0000000001\", \"-0.0000000001000000000\"},\n\t\t\t{\"-0.00000000001\", \"-0.0000000000100000000\"},\n\t\t\t{\"-0.000000000001\", \"-0.0000000000010000000\"},\n\t\t\t{\"-0.0000000000001\", \"-0.0000000000001000000\"},\n\t\t\t{\"-0.00000000000001\", \"-0.0000000000000100000\"},\n\t\t\t{\"-0.000000000000001\", \"-0.0000000000000010000\"},\n\t\t\t{\"-0.0000000000000001\", \"-0.0000000000000001000\"},\n\t\t\t{\"-0.00000000000000001\", \"-0.0000000000000000100\"},\n\t\t\t{\"-0.000000000000000001\", \"-0.0000000000000000010\"},\n\t\t\t{\"-0.0000000000000000001\", \"-0.0000000000000000001\"},\n\n\t\t\t// Powers of ten\n\t\t\t{\"0.0000000000000000001\", \"0.0000000000000000001\"},\n\t\t\t{\"0.000000000000000001\", \"0.0000000000000000010\"},\n\t\t\t{\"0.00000000000000001\", \"0.0000000000000000100\"},\n\t\t\t{\"0.0000000000000001\", \"0.0000000000000001000\"},\n\t\t\t{\"0.000000000000001\", \"0.0000000000000010000\"},\n\t\t\t{\"0.00000000000001\", \"0.0000000000000100000\"},\n\t\t\t{\"0.0000000000001\", \"0.0000000000001000000\"},\n\t\t\t{\"0.000000000001\", \"0.0000000000010000000\"},\n\t\t\t{\"0.00000000001\", \"0.0000000000100000000\"},\n\t\t\t{\"0.0000000001\", \"0.0000000001000000000\"},\n\t\t\t{\"0.000000001\", \"0.0000000010000000005\"},\n\t\t\t{\"0.00000001\", \"0.0000000100000000500\"},\n\t\t\t{\"0.0000001\", \"0.0000001000000050000\"},\n\t\t\t{\"0.000001\", \"0.0000010000005000002\"},\n\t\t\t{\"0.00001\", \"0.0000100000500001667\"},\n\t\t\t{\"0.0001\", \"0.0001000050001666708\"},\n\t\t\t{\"0.001\", \"0.0010005001667083417\"},\n\t\t\t{\"0.01\", \"0.0100501670841680575\"},\n\t\t\t{\"0.1\", \"0.1051709180756476248\"},\n\t\t\t{\"1\", \"1.718281828459045235\"},\n\t\t\t{\"10\", \"22025.46579480671652\"},\n\n\t\t\t// Negative numbers\n\t\t\t{\"-101\", \"-1.000000000000000000\"},\n\t\t\t{\"-100\", \"-1.000000000000000000\"},\n\t\t\t{\"-99\", \"-1.000000000000000000\"},\n\t\t\t{\"-50\", \"-1.000000000000000000\"},\n\t\t\t{\"-45\", \"-1.000000000000000000\"},\n\t\t\t{\"-44\", \"-0.9999999999999999999\"},\n\t\t\t{\"-43\", \"-0.9999999999999999998\"},\n\n\t\t\t// Natural numbers\n\t\t\t{\"1\", \"1.718281828459045235\"},\n\t\t\t{\"2\", \"6.389056098930650227\"},\n\t\t\t{\"3\", \"19.08553692318766774\"},\n\t\t\t{\"4\", \"53.59815003314423908\"},\n\t\t\t{\"5\", \"147.4131591025766034\"},\n\t\t\t{\"6\", \"402.4287934927351226\"},\n\t\t\t{\"7\", \"1095.633158428458599\"},\n\t\t\t{\"8\", \"2979.957987041728275\"},\n\t\t\t{\"9\", \"8102.083927575384008\"},\n\t\t\t{\"10\", \"22025.46579480671652\"},\n\t\t\t{\"11\", \"59873.14171519781846\"},\n\t\t\t{\"12\", \"162753.7914190039208\"},\n\t\t\t{\"13\", \"442412.3920089205033\"},\n\t\t\t{\"14\", \"1202603.284164776778\"},\n\t\t\t{\"15\", \"3269016.372472110639\"},\n\t\t\t{\"16\", \"8886109.520507872637\"},\n\t\t\t{\"17\", \"24154951.75357529821\"},\n\t\t\t{\"18\", \"65659968.13733051114\"},\n\t\t\t{\"19\", \"178482299.9631872608\"},\n\t\t\t{\"20\", \"485165194.4097902780\"},\n\t\t\t{\"21\", \"1318815733.483214697\"},\n\t\t\t{\"22\", \"3584912845.131591562\"},\n\t\t\t{\"23\", \"9744803445.248902600\"},\n\t\t\t{\"24\", \"26489122128.84347229\"},\n\t\t\t{\"25\", \"72004899336.38587252\"},\n\t\t\t{\"26\", \"195729609427.8387643\"},\n\t\t\t{\"27\", \"532048240600.7986167\"},\n\t\t\t{\"28\", \"1446257064290.475174\"},\n\t\t\t{\"29\", \"3931334297143.042074\"},\n\t\t\t{\"30\", \"10686474581523.46215\"},\n\t\t\t{\"31\", \"29048849665246.42523\"},\n\t\t\t{\"32\", \"78962960182679.69516\"},\n\t\t\t{\"33\", \"214643579785915.0646\"},\n\t\t\t{\"34\", \"583461742527453.8814\"},\n\t\t\t{\"35\", \"1586013452313429.728\"},\n\t\t\t{\"36\", \"4311231547115194.227\"},\n\t\t\t{\"37\", \"11719142372802610.31\"},\n\t\t\t{\"38\", \"31855931757113755.22\"},\n\t\t\t{\"39\", \"86593400423993745.95\"},\n\t\t\t{\"40\", \"235385266837019984.4\"},\n\t\t\t{\"41\", \"639843493530054948.2\"},\n\t\t\t{\"42\", \"1739274941520501046\"},\n\t\t\t{\"43\", \"4727839468229346560\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\tgot, err := d.Expm1()\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.Expm1() failed: %v\", d, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"%q.Expm1() = %q, want %q\", d, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]string{\n\t\t\t\"overflow 1\": \"49\",\n\t\t\t\"overflow 2\": \"50\",\n\t\t}\n\t\tfor name, d := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\td := MustParse(d)\n\t\t\t\t_, err := d.Expm1()\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"%q.Expm1() did not fail\", d)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestDecimal_Log(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, want string\n\t\t}{\n\t\t\t// Ones\n\t\t\t{\"1\", \"0\"},\n\t\t\t{\"1.0\", \"0\"},\n\t\t\t{\"1.00\", \"0\"},\n\t\t\t{\"1.000\", \"0\"},\n\n\t\t\t// Powers of Euler's number\n\t\t\t{\"0.0000000000000000002\", \"-43.05596958632692269\"},\n\t\t\t{\"0.0000000000000000006\", \"-41.95735729765881300\"},\n\t\t\t{\"0.0000000000000000016\", \"-40.97652804464708676\"},\n\t\t\t{\"0.0000000000000000042\", \"-40.01144714860349969\"},\n\t\t\t{\"0.0000000000000000115\", \"-39.00418463852361793\"},\n\t\t\t{\"0.0000000000000000314\", \"-37.99972378097861463\"},\n\t\t\t{\"0.0000000000000000853\", \"-37.00035721939518888\"},\n\t\t\t{\"0.0000000000000002320\", \"-35.99979430222651236\"},\n\t\t\t{\"0.0000000000000006305\", \"-35.00001851848784806\"},\n\t\t\t{\"0.0000000000000017139\", \"-34.00000491949429577\"},\n\t\t\t{\"0.0000000000000046589\", \"-32.99999702613981757\"},\n\t\t\t{\"0.0000000000000126642\", \"-31.99999727965819527\"},\n\t\t\t{\"0.0000000000000344248\", \"-30.99999916004414320\"},\n\t\t\t{\"0.0000000000000935762\", \"-30.00000031726440095\"},\n\t\t\t{\"0.0000000000002543666\", \"-28.99999986137208992\"},\n\t\t\t{\"0.0000000000006914400\", \"-28.00000001546630253\"},\n\t\t\t{\"0.0000000000018795288\", \"-27.00000000879959021\"},\n\t\t\t{\"0.0000000000051090890\", \"-26.00000000549282360\"},\n\t\t\t{\"0.0000000000138879439\", \"-24.99999999747723783\"},\n\t\t\t{\"0.0000000000377513454\", \"-24.00000000113349543\"},\n\t\t\t{\"0.0000000001026187963\", \"-23.00000000016584587\"},\n\t\t\t{\"0.0000000002789468093\", \"-21.99999999995301069\"},\n\t\t\t{\"0.0000000007582560428\", \"-20.99999999998838212\"},\n\t\t\t{\"0.0000000020611536224\", \"-20.00000000001870692\"},\n\t\t\t{\"0.0000000056027964375\", \"-19.00000000000665160\"},\n\t\t\t{\"0.0000000152299797447\", \"-18.00000000000082918\"},\n\t\t\t{\"0.0000000413993771879\", \"-16.99999999999883251\"},\n\t\t\t{\"0.0000001125351747193\", \"-15.99999999999963669\"},\n\t\t\t{\"0.0000003059023205018\", \"-15.00000000000008430\"},\n\t\t\t{\"0.0000008315287191036\", \"-13.99999999999996138\"},\n\t\t\t{\"0.0000022603294069811\", \"-12.99999999999997979\"},\n\t\t\t{\"0.0000061442123533282\", \"-12.00000000000000159\"},\n\t\t\t{\"0.0000167017007902457\", \"-10.99999999999999756\"},\n\t\t\t{\"0.0000453999297624849\", \"-9.999999999999998933\"},\n\t\t\t{\"0.0001234098040866795\", \"-9.000000000000000401\"},\n\t\t\t{\"0.0003354626279025118\", \"-8.000000000000000116\"},\n\t\t\t{\"0.0009118819655545162\", \"-7.000000000000000009\"},\n\t\t\t{\"0.0024787521766663584\", \"-6.000000000000000009\"},\n\t\t\t{\"0.0067379469990854671\", \"-5.000000000000000000\"},\n\t\t\t{\"0.0183156388887341803\", \"-4.000000000000000000\"},\n\t\t\t{\"0.0497870683678639430\", \"-3.000000000000000000\"},\n\t\t\t{\"0.1353352832366126919\", \"-2.000000000000000000\"},\n\t\t\t{\"0.3678794411714423216\", \"-1.000000000000000000\"},\n\t\t\t{\"1\", \"0\"},\n\t\t\t{E.String(), \"0.9999999999999999999\"},\n\t\t\t{\"7.389056098930650227\", \"2.000000000000000000\"},\n\t\t\t{\"20.08553692318766774\", \"3.000000000000000000\"},\n\t\t\t{\"54.59815003314423908\", \"4.000000000000000000\"},\n\t\t\t{\"148.4131591025766034\", \"5.000000000000000000\"},\n\t\t\t{\"403.4287934927351226\", \"6.000000000000000000\"},\n\t\t\t{\"1096.633158428458599\", \"7.000000000000000000\"},\n\t\t\t{\"2980.957987041728275\", \"8.000000000000000000\"},\n\t\t\t{\"8103.083927575384008\", \"9.000000000000000000\"},\n\t\t\t{\"22026.46579480671652\", \"10.00000000000000000\"},\n\t\t\t{\"59874.14171519781846\", \"11.00000000000000000\"},\n\t\t\t{\"162754.7914190039208\", \"12.00000000000000000\"},\n\t\t\t{\"442413.3920089205033\", \"13.00000000000000000\"},\n\t\t\t{\"1202604.284164776778\", \"14.00000000000000000\"},\n\t\t\t{\"3269017.372472110639\", \"15.00000000000000000\"},\n\t\t\t{\"8886110.520507872637\", \"16.00000000000000000\"},\n\t\t\t{\"24154952.75357529821\", \"17.00000000000000000\"},\n\t\t\t{\"65659969.13733051114\", \"18.00000000000000000\"},\n\t\t\t{\"178482300.9631872608\", \"19.00000000000000000\"},\n\t\t\t{\"485165195.4097902780\", \"20.00000000000000000\"},\n\t\t\t{\"1318815734.483214697\", \"21.00000000000000000\"},\n\t\t\t{\"3584912846.131591562\", \"22.00000000000000000\"},\n\t\t\t{\"9744803446.248902600\", \"23.00000000000000000\"},\n\t\t\t{\"26489122129.84347229\", \"24.00000000000000000\"},\n\t\t\t{\"72004899337.38587252\", \"25.00000000000000000\"},\n\t\t\t{\"195729609428.8387643\", \"26.00000000000000000\"},\n\t\t\t{\"532048240601.7986167\", \"27.00000000000000000\"},\n\t\t\t{\"1446257064291.475174\", \"28.00000000000000000\"},\n\t\t\t{\"3931334297144.042074\", \"29.00000000000000000\"},\n\t\t\t{\"10686474581524.46215\", \"30.00000000000000000\"},\n\t\t\t{\"29048849665247.42523\", \"31.00000000000000000\"},\n\t\t\t{\"78962960182680.69516\", \"32.00000000000000000\"},\n\t\t\t{\"214643579785916.0646\", \"33.00000000000000000\"},\n\t\t\t{\"583461742527454.8814\", \"34.00000000000000000\"},\n\t\t\t{\"1586013452313430.728\", \"35.00000000000000000\"},\n\t\t\t{\"4311231547115195.227\", \"36.00000000000000000\"},\n\t\t\t{\"11719142372802611.31\", \"37.00000000000000000\"},\n\t\t\t{\"31855931757113756.22\", \"38.00000000000000000\"},\n\t\t\t{\"86593400423993746.95\", \"39.00000000000000000\"},\n\t\t\t{\"235385266837019985.4\", \"40.00000000000000000\"},\n\t\t\t{\"639843493530054949.2\", \"41.00000000000000000\"},\n\t\t\t{\"1739274941520501047\", \"42.00000000000000000\"},\n\t\t\t{\"4727839468229346561\", \"43.00000000000000000\"},\n\n\t\t\t// Closer and closer to Euler's number\n\t\t\t{\"2.7\", \"0.9932517730102833902\"},\n\t\t\t{\"2.71\", \"0.9969486348916095321\"},\n\t\t\t{\"2.718\", \"0.9998963157289519689\"},\n\t\t\t{\"2.7182\", \"0.9999698965391098865\"},\n\t\t\t{\"2.71828\", \"0.9999993273472820032\"},\n\t\t\t{\"2.718281\", \"0.9999996952269029621\"},\n\t\t\t{\"2.7182818\", \"0.9999999895305022877\"},\n\t\t\t{\"2.71828182\", \"0.9999999968880911611\"},\n\t\t\t{\"2.718281828\", \"0.9999999998311266953\"},\n\t\t\t{\"2.7182818284\", \"0.9999999999782784718\"},\n\t\t\t{\"2.71828182845\", \"0.9999999999966724439\"},\n\t\t\t{\"2.718281828459\", \"0.9999999999999833588\"},\n\t\t\t{\"2.7182818284590\", \"0.9999999999999833588\"},\n\t\t\t{\"2.71828182845904\", \"0.9999999999999980740\"},\n\t\t\t{\"2.718281828459045\", \"0.9999999999999999134\"},\n\t\t\t{\"2.7182818284590452\", \"0.9999999999999999870\"},\n\t\t\t{\"2.71828182845904523\", \"0.9999999999999999980\"},\n\t\t\t{\"2.718281828459045234\", \"0.9999999999999999995\"},\n\t\t\t{E.String(), \"0.9999999999999999999\"},\n\t\t\t{\"2.718281828459045236\", \"1.000000000000000000\"},\n\t\t\t{\"2.71828182845904524\", \"1.000000000000000002\"},\n\t\t\t{\"2.7182818284590453\", \"1.000000000000000024\"},\n\t\t\t{\"2.718281828459046\", \"1.000000000000000281\"},\n\t\t\t{\"2.71828182845905\", \"1.000000000000001753\"},\n\t\t\t{\"2.7182818284591\", \"1.000000000000020147\"},\n\t\t\t{\"2.718281828460\", \"1.000000000000351238\"},\n\t\t\t{\"2.71828182846\", \"1.000000000000351238\"},\n\t\t\t{\"2.7182818285\", \"1.000000000015066416\"},\n\t\t\t{\"2.718281829\", \"1.000000000199006136\"},\n\t\t\t{\"2.71828183\", \"1.000000000566885578\"},\n\t\t\t{\"2.7182819\", \"1.000000026318446113\"},\n\t\t\t{\"2.718282\", \"1.000000063106388586\"},\n\t\t\t{\"2.71829\", \"1.000003006137401513\"},\n\t\t\t{\"2.7183\", \"1.000006684913987575\"},\n\t\t\t{\"2.719\", \"1.000264165650333661\"},\n\t\t\t{\"2.72\", \"1.000631880307905950\"},\n\t\t\t{\"2.8\", \"1.029619417181158240\"},\n\n\t\t\t// Closer and closer to one\n\t\t\t{\"0.9\", \"-0.1053605156578263012\"},\n\t\t\t{\"0.99\", \"-0.0100503358535014412\"},\n\t\t\t{\"0.999\", \"-0.0010005003335835335\"},\n\t\t\t{\"0.9999\", \"-0.0001000050003333583\"},\n\t\t\t{\"0.99999\", \"-0.0000100000500003333\"},\n\t\t\t{\"0.999999\", \"-0.0000010000005000003\"},\n\t\t\t{\"0.9999999\", \"-0.0000001000000050000\"},\n\t\t\t{\"0.99999999\", \"-0.0000000100000000500\"},\n\t\t\t{\"0.999999999\", \"-0.0000000010000000005\"},\n\t\t\t{\"0.9999999999\", \"-0.0000000001000000000\"},\n\t\t\t{\"0.99999999999\", \"-0.0000000000100000000\"},\n\t\t\t{\"0.999999999999\", \"-0.0000000000010000000\"},\n\t\t\t{\"0.9999999999999\", \"-0.0000000000001000000\"},\n\t\t\t{\"0.99999999999999\", \"-0.0000000000000100000\"},\n\t\t\t{\"0.999999999999999\", \"-0.0000000000000010000\"},\n\t\t\t{\"0.9999999999999999\", \"-0.0000000000000001000\"},\n\t\t\t{\"0.99999999999999999\", \"-0.0000000000000000100\"},\n\t\t\t{\"0.999999999999999999\", \"-0.0000000000000000010\"},\n\t\t\t{\"0.9999999999999999999\", \"-0.0000000000000000001\"},\n\t\t\t{\"1\", \"0\"},\n\t\t\t{\"1.000000000000000001\", \"0.0000000000000000010\"},\n\t\t\t{\"1.00000000000000001\", \"0.0000000000000000100\"},\n\t\t\t{\"1.0000000000000001\", \"0.0000000000000001000\"},\n\t\t\t{\"1.000000000000001\", \"0.0000000000000010000\"},\n\t\t\t{\"1.00000000000001\", \"0.0000000000000100000\"},\n\t\t\t{\"1.0000000000001\", \"0.0000000000001000000\"},\n\t\t\t{\"1.000000000001\", \"0.0000000000010000000\"},\n\t\t\t{\"1.00000000001\", \"0.0000000000100000000\"},\n\t\t\t{\"1.0000000001\", \"0.0000000001000000000\"},\n\t\t\t{\"1.000000001\", \"0.0000000009999999995\"},\n\t\t\t{\"1.00000001\", \"0.0000000099999999500\"},\n\t\t\t{\"1.0000001\", \"0.0000000999999950000\"},\n\t\t\t{\"1.000001\", \"0.0000009999995000003\"},\n\t\t\t{\"1.00001\", \"0.0000099999500003333\"},\n\t\t\t{\"1.0001\", \"0.0000999950003333083\"},\n\t\t\t{\"1.001\", \"0.0009995003330835332\"},\n\t\t\t{\"1.01\", \"0.0099503308531680828\"},\n\t\t\t{\"1.1\", \"0.0953101798043248600\"},\n\n\t\t\t// Closer and closer to zero\n\t\t\t{\"0.0000000000000000001\", \"-43.74911676688686800\"},\n\t\t\t{\"0.000000000000000001\", \"-41.44653167389282231\"},\n\t\t\t{\"0.00000000000000001\", \"-39.14394658089877663\"},\n\t\t\t{\"0.0000000000000001\", \"-36.84136148790473094\"},\n\t\t\t{\"0.000000000000001\", \"-34.53877639491068526\"},\n\t\t\t{\"0.00000000000001\", \"-32.23619130191663958\"},\n\t\t\t{\"0.0000000000001\", \"-29.93360620892259389\"},\n\t\t\t{\"0.000000000001\", \"-27.63102111592854821\"},\n\t\t\t{\"0.00000000001\", \"-25.32843602293450252\"},\n\t\t\t{\"0.0000000001\", \"-23.02585092994045684\"},\n\t\t\t{\"0.000000001\", \"-20.72326583694641116\"},\n\t\t\t{\"0.00000001\", \"-18.42068074395236547\"},\n\t\t\t{\"0.0000001\", \"-16.11809565095831979\"},\n\t\t\t{\"0.000001\", \"-13.81551055796427410\"},\n\t\t\t{\"0.00001\", \"-11.51292546497022842\"},\n\t\t\t{\"0.0001\", \"-9.210340371976182736\"},\n\t\t\t{\"0.001\", \"-6.907755278982137052\"},\n\t\t\t{\"0.01\", \"-4.605170185988091368\"},\n\t\t\t{\"0.1\", \"-2.302585092994045684\"},\n\n\t\t\t// Natural numbers\n\t\t\t{\"1\", \"0\"},\n\t\t\t{\"2\", \"0.6931471805599453094\"},\n\t\t\t{\"3\", \"1.098612288668109691\"},\n\t\t\t{\"4\", \"1.386294361119890619\"},\n\t\t\t{\"5\", \"1.609437912434100375\"},\n\t\t\t{\"6\", \"1.791759469228055001\"},\n\t\t\t{\"7\", \"1.945910149055313305\"},\n\t\t\t{\"8\", \"2.079441541679835928\"},\n\t\t\t{\"9\", \"2.197224577336219383\"},\n\t\t\t{\"10\", \"2.302585092994045684\"},\n\t\t\t{\"11\", \"2.397895272798370544\"},\n\t\t\t{\"12\", \"2.484906649788000310\"},\n\t\t\t{\"13\", \"2.564949357461536736\"},\n\t\t\t{\"14\", \"2.639057329615258615\"},\n\t\t\t{\"15\", \"2.708050201102210066\"},\n\t\t\t{\"16\", \"2.772588722239781238\"},\n\t\t\t{\"17\", \"2.833213344056216080\"},\n\t\t\t{\"18\", \"2.890371757896164692\"},\n\t\t\t{\"19\", \"2.944438979166440460\"},\n\t\t\t{\"20\", \"2.995732273553990993\"},\n\n\t\t\t// Smallest and largest numbers\n\t\t\t{\"0.0000000000000000001\", \"-43.74911676688686800\"},\n\t\t\t{\"9999999999999999999\", \"43.74911676688686800\"},\n\n\t\t\t// Captured during fuzzing\n\t\t\t{\"0.0000000000000097\", \"-32.26665050940134812\"},\n\t\t\t{\"0.00000000000018\", \"-29.34581954402047488\"},\n\t\t\t{\"0.00444\", \"-5.417100902538003665\"},\n\t\t\t{\"562\", \"6.331501849893691075\"},\n\t\t}\n\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\tgot, err := d.Log()\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.Log() failed: %v\", d, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"%q.Log() = %q, want %q\", d, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]string{\n\t\t\t\"negative\": \"-1\",\n\t\t\t\"zero\":     \"0\",\n\t\t}\n\t\tfor name, d := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\td := MustParse(d)\n\t\t\t\t_, err := d.Log()\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"%q.Log() did not fail\", d)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestDecimal_Log1p(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, want string\n\t\t}{\n\t\t\t// Zeros\n\t\t\t{\"0\", \"0\"},\n\t\t\t{\"0.0\", \"0\"},\n\t\t\t{\"0.00\", \"0\"},\n\t\t\t{\"0.000\", \"0\"},\n\n\t\t\t// Ones\n\t\t\t{\"1\", \"0.6931471805599453094\"},\n\t\t\t{\"1.0\", \"0.6931471805599453094\"},\n\t\t\t{\"1.00\", \"0.6931471805599453094\"},\n\t\t\t{\"1.000\", \"0.6931471805599453094\"},\n\n\t\t\t// Closer and closer to one\n\t\t\t{\"0.9\", \"0.6418538861723947760\"},\n\t\t\t{\"0.99\", \"0.6881346387364010274\"},\n\t\t\t{\"0.999\", \"0.6926470555182630115\"},\n\t\t\t{\"0.9999\", \"0.6930971793099036412\"},\n\t\t\t{\"0.99999\", \"0.6931421805474452678\"},\n\t\t\t{\"0.999999\", \"0.6931466805598203094\"},\n\t\t\t{\"0.9999999\", \"0.6931471305599440594\"},\n\t\t\t{\"0.99999999\", \"0.6931471755599452969\"},\n\t\t\t{\"0.999999999\", \"0.6931471800599453093\"},\n\t\t\t{\"0.9999999999\", \"0.6931471805099453094\"},\n\t\t\t{\"0.99999999999\", \"0.6931471805549453094\"},\n\t\t\t{\"0.999999999999\", \"0.6931471805594453094\"},\n\t\t\t{\"0.9999999999999\", \"0.6931471805598953094\"},\n\t\t\t{\"0.99999999999999\", \"0.6931471805599403094\"},\n\t\t\t{\"0.999999999999999\", \"0.6931471805599448094\"},\n\t\t\t{\"0.9999999999999999\", \"0.6931471805599452594\"},\n\t\t\t{\"0.99999999999999999\", \"0.6931471805599453044\"},\n\t\t\t{\"0.999999999999999999\", \"0.6931471805599453089\"},\n\t\t\t{\"0.9999999999999999999\", \"0.6931471805599453094\"},\n\t\t\t{\"1\", \"0.6931471805599453094\"},\n\t\t\t{\"1.000000000000000001\", \"0.6931471805599453099\"},\n\t\t\t{\"1.00000000000000001\", \"0.6931471805599453144\"},\n\t\t\t{\"1.0000000000000001\", \"0.6931471805599453594\"},\n\t\t\t{\"1.000000000000001\", \"0.6931471805599458094\"},\n\t\t\t{\"1.00000000000001\", \"0.6931471805599503094\"},\n\t\t\t{\"1.0000000000001\", \"0.6931471805599953094\"},\n\t\t\t{\"1.000000000001\", \"0.6931471805604453094\"},\n\t\t\t{\"1.00000000001\", \"0.6931471805649453094\"},\n\t\t\t{\"1.0000000001\", \"0.6931471806099453094\"},\n\t\t\t{\"1.000000001\", \"0.6931471810599453093\"},\n\t\t\t{\"1.00000001\", \"0.6931471855599452969\"},\n\t\t\t{\"1.0000001\", \"0.6931472305599440594\"},\n\t\t\t{\"1.000001\", \"0.6931476805598203095\"},\n\t\t\t{\"1.00001\", \"0.6931521805474453511\"},\n\t\t\t{\"1.0001\", \"0.6931971793099869745\"},\n\t\t\t{\"1.001\", \"0.6936470556015963573\"},\n\t\t\t{\"1.01\", \"0.6981347220709843830\"},\n\t\t\t{\"1.1\", \"0.7419373447293773125\"},\n\n\t\t\t// Closer and closer to zero\n\t\t\t{\"-0.1\", \"-0.1053605156578263012\"},\n\t\t\t{\"-0.01\", \"-0.0100503358535014412\"},\n\t\t\t{\"-0.001\", \"-0.0010005003335835335\"},\n\t\t\t{\"-0.0001\", \"-0.0001000050003333583\"},\n\t\t\t{\"-0.00001\", \"-0.0000100000500003333\"},\n\t\t\t{\"-0.000001\", \"-0.0000010000005000003\"},\n\t\t\t{\"-0.0000001\", \"-0.0000001000000050000\"},\n\t\t\t{\"-0.00000001\", \"-0.0000000100000000500\"},\n\t\t\t{\"-0.000000001\", \"-0.0000000010000000005\"},\n\t\t\t{\"-0.0000000001\", \"-0.0000000001000000000\"},\n\t\t\t{\"-0.00000000001\", \"-0.0000000000100000000\"},\n\t\t\t{\"-0.000000000001\", \"-0.0000000000010000000\"},\n\t\t\t{\"-0.0000000000001\", \"-0.0000000000001000000\"},\n\t\t\t{\"-0.00000000000001\", \"-0.0000000000000100000\"},\n\t\t\t{\"-0.000000000000001\", \"-0.0000000000000010000\"},\n\t\t\t{\"-0.0000000000000001\", \"-0.0000000000000001000\"},\n\t\t\t{\"-0.00000000000000001\", \"-0.0000000000000000100\"},\n\t\t\t{\"-0.000000000000000001\", \"-0.0000000000000000010\"},\n\t\t\t{\"-0.0000000000000000001\", \"-0.0000000000000000001\"},\n\t\t\t{\"0\", \"0\"},\n\t\t\t{\"0.0000000000000000001\", \"0.0000000000000000001\"},\n\t\t\t{\"0.000000000000000001\", \"0.0000000000000000010\"},\n\t\t\t{\"0.00000000000000001\", \"0.0000000000000000100\"},\n\t\t\t{\"0.0000000000000001\", \"0.0000000000000001000\"},\n\t\t\t{\"0.000000000000001\", \"0.0000000000000010000\"},\n\t\t\t{\"0.00000000000001\", \"0.0000000000000100000\"},\n\t\t\t{\"0.0000000000001\", \"0.0000000000001000000\"},\n\t\t\t{\"0.000000000001\", \"0.0000000000010000000\"},\n\t\t\t{\"0.00000000001\", \"0.0000000000100000000\"},\n\t\t\t{\"0.0000000001\", \"0.0000000001000000000\"},\n\t\t\t{\"0.000000001\", \"0.0000000009999999995\"},\n\t\t\t{\"0.00000001\", \"0.0000000099999999500\"},\n\t\t\t{\"0.0000001\", \"0.0000000999999950000\"},\n\t\t\t{\"0.000001\", \"0.0000009999995000003\"},\n\t\t\t{\"0.00001\", \"0.0000099999500003333\"},\n\t\t\t{\"0.0001\", \"0.0000999950003333083\"},\n\t\t\t{\"0.001\", \"0.0009995003330835332\"},\n\t\t\t{\"0.01\", \"0.0099503308531680828\"},\n\t\t\t{\"0.1\", \"0.0953101798043248600\"},\n\n\t\t\t// Closer and closer to negative one\n\t\t\t{\"-0.9999999999999999999\", \"-43.74911676688686800\"},\n\t\t\t{\"-0.999999999999999999\", \"-41.44653167389282231\"},\n\t\t\t{\"-0.99999999999999999\", \"-39.14394658089877663\"},\n\t\t\t{\"-0.9999999999999999\", \"-36.84136148790473094\"},\n\t\t\t{\"-0.999999999999999\", \"-34.53877639491068526\"},\n\t\t\t{\"-0.99999999999999\", \"-32.23619130191663958\"},\n\t\t\t{\"-0.9999999999999\", \"-29.93360620892259389\"},\n\t\t\t{\"-0.999999999999\", \"-27.63102111592854821\"},\n\t\t\t{\"-0.99999999999\", \"-25.32843602293450252\"},\n\t\t\t{\"-0.9999999999\", \"-23.02585092994045684\"},\n\t\t\t{\"-0.999999999\", \"-20.72326583694641116\"},\n\t\t\t{\"-0.99999999\", \"-18.42068074395236547\"},\n\t\t\t{\"-0.9999999\", \"-16.11809565095831979\"},\n\t\t\t{\"-0.999999\", \"-13.81551055796427410\"},\n\t\t\t{\"-0.99999\", \"-11.51292546497022842\"},\n\t\t\t{\"-0.9999\", \"-9.210340371976182736\"},\n\t\t\t{\"-0.999\", \"-6.907755278982137052\"},\n\t\t\t{\"-0.99\", \"-4.605170185988091368\"},\n\t\t\t{\"-0.9\", \"-2.302585092994045684\"},\n\n\t\t\t// Natural numbers\n\t\t\t{\"0\", \"0\"},\n\t\t\t{\"1\", \"0.6931471805599453094\"},\n\t\t\t{\"2\", \"1.098612288668109691\"},\n\t\t\t{\"3\", \"1.386294361119890619\"},\n\t\t\t{\"4\", \"1.609437912434100375\"},\n\t\t\t{\"5\", \"1.791759469228055001\"},\n\t\t\t{\"6\", \"1.945910149055313305\"},\n\t\t\t{\"7\", \"2.079441541679835928\"},\n\t\t\t{\"8\", \"2.197224577336219383\"},\n\t\t\t{\"9\", \"2.302585092994045684\"},\n\t\t\t{\"10\", \"2.397895272798370544\"},\n\t\t\t{\"11\", \"2.484906649788000310\"},\n\t\t\t{\"12\", \"2.564949357461536736\"},\n\t\t\t{\"13\", \"2.639057329615258615\"},\n\t\t\t{\"14\", \"2.708050201102210066\"},\n\t\t\t{\"15\", \"2.772588722239781238\"},\n\t\t\t{\"16\", \"2.833213344056216080\"},\n\t\t\t{\"17\", \"2.890371757896164692\"},\n\t\t\t{\"18\", \"2.944438979166440460\"},\n\t\t\t{\"19\", \"2.995732273553990993\"},\n\t\t\t{\"20\", \"3.044522437723422997\"},\n\n\t\t\t// Smallest and largest numbers\n\t\t\t{\"0.0000000000000000001\", \"0.0000000000000000001\"},\n\t\t\t{\"9999999999999999999\", \"43.74911676688686800\"},\n\t\t}\n\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\tgot, err := d.Log1p()\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.Log1p() failed: %v\", d, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"%q.Log1p() = %q, want %q\", d, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]string{\n\t\t\t\"negative\": \"-1\",\n\t\t}\n\t\tfor name, d := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\td := MustParse(d)\n\t\t\t\t_, err := d.Log1p()\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"%q.Log1p() did not fail\", d)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestDecimal_Log2(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, want string\n\t\t}{\n\t\t\t// Ones\n\t\t\t{\"1\", \"0\"},\n\t\t\t{\"1.0\", \"0\"},\n\t\t\t{\"1.00\", \"0\"},\n\t\t\t{\"1.000\", \"0\"},\n\n\t\t\t// Powers of two\n\t\t\t{\"0.0000000000000000001\", \"-63.11663380285988461\"},\n\t\t\t{\"0.0000000000000000002\", \"-62.11663380285988461\"},\n\t\t\t{\"0.0000000000000000004\", \"-61.11663380285988461\"},\n\t\t\t{\"0.0000000000000000009\", \"-59.94670880141757225\"},\n\t\t\t{\"0.0000000000000000017\", \"-59.02917096160954520\"},\n\t\t\t{\"0.0000000000000000035\", \"-57.98735078591491815\"},\n\t\t\t{\"0.0000000000000000069\", \"-57.00810934608171556\"},\n\t\t\t{\"0.0000000000000000139\", \"-55.99769273013637718\"},\n\t\t\t{\"0.0000000000000000278\", \"-54.99769273013637718\"},\n\t\t\t{\"0.0000000000000000555\", \"-54.00028984162241630\"},\n\t\t\t{\"0.0000000000000001110\", \"-53.00028984162241630\"},\n\t\t\t{\"0.0000000000000002220\", \"-52.00028984162241630\"},\n\t\t\t{\"0.0000000000000004441\", \"-50.99996494689277185\"},\n\t\t\t{\"0.0000000000000008882\", \"-49.99996494689277185\"},\n\t\t\t{\"0.0000000000000017764\", \"-48.99996494689277185\"},\n\t\t\t{\"0.0000000000000035527\", \"-48.00000555473292341\"},\n\t\t\t{\"0.0000000000000071054\", \"-47.00000555473292341\"},\n\t\t\t{\"0.0000000000000142109\", \"-45.99999540266572901\"},\n\t\t\t{\"0.0000000000000284217\", \"-45.00000047869039635\"},\n\t\t\t{\"0.0000000000000568434\", \"-44.00000047869039635\"},\n\t\t\t{\"0.0000000000001136868\", \"-43.00000047869039635\"},\n\t\t\t{\"0.0000000000002273737\", \"-41.99999984418633623\"},\n\t\t\t{\"0.0000000000004547474\", \"-40.99999984418633623\"},\n\t\t\t{\"0.0000000000009094947\", \"-40.00000000281232510\"},\n\t\t\t{\"0.0000000000018189894\", \"-39.00000000281232510\"},\n\t\t\t{\"0.0000000000036379788\", \"-38.00000000281232510\"},\n\t\t\t{\"0.0000000000072759576\", \"-37.00000000281232510\"},\n\t\t\t{\"0.0000000000145519152\", \"-36.00000000281232510\"},\n\t\t\t{\"0.0000000000291038305\", \"-34.99999999785526269\"},\n\t\t\t{\"0.0000000000582076609\", \"-34.00000000033379389\"},\n\t\t\t{\"0.0000000001164153218\", \"-33.00000000033379389\"},\n\t\t\t{\"0.0000000002328306437\", \"-31.99999999971416109\"},\n\t\t\t{\"0.0000000004656612873\", \"-31.00000000002397749\"},\n\t\t\t{\"0.0000000009313225746\", \"-30.00000000002397749\"},\n\t\t\t{\"0.0000000018626451492\", \"-29.00000000002397749\"},\n\t\t\t{\"0.0000000037252902985\", \"-27.99999999998525044\"},\n\t\t\t{\"0.0000000074505805969\", \"-27.00000000000461396\"},\n\t\t\t{\"0.0000000149011611938\", \"-26.00000000000461396\"},\n\t\t\t{\"0.0000000298023223877\", \"-24.99999999999977308\"},\n\t\t\t{\"0.0000000596046447754\", \"-23.99999999999977308\"},\n\t\t\t{\"0.0000001192092895508\", \"-22.99999999999977308\"},\n\t\t\t{\"0.0000002384185791016\", \"-21.99999999999977308\"},\n\t\t\t{\"0.0000004768371582031\", \"-21.00000000000007564\"},\n\t\t\t{\"0.0000009536743164062\", \"-20.00000000000007564\"},\n\t\t\t{\"0.0000019073486328125\", \"-19\"},\n\t\t\t{\"0.000003814697265625\", \"-18\"},\n\t\t\t{\"0.00000762939453125\", \"-17\"},\n\t\t\t{\"0.0000152587890625\", \"-16\"},\n\t\t\t{\"0.000030517578125\", \"-15\"},\n\t\t\t{\"0.00006103515625\", \"-14\"},\n\t\t\t{\"0.0001220703125\", \"-13\"},\n\t\t\t{\"0.000244140625\", \"-12\"},\n\t\t\t{\"0.00048828125\", \"-11\"},\n\t\t\t{\"0.0009765625\", \"-10\"},\n\t\t\t{\"0.001953125\", \"-9\"},\n\t\t\t{\"0.00390625\", \"-8\"},\n\t\t\t{\"0.0078125\", \"-7\"},\n\t\t\t{\"0.015625\", \"-6\"},\n\t\t\t{\"0.03125\", \"-5\"},\n\t\t\t{\"0.0625\", \"-4\"},\n\t\t\t{\"0.125\", \"-3\"},\n\t\t\t{\"0.25\", \"-2\"},\n\t\t\t{\"0.5\", \"-1\"},\n\t\t\t{\"1\", \"0\"},\n\t\t\t{\"2\", \"1\"},\n\t\t\t{\"4\", \"2\"},\n\t\t\t{\"8\", \"3\"},\n\t\t\t{\"16\", \"4\"},\n\t\t\t{\"32\", \"5\"},\n\t\t\t{\"64\", \"6\"},\n\t\t\t{\"128\", \"7\"},\n\t\t\t{\"256\", \"8\"},\n\t\t\t{\"512\", \"9\"},\n\t\t\t{\"1024\", \"10\"},\n\t\t\t{\"2048\", \"11\"},\n\t\t\t{\"4096\", \"12\"},\n\t\t\t{\"8192\", \"13\"},\n\t\t\t{\"16384\", \"14\"},\n\t\t\t{\"32768\", \"15\"},\n\t\t\t{\"65536\", \"16\"},\n\t\t\t{\"131072\", \"17\"},\n\t\t\t{\"262144\", \"18\"},\n\t\t\t{\"524288\", \"19\"},\n\t\t\t{\"1048576\", \"20\"},\n\t\t\t{\"2097152\", \"21\"},\n\t\t\t{\"4194304\", \"22\"},\n\t\t\t{\"8388608\", \"23\"},\n\t\t\t{\"16777216\", \"24\"},\n\t\t\t{\"33554432\", \"25\"},\n\t\t\t{\"67108864\", \"26\"},\n\t\t\t{\"134217728\", \"27\"},\n\t\t\t{\"268435456\", \"28\"},\n\t\t\t{\"536870912\", \"29\"},\n\t\t\t{\"1073741824\", \"30\"},\n\t\t\t{\"2147483648\", \"31\"},\n\t\t\t{\"4294967296\", \"32\"},\n\t\t\t{\"8589934592\", \"33\"},\n\t\t\t{\"17179869184\", \"34\"},\n\t\t\t{\"34359738368\", \"35\"},\n\t\t\t{\"68719476736\", \"36\"},\n\t\t\t{\"137438953472\", \"37\"},\n\t\t\t{\"274877906944\", \"38\"},\n\t\t\t{\"549755813888\", \"39\"},\n\t\t\t{\"1099511627776\", \"40\"},\n\t\t\t{\"2199023255552\", \"41\"},\n\t\t\t{\"4398046511104\", \"42\"},\n\t\t\t{\"8796093022208\", \"43\"},\n\t\t\t{\"17592186044416\", \"44\"},\n\t\t\t{\"35184372088832\", \"45\"},\n\t\t\t{\"70368744177664\", \"46\"},\n\t\t\t{\"140737488355328\", \"47\"},\n\t\t\t{\"281474976710656\", \"48\"},\n\t\t\t{\"562949953421312\", \"49\"},\n\t\t\t{\"1125899906842624\", \"50\"},\n\t\t\t{\"2251799813685248\", \"51\"},\n\t\t\t{\"4503599627370496\", \"52\"},\n\t\t\t{\"9007199254740992\", \"53\"},\n\t\t\t{\"18014398509481984\", \"54\"},\n\t\t\t{\"36028797018963968\", \"55\"},\n\t\t\t{\"72057594037927936\", \"56\"},\n\t\t\t{\"144115188075855872\", \"57\"},\n\t\t\t{\"288230376151711744\", \"58\"},\n\t\t\t{\"576460752303423488\", \"59\"},\n\t\t\t{\"1152921504606846976\", \"60\"},\n\t\t\t{\"2305843009213693952\", \"61\"},\n\t\t\t{\"4611686018427387904\", \"62\"},\n\t\t\t{\"9223372036854775808\", \"63\"},\n\n\t\t\t// Closer and closer to two\n\t\t\t{\"1.9\", \"0.9259994185562231459\"},\n\t\t\t{\"1.99\", \"0.9927684307689241428\"},\n\t\t\t{\"1.999\", \"0.9992784720825405627\"},\n\t\t\t{\"1.9999\", \"0.9999278634445266362\"},\n\t\t\t{\"1.99999\", \"0.9999927865067618071\"},\n\t\t\t{\"1.999999\", \"0.9999992786522992186\"},\n\t\t\t{\"1.9999999\", \"0.9999999278652461522\"},\n\t\t\t{\"1.99999999\", \"0.9999999927865247775\"},\n\t\t\t{\"1.999999999\", \"0.9999999992786524794\"},\n\t\t\t{\"1.9999999999\", \"0.9999999999278652480\"},\n\t\t\t{\"1.99999999999\", \"0.9999999999927865248\"},\n\t\t\t{\"1.999999999999\", \"0.9999999999992786525\"},\n\t\t\t{\"1.9999999999999\", \"0.9999999999999278652\"},\n\t\t\t{\"1.99999999999999\", \"0.9999999999999927865\"},\n\t\t\t{\"1.999999999999999\", \"0.9999999999999992787\"},\n\t\t\t{\"1.9999999999999999\", \"0.9999999999999999279\"},\n\t\t\t{\"1.99999999999999999\", \"0.9999999999999999928\"},\n\t\t\t{\"2\", \"1\"},\n\t\t\t{\"2.00000000000000001\", \"1.000000000000000007\"},\n\t\t\t{\"2.0000000000000001\", \"1.000000000000000072\"},\n\t\t\t{\"2.000000000000001\", \"1.000000000000000721\"},\n\t\t\t{\"2.00000000000001\", \"1.000000000000007213\"},\n\t\t\t{\"2.0000000000001\", \"1.000000000000072135\"},\n\t\t\t{\"2.000000000001\", \"1.000000000000721348\"},\n\t\t\t{\"2.00000000001\", \"1.000000000007213475\"},\n\t\t\t{\"2.0000000001\", \"1.000000000072134752\"},\n\t\t\t{\"2.000000001\", \"1.000000000721347520\"},\n\t\t\t{\"2.00000001\", \"1.000000007213475186\"},\n\t\t\t{\"2.0000001\", \"1.000000072134750241\"},\n\t\t\t{\"2.000001\", \"1.000000721347340108\"},\n\t\t\t{\"2.00001\", \"1.000007213457170817\"},\n\t\t\t{\"2.0001\", \"1.000072132948735757\"},\n\t\t\t{\"2.001\", \"1.000721167243654131\"},\n\t\t\t{\"2.1\", \"1.070389327891397941\"},\n\n\t\t\t// Closer and closer to one\n\t\t\t{\"0.9\", \"-0.1520030934450499850\"},\n\t\t\t{\"0.99\", \"-0.0144995696951150766\"},\n\t\t\t{\"0.999\", \"-0.0014434168696687174\"},\n\t\t\t{\"0.9999\", \"-0.0001442767180450352\"},\n\t\t\t{\"0.99999\", \"-0.0000144270225441226\"},\n\t\t\t{\"0.999999\", \"-0.0000014426957622370\"},\n\t\t\t{\"0.9999999\", \"-0.0000001442695113024\"},\n\t\t\t{\"0.99999999\", \"-0.0000000144269504810\"},\n\t\t\t{\"0.999999999\", \"-0.0000000014426950416\"},\n\t\t\t{\"0.9999999999\", \"-0.0000000001442695041\"},\n\t\t\t{\"0.99999999999\", \"-0.0000000000144269504\"},\n\t\t\t{\"0.999999999999\", \"-0.0000000000014426950\"},\n\t\t\t{\"0.9999999999999\", \"-0.0000000000001442695\"},\n\t\t\t{\"0.99999999999999\", \"-0.0000000000000144270\"},\n\t\t\t{\"0.999999999999999\", \"-0.0000000000000014427\"},\n\t\t\t{\"0.9999999999999999\", \"-0.0000000000000001443\"},\n\t\t\t{\"0.99999999999999999\", \"-0.0000000000000000144\"},\n\t\t\t{\"0.999999999999999999\", \"-0.0000000000000000014\"},\n\t\t\t{\"1\", \"0\"},\n\t\t\t{\"1.000000000000000001\", \"0.0000000000000000014\"},\n\t\t\t{\"1.00000000000000001\", \"0.0000000000000000144\"},\n\t\t\t{\"1.0000000000000001\", \"0.0000000000000001443\"},\n\t\t\t{\"1.000000000000001\", \"0.0000000000000014427\"},\n\t\t\t{\"1.00000000000001\", \"0.0000000000000144270\"},\n\t\t\t{\"1.0000000000001\", \"0.0000000000001442695\"},\n\t\t\t{\"1.000000000001\", \"0.0000000000014426950\"},\n\t\t\t{\"1.00000000001\", \"0.0000000000144269504\"},\n\t\t\t{\"1.0000000001\", \"0.0000000001442695041\"},\n\t\t\t{\"1.000000001\", \"0.0000000014426950402\"},\n\t\t\t{\"1.00000001\", \"0.0000000144269503368\"},\n\t\t\t{\"1.0000001\", \"0.0000001442694968754\"},\n\t\t\t{\"1.000001\", \"0.0000014426943195419\"},\n\t\t\t{\"1.00001\", \"0.0000144268782746185\"},\n\t\t\t{\"1.0001\", \"0.0001442622910945542\"},\n\t\t\t{\"1.001\", \"0.0014419741739064804\"},\n\t\t\t{\"1.01\", \"0.0143552929770700414\"},\n\t\t\t{\"1.1\", \"0.1375035237499349083\"},\n\n\t\t\t// Natural numbers\n\t\t\t{\"1\", \"0\"},\n\t\t\t{\"2\", \"1\"},\n\t\t\t{\"3\", \"1.584962500721156181\"},\n\t\t\t{\"4\", \"2\"},\n\t\t\t{\"5\", \"2.321928094887362348\"},\n\t\t\t{\"6\", \"2.584962500721156181\"},\n\t\t\t{\"7\", \"2.807354922057604107\"},\n\t\t\t{\"8\", \"3\"},\n\t\t\t{\"9\", \"3.169925001442312363\"},\n\t\t\t{\"10\", \"3.321928094887362348\"},\n\t\t\t{\"11\", \"3.459431618637297256\"},\n\t\t\t{\"12\", \"3.584962500721156181\"},\n\t\t\t{\"13\", \"3.700439718141092160\"},\n\t\t\t{\"14\", \"3.807354922057604107\"},\n\t\t\t{\"15\", \"3.906890595608518529\"},\n\t\t\t{\"16\", \"4\"},\n\t\t\t{\"17\", \"4.087462841250339408\"},\n\t\t\t{\"18\", \"4.169925001442312363\"},\n\t\t\t{\"19\", \"4.247927513443585494\"},\n\t\t\t{\"20\", \"4.321928094887362348\"},\n\n\t\t\t// Smallest and largest numbers\n\t\t\t{\"0.0000000000000000001\", \"-63.11663380285988461\"},\n\t\t\t{\"9999999999999999999\", \"63.11663380285988461\"},\n\n\t\t\t// Captured during fuzzing\n\t\t\t{\"0.00375\", \"-8.058893689053568514\"},\n\t\t\t{\"9223372036854.775784\", \"43.06843143067582591\"},\n\t\t}\n\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\tgot, err := d.Log2()\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.Log2() failed: %v\", d, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"%q,%q, want %q\", d, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]string{\n\t\t\t\"negative\": \"-1\",\n\t\t\t\"zero\":     \"0\",\n\t\t}\n\t\tfor name, d := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\td := MustParse(d)\n\t\t\t\t_, err := d.Log2()\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"%q.Log2() did not fail\", d)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestDecimal_Log10(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, want string\n\t\t}{\n\t\t\t// Ones\n\t\t\t{\"1\", \"0\"},\n\t\t\t{\"1.0\", \"0\"},\n\t\t\t{\"1.00\", \"0\"},\n\t\t\t{\"1.000\", \"0\"},\n\n\t\t\t// Powers of ten\n\t\t\t{\"0.0000000000000000001\", \"-19\"},\n\t\t\t{\"0.000000000000000001\", \"-18\"},\n\t\t\t{\"0.00000000000000001\", \"-17\"},\n\t\t\t{\"0.0000000000000001\", \"-16\"},\n\t\t\t{\"0.000000000000001\", \"-15\"},\n\t\t\t{\"0.00000000000001\", \"-14\"},\n\t\t\t{\"0.0000000000001\", \"-13\"},\n\t\t\t{\"0.000000000001\", \"-12\"},\n\t\t\t{\"0.00000000001\", \"-11\"},\n\t\t\t{\"0.0000000001\", \"-10\"},\n\t\t\t{\"0.000000001\", \"-9\"},\n\t\t\t{\"0.00000001\", \"-8\"},\n\t\t\t{\"0.0000001\", \"-7\"},\n\t\t\t{\"0.000001\", \"-6\"},\n\t\t\t{\"0.00001\", \"-5\"},\n\t\t\t{\"0.0001\", \"-4\"},\n\t\t\t{\"0.001\", \"-3\"},\n\t\t\t{\"0.01\", \"-2\"},\n\t\t\t{\"0.1\", \"-1\"},\n\t\t\t{\"1\", \"0\"},\n\t\t\t{\"10\", \"1\"},\n\t\t\t{\"100\", \"2\"},\n\t\t\t{\"1000\", \"3\"},\n\t\t\t{\"10000\", \"4\"},\n\t\t\t{\"100000\", \"5\"},\n\t\t\t{\"1000000\", \"6\"},\n\t\t\t{\"10000000\", \"7\"},\n\t\t\t{\"100000000\", \"8\"},\n\t\t\t{\"1000000000\", \"9\"},\n\t\t\t{\"10000000000\", \"10\"},\n\t\t\t{\"100000000000\", \"11\"},\n\t\t\t{\"1000000000000\", \"12\"},\n\t\t\t{\"10000000000000\", \"13\"},\n\t\t\t{\"100000000000000\", \"14\"},\n\t\t\t{\"1000000000000000\", \"15\"},\n\t\t\t{\"10000000000000000\", \"16\"},\n\t\t\t{\"100000000000000000\", \"17\"},\n\t\t\t{\"1000000000000000000\", \"18\"},\n\n\t\t\t// Closer and closer to ten\n\t\t\t{\"9.9\", \"0.9956351945975499153\"},\n\t\t\t{\"9.99\", \"0.9995654882259823087\"},\n\t\t\t{\"9.999\", \"0.9999565683801924896\"},\n\t\t\t{\"9.9999\", \"0.9999956570334660986\"},\n\t\t\t{\"9.99999\", \"0.9999995657053009494\"},\n\t\t\t{\"9.999999\", \"0.9999999565705496382\"},\n\t\t\t{\"9.9999999\", \"0.9999999956570551593\"},\n\t\t\t{\"9.99999999\", \"0.9999999995657055179\"},\n\t\t\t{\"9.999999999\", \"0.9999999999565705518\"},\n\t\t\t{\"9.9999999999\", \"0.9999999999956570552\"},\n\t\t\t{\"9.99999999999\", \"0.9999999999995657055\"},\n\t\t\t{\"9.999999999999\", \"0.9999999999999565706\"},\n\t\t\t{\"9.9999999999999\", \"0.9999999999999956571\"},\n\t\t\t{\"9.99999999999999\", \"0.9999999999999995657\"},\n\t\t\t{\"9.999999999999999\", \"0.9999999999999999566\"},\n\t\t\t{\"9.9999999999999999\", \"0.9999999999999999957\"},\n\t\t\t{\"9.99999999999999999\", \"0.9999999999999999996\"},\n\t\t\t{\"9.999999999999999999\", \"1\"},\n\t\t\t{\"10\", \"1\"},\n\t\t\t{\"10.00000000000000001\", \"1\"},\n\t\t\t{\"10.0000000000000001\", \"1.000000000000000004\"},\n\t\t\t{\"10.000000000000001\", \"1.000000000000000043\"},\n\t\t\t{\"10.00000000000001\", \"1.000000000000000434\"},\n\t\t\t{\"10.0000000000001\", \"1.000000000000004343\"},\n\t\t\t{\"10.000000000001\", \"1.000000000000043429\"},\n\t\t\t{\"10.00000000001\", \"1.000000000000434294\"},\n\t\t\t{\"10.0000000001\", \"1.000000000004342945\"},\n\t\t\t{\"10.000000001\", \"1.000000000043429448\"},\n\t\t\t{\"10.00000001\", \"1.000000000434294482\"},\n\t\t\t{\"10.0000001\", \"1.000000004342944797\"},\n\t\t\t{\"10.000001\", \"1.000000043429446019\"},\n\t\t\t{\"10.00001\", \"1.000000434294264756\"},\n\t\t\t{\"10.0001\", \"1.000004342923104453\"},\n\t\t\t{\"10.001\", \"1.000043427276862670\"},\n\t\t\t{\"10.01\", \"1.000434077479318641\"},\n\t\t\t{\"10.1\", \"1.004321373782642574\"},\n\n\t\t\t// Closer and closer to one\n\t\t\t{\"0.9\", \"-0.0457574905606751254\"},\n\t\t\t{\"0.99\", \"-0.0043648054024500847\"},\n\t\t\t{\"0.999\", \"-0.0004345117740176913\"},\n\t\t\t{\"0.9999\", \"-0.0000434316198075104\"},\n\t\t\t{\"0.99999\", \"-0.0000043429665339014\"},\n\t\t\t{\"0.999999\", \"-0.0000004342946990506\"},\n\t\t\t{\"0.9999999\", \"-0.0000000434294503618\"},\n\t\t\t{\"0.99999999\", \"-0.0000000043429448407\"},\n\t\t\t{\"0.999999999\", \"-0.0000000004342944821\"},\n\t\t\t{\"0.9999999999\", \"-0.0000000000434294482\"},\n\t\t\t{\"0.99999999999\", \"-0.0000000000043429448\"},\n\t\t\t{\"0.999999999999\", \"-0.0000000000004342945\"},\n\t\t\t{\"0.9999999999999\", \"-0.0000000000000434294\"},\n\t\t\t{\"0.99999999999999\", \"-0.0000000000000043429\"},\n\t\t\t{\"0.999999999999999\", \"-0.0000000000000004343\"},\n\t\t\t{\"0.9999999999999999\", \"-0.0000000000000000434\"},\n\t\t\t{\"0.99999999999999999\", \"-0.0000000000000000043\"},\n\t\t\t{\"0.999999999999999999\", \"-0.0000000000000000004\"},\n\t\t\t{\"0.9999999999999999999\", \"0\"},\n\t\t\t{\"1\", \"0\"},\n\t\t\t{\"1.000000000000000001\", \"0.0000000000000000004\"},\n\t\t\t{\"1.00000000000000001\", \"0.0000000000000000043\"},\n\t\t\t{\"1.0000000000000001\", \"0.0000000000000000434\"},\n\t\t\t{\"1.000000000000001\", \"0.0000000000000004343\"},\n\t\t\t{\"1.00000000000001\", \"0.0000000000000043429\"},\n\t\t\t{\"1.0000000000001\", \"0.0000000000000434294\"},\n\t\t\t{\"1.000000000001\", \"0.0000000000004342945\"},\n\t\t\t{\"1.00000000001\", \"0.0000000000043429448\"},\n\t\t\t{\"1.0000000001\", \"0.0000000000434294482\"},\n\t\t\t{\"1.000000001\", \"0.0000000004342944817\"},\n\t\t\t{\"1.00000001\", \"0.0000000043429447973\"},\n\t\t\t{\"1.0000001\", \"0.0000000434294460189\"},\n\t\t\t{\"1.000001\", \"0.0000004342942647562\"},\n\t\t\t{\"1.00001\", \"0.0000043429231044532\"},\n\t\t\t{\"1.0001\", \"0.0000434272768626696\"},\n\t\t\t{\"1.001\", \"0.0004340774793186407\"},\n\t\t\t{\"1.01\", \"0.0043213737826425743\"},\n\t\t\t{\"1.1\", \"0.0413926851582250408\"},\n\n\t\t\t// Natural numbers\n\t\t\t{\"1\", \"0\"},\n\t\t\t{\"2\", \"0.3010299956639811952\"},\n\t\t\t{\"3\", \"0.4771212547196624373\"},\n\t\t\t{\"4\", \"0.6020599913279623904\"},\n\t\t\t{\"5\", \"0.6989700043360188048\"},\n\t\t\t{\"6\", \"0.7781512503836436325\"},\n\t\t\t{\"7\", \"0.8450980400142568307\"},\n\t\t\t{\"8\", \"0.9030899869919435856\"},\n\t\t\t{\"9\", \"0.9542425094393248746\"},\n\t\t\t{\"10\", \"1\"},\n\t\t\t{\"11\", \"1.041392685158225041\"},\n\t\t\t{\"12\", \"1.079181246047624828\"},\n\t\t\t{\"13\", \"1.113943352306836769\"},\n\t\t\t{\"14\", \"1.146128035678238026\"},\n\t\t\t{\"15\", \"1.176091259055681242\"},\n\t\t\t{\"16\", \"1.204119982655924781\"},\n\t\t\t{\"17\", \"1.230448921378273929\"},\n\t\t\t{\"18\", \"1.255272505103306070\"},\n\t\t\t{\"19\", \"1.278753600952828962\"},\n\t\t\t{\"20\", \"1.301029995663981195\"},\n\n\t\t\t// Smallest and largest numbers\n\t\t\t{\"0.0000000000000000001\", \"-19\"},\n\t\t\t{\"9999999999999999999\", \"19\"},\n\n\t\t\t// Captured during fuzzing\n\t\t\t{\"0.00000000373\", \"-8.428291168191312394\"},\n\t\t\t{\"1.048\", \"0.0203612826477078465\"},\n\t\t}\n\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\tgot, err := d.Log10()\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.Log10() failed: %v\", d, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"%q.Log10() = %q, want %q\", d, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]string{\n\t\t\t\"negative\": \"-1\",\n\t\t\t\"zero\":     \"0\",\n\t\t}\n\t\tfor name, d := range tests {\n\t\t\tt.Run(name, func(t *testing.T) {\n\t\t\t\td := MustParse(d)\n\t\t\t\t_, err := d.Log10()\n\t\t\t\tif err == nil {\n\t\t\t\t\tt.Errorf(\"%q.Log10() did not fail\", d)\n\t\t\t\t}\n\t\t\t})\n\t\t}\n\t})\n}\n\nfunc TestDecimal_Abs(t *testing.T) {\n\ttests := []struct {\n\t\td, want string\n\t}{\n\t\t{\"1\", \"1\"},\n\t\t{\"-1\", \"1\"},\n\t\t{\"1.00\", \"1.00\"},\n\t\t{\"-1.00\", \"1.00\"},\n\t\t{\"0\", \"0\"},\n\t\t{\"0.0\", \"0.0\"},\n\t\t{\"0.00\", \"0.00\"},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\tgot := d.Abs()\n\t\twant := MustParse(tt.want)\n\t\tif got != want {\n\t\t\tt.Errorf(\"%q.Abs() = %q, want %q\", d, got, want)\n\t\t}\n\t}\n}\n\nfunc TestDecimal_CopySign(t *testing.T) {\n\ttests := []struct {\n\t\td, e, want string\n\t}{\n\t\t{\"10\", \"1\", \"10\"},\n\t\t{\"10\", \"0\", \"10\"},\n\t\t{\"10\", \"-1\", \"-10\"},\n\t\t{\"0\", \"1\", \"0\"},\n\t\t{\"0\", \"0\", \"0\"},\n\t\t{\"0\", \"-1\", \"0\"},\n\t\t{\"-10\", \"1\", \"10\"},\n\t\t{\"-10\", \"0\", \"10\"},\n\t\t{\"-10\", \"-1\", \"-10\"},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\te := MustParse(tt.e)\n\t\tgot := d.CopySign(e)\n\t\twant := MustParse(tt.want)\n\t\tif got != want {\n\t\t\tt.Errorf(\"%q.CopySign(%q) = %q, want %q\", d, e, got, want)\n\t\t}\n\t}\n}\n\nfunc TestDecimal_Neg(t *testing.T) {\n\ttests := []struct {\n\t\td, want string\n\t}{\n\t\t{\"1\", \"-1\"},\n\t\t{\"-1\", \"1\"},\n\t\t{\"1.00\", \"-1.00\"},\n\t\t{\"-1.00\", \"1.00\"},\n\t\t{\"0\", \"0\"},\n\t\t{\"0.0\", \"0.0\"},\n\t\t{\"0.00\", \"0.00\"},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\tgot := d.Neg()\n\t\twant := MustParse(tt.want)\n\t\tif got != want {\n\t\t\tt.Errorf(\"%q.Neg() = %q, want %q\", d, got, want)\n\t\t}\n\t}\n}\n\nfunc TestDecimal_Quo(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, e, want string\n\t\t}{\n\t\t\t// Zeros\n\t\t\t{\"0\", \"1.000\", \"0\"},\n\t\t\t{\"0.0\", \"1.000\", \"0\"},\n\t\t\t{\"0.00\", \"1.000\", \"0\"},\n\t\t\t{\"0.000\", \"1.000\", \"0\"},\n\t\t\t{\"0.0000\", \"1.000\", \"0.0\"},\n\t\t\t{\"0.00000\", \"1.000\", \"0.00\"},\n\n\t\t\t{\"0.000\", \"1\", \"0.000\"},\n\t\t\t{\"0.000\", \"1.0\", \"0.00\"},\n\t\t\t{\"0.000\", \"1.00\", \"0.0\"},\n\t\t\t{\"0.000\", \"1.000\", \"0\"},\n\t\t\t{\"0.000\", \"1.0000\", \"0\"},\n\t\t\t{\"0.000\", \"1.00000\", \"0\"},\n\n\t\t\t// Ones\n\t\t\t{\"1\", \"1.000\", \"1\"},\n\t\t\t{\"1.0\", \"1.000\", \"1\"},\n\t\t\t{\"1.00\", \"1.000\", \"1\"},\n\t\t\t{\"1.000\", \"1.000\", \"1\"},\n\t\t\t{\"1.0000\", \"1.000\", \"1.0\"},\n\t\t\t{\"1.00000\", \"1.000\", \"1.00\"},\n\n\t\t\t{\"1.000\", \"1\", \"1.000\"},\n\t\t\t{\"1.000\", \"1.0\", \"1.00\"},\n\t\t\t{\"1.000\", \"1.00\", \"1.0\"},\n\t\t\t{\"1.000\", \"1.000\", \"1\"},\n\t\t\t{\"1.000\", \"1.0000\", \"1\"},\n\t\t\t{\"1.000\", \"1.00000\", \"1\"},\n\n\t\t\t// Simple cases\n\t\t\t{\"1\", \"1\", \"1\"},\n\t\t\t{\"2\", \"1\", \"2\"},\n\t\t\t{\"1\", \"2\", \"0.5\"},\n\t\t\t{\"2\", \"2\", \"1\"},\n\t\t\t{\"0\", \"1\", \"0\"},\n\t\t\t{\"0\", \"2\", \"0\"},\n\t\t\t{\"1.5\", \"3\", \"0.5\"},\n\t\t\t{\"3\", \"3\", \"1\"},\n\t\t\t{\"9999999999999999999\", \"1\", \"9999999999999999999\"},\n\t\t\t{\"9999999999999999999\", \"9999999999999999999\", \"1\"},\n\n\t\t\t// Signs\n\t\t\t{\"2.4\", \"1\", \"2.4\"},\n\t\t\t{\"2.4\", \"-1\", \"-2.4\"},\n\t\t\t{\"-2.4\", \"1\", \"-2.4\"},\n\t\t\t{\"-2.4\", \"-1\", \"2.4\"},\n\n\t\t\t// Scales\n\t\t\t{\"2.40\", \"1\", \"2.40\"},\n\t\t\t{\"2.400\", \"1\", \"2.400\"},\n\t\t\t{\"2.4\", \"2\", \"1.2\"},\n\t\t\t{\"2.400\", \"2\", \"1.200\"},\n\n\t\t\t// 1 divided by digits\n\t\t\t{\"1\", \"1\", \"1\"},\n\t\t\t{\"1\", \"2\", \"0.5\"},\n\t\t\t{\"1\", \"3\", \"0.3333333333333333333\"},\n\t\t\t{\"1\", \"4\", \"0.25\"},\n\t\t\t{\"1\", \"5\", \"0.2\"},\n\t\t\t{\"1\", \"6\", \"0.1666666666666666667\"},\n\t\t\t{\"1\", \"7\", \"0.1428571428571428571\"},\n\t\t\t{\"1\", \"8\", \"0.125\"},\n\t\t\t{\"1\", \"9\", \"0.1111111111111111111\"},\n\n\t\t\t// 2 divided by digits\n\t\t\t{\"2\", \"1\", \"2\"},\n\t\t\t{\"2\", \"2\", \"1\"},\n\t\t\t{\"2\", \"3\", \"0.6666666666666666667\"},\n\t\t\t{\"2\", \"4\", \"0.5\"},\n\t\t\t{\"2\", \"5\", \"0.4\"},\n\t\t\t{\"2\", \"6\", \"0.3333333333333333333\"},\n\t\t\t{\"2\", \"7\", \"0.2857142857142857143\"},\n\t\t\t{\"2\", \"8\", \"0.25\"},\n\t\t\t{\"2\", \"9\", \"0.2222222222222222222\"},\n\n\t\t\t// 2 divided by 3\n\t\t\t{\"0.0000000000000000002\", \"3\", \"0.0000000000000000001\"},\n\t\t\t{\"0.0000000000000000002\", \"3.000000000000000000\", \"0.0000000000000000001\"},\n\t\t\t{\"2\", \"3\", \"0.6666666666666666667\"},\n\t\t\t{\"2.000000000000000000\", \"3\", \"0.6666666666666666667\"},\n\t\t\t{\"2\", \"3.000000000000000000\", \"0.6666666666666666667\"},\n\t\t\t{\"2.000000000000000000\", \"3.000000000000000000\", \"0.6666666666666666667\"},\n\t\t\t{\"0.0000000000000000002\", \"0.0000000000000000003\", \"0.6666666666666666667\"},\n\t\t\t{\"2\", \"0.0000000000000000003\", \"6666666666666666667\"},\n\t\t\t{\"2.000000000000000000\", \"0.0000000000000000003\", \"6666666666666666667\"},\n\n\t\t\t// Interest accrual\n\t\t\t{\"0.0001\", \"365\", \"0.0000002739726027397\"}, // no error\n\t\t\t{\"0.0001\", \"366\", \"0.0000002732240437158\"}, // no error\n\n\t\t\t// Captured during fuzzing\n\t\t\t{\"9223372036854775807\", \"-9223372036854775808\", \"-0.9999999999999999999\"},\n\t\t\t{\"0.000000000000000001\", \"20\", \"0.000000000000000000\"},\n\t\t\t{\"105\", \"0.999999999999999990\", \"105.0000000000000011\"},\n\t\t\t{\"0.05\", \"999999999999999954\", \"0.0000000000000000001\"},\n\t\t\t{\"9.99999999999999998\", \"185\", \"0.0540540540540540539\"},\n\t\t\t{\"7\", \"2.000000000000000002\", \"3.499999999999999997\"},\n\t\t\t{\"0.000000009\", \"999999999999999999\", \"0.000000000\"},\n\t\t\t{\"0.0000000000000000001\", \"9999999999999999999\", \"0.0000000000000000000\"},\n\t\t\t{\"9999999999999999999\", \"2\", \"5000000000000000000\"},\n\t\t\t{\"9999999999999999999\", \"5000000000000000000\", \"2\"},\n\t\t\t{\"1.000000000000000049\", \"-99.9999999999999924\", \"-0.0100000000000000013\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\te := MustParse(tt.e)\n\t\t\tgot, err := d.Quo(e)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.Quo(%q) failed: %v\", d, e, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"%q.Quo(%q) = %q, want %q\", d, e, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]struct {\n\t\t\td, e  string\n\t\t\tscale int\n\t\t}{\n\t\t\t\"zero 1\":     {\"1\", \"0\", 0},\n\t\t\t\"overflow 1\": {\"9999999999999999999\", \"0.001\", 0},\n\t\t\t\"scale 1\":    {\"1\", \"1\", MaxScale},\n\t\t\t\"scale 2\":    {\"0\", \"1\", MaxScale + 1},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\te := MustParse(tt.e)\n\t\t\t_, err := d.QuoExact(e, tt.scale)\n\t\t\tif err == nil {\n\t\t\t\tt.Errorf(\"%q.QuoExact(%q, %v) did not fail\", d, e, tt.scale)\n\t\t\t}\n\t\t}\n\t})\n}\n\nfunc TestDecimal_Inv(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, want string\n\t\t}{\n\t\t\t{\"0.1\", \"10\"},\n\t\t\t{\"1\", \"1\"},\n\t\t\t{\"10\", \"0.1\"},\n\t\t\t{\"2\", \"0.5\"},\n\t\t\t{\"2.0\", \"0.5\"},\n\t\t\t{\"2.00\", \"0.5\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\tgot, err := d.Inv()\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.Inv() failed: %v\", d, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"%q.Inv() = %q, want %q\", d, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]struct {\n\t\t\td string\n\t\t}{\n\t\t\t\"zero 1\":     {\"0\"},\n\t\t\t\"overflow 1\": {\"0.0000000000000000001\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\t_, err := d.Inv()\n\t\t\tif err == nil {\n\t\t\t\tt.Errorf(\"%q.Inv() did not fail\", d)\n\t\t\t}\n\t\t}\n\t})\n}\n\nfunc TestDecimal_QuoRem(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, e, wantQuo, wantRem string\n\t\t}{\n\t\t\t// Zeros\n\t\t\t{\"0\", \"1.000\", \"0\", \"0.000\"},\n\t\t\t{\"0.0\", \"1.000\", \"0\", \"0.000\"},\n\t\t\t{\"0.00\", \"1.000\", \"0\", \"0.000\"},\n\t\t\t{\"0.000\", \"1.000\", \"0\", \"0.000\"},\n\t\t\t{\"0.0000\", \"1.000\", \"0\", \"0.0000\"},\n\t\t\t{\"0.00000\", \"1.000\", \"0\", \"0.00000\"},\n\n\t\t\t{\"0.000\", \"1\", \"0\", \"0.000\"},\n\t\t\t{\"0.000\", \"1.0\", \"0\", \"0.000\"},\n\t\t\t{\"0.000\", \"1.00\", \"0\", \"0.000\"},\n\t\t\t{\"0.000\", \"1.000\", \"0\", \"0.000\"},\n\t\t\t{\"0.000\", \"1.0000\", \"0\", \"0.0000\"},\n\t\t\t{\"0.000\", \"1.00000\", \"0\", \"0.00000\"},\n\n\t\t\t// Ones\n\t\t\t{\"1\", \"1.000\", \"1\", \"0.000\"},\n\t\t\t{\"1.0\", \"1.000\", \"1\", \"0.000\"},\n\t\t\t{\"1.00\", \"1.000\", \"1\", \"0.000\"},\n\t\t\t{\"1.000\", \"1.000\", \"1\", \"0.000\"},\n\t\t\t{\"1.0000\", \"1.000\", \"1\", \"0.0000\"},\n\t\t\t{\"1.00000\", \"1.000\", \"1\", \"0.00000\"},\n\n\t\t\t{\"1.000\", \"1\", \"1\", \"0.000\"},\n\t\t\t{\"1.000\", \"1.0\", \"1\", \"0.000\"},\n\t\t\t{\"1.000\", \"1.00\", \"1\", \"0.000\"},\n\t\t\t{\"1.000\", \"1.000\", \"1\", \"0.000\"},\n\t\t\t{\"1.000\", \"1.0000\", \"1\", \"0.0000\"},\n\t\t\t{\"1.000\", \"1.00000\", \"1\", \"0.00000\"},\n\n\t\t\t// Signs\n\t\t\t{\"2.4\", \"1\", \"2\", \"0.4\"},\n\t\t\t{\"2.4\", \"-1\", \"-2\", \"0.4\"},\n\t\t\t{\"-2.4\", \"1\", \"-2\", \"-0.4\"},\n\t\t\t{\"-2.4\", \"-1\", \"2\", \"-0.4\"},\n\n\t\t\t// Scales\n\t\t\t{\"2.40\", \"1\", \"2\", \"0.40\"},\n\t\t\t{\"2.400\", \"1\", \"2\", \"0.400\"},\n\t\t\t{\"2.4\", \"2\", \"1\", \"0.4\"},\n\t\t\t{\"2.400\", \"2\", \"1\", \"0.400\"},\n\n\t\t\t// 1 divided by natural numbers\n\t\t\t{\"1\", \"1\", \"1\", \"0\"},\n\t\t\t{\"1\", \"2\", \"0\", \"1\"},\n\t\t\t{\"1\", \"3\", \"0\", \"1\"},\n\t\t\t{\"1\", \"4\", \"0\", \"1\"},\n\t\t\t{\"1\", \"5\", \"0\", \"1\"},\n\t\t\t{\"1\", \"6\", \"0\", \"1\"},\n\t\t\t{\"1\", \"7\", \"0\", \"1\"},\n\t\t\t{\"1\", \"8\", \"0\", \"1\"},\n\t\t\t{\"1\", \"9\", \"0\", \"1\"},\n\n\t\t\t// 2 divided by natural numbers\n\t\t\t{\"2\", \"1\", \"2\", \"0\"},\n\t\t\t{\"2\", \"2\", \"1\", \"0\"},\n\t\t\t{\"2\", \"3\", \"0\", \"2\"},\n\t\t\t{\"2\", \"4\", \"0\", \"2\"},\n\t\t\t{\"2\", \"5\", \"0\", \"2\"},\n\t\t\t{\"2\", \"6\", \"0\", \"2\"},\n\t\t\t{\"2\", \"7\", \"0\", \"2\"},\n\t\t\t{\"2\", \"8\", \"0\", \"2\"},\n\t\t\t{\"2\", \"9\", \"0\", \"2\"},\n\n\t\t\t// Closer and closer to five\n\t\t\t{\"12345\", \"4.9\", \"2519\", \"1.9\"},\n\t\t\t{\"12345\", \"4.99\", \"2473\", \"4.73\"},\n\t\t\t{\"12345\", \"4.999\", \"2469\", \"2.469\"},\n\t\t\t{\"12345\", \"4.9999\", \"2469\", \"0.2469\"},\n\t\t\t{\"12345\", \"4.99999\", \"2469\", \"0.02469\"},\n\t\t\t{\"12345\", \"4.999999\", \"2469\", \"0.002469\"},\n\t\t\t{\"12345\", \"4.9999999\", \"2469\", \"0.0002469\"},\n\t\t\t{\"12345\", \"4.99999999\", \"2469\", \"0.00002469\"},\n\t\t\t{\"12345\", \"4.999999999\", \"2469\", \"0.000002469\"},\n\t\t\t{\"12345\", \"4.9999999999\", \"2469\", \"0.0000002469\"},\n\t\t\t{\"12345\", \"4.99999999999\", \"2469\", \"0.00000002469\"},\n\t\t\t{\"12345\", \"4.999999999999\", \"2469\", \"0.000000002469\"},\n\t\t\t{\"12345\", \"4.9999999999999\", \"2469\", \"0.0000000002469\"},\n\t\t\t{\"12345\", \"4.99999999999999\", \"2469\", \"0.00000000002469\"},\n\t\t\t{\"12345\", \"4.999999999999999\", \"2469\", \"0.000000000002469\"},\n\t\t\t{\"12345\", \"4.9999999999999999\", \"2469\", \"0.0000000000002469\"},\n\t\t\t{\"12345\", \"4.99999999999999999\", \"2469\", \"0.00000000000002469\"},\n\t\t\t{\"12345\", \"4.999999999999999999\", \"2469\", \"0.000000000000002469\"},\n\t\t\t{\"12345\", \"5\", \"2469\", \"0\"},\n\t\t\t{\"12345\", \"5.000000000000000001\", \"2468\", \"4.999999999999997532\"},\n\t\t\t{\"12345\", \"5.00000000000000001\", \"2468\", \"4.99999999999997532\"},\n\t\t\t{\"12345\", \"5.0000000000000001\", \"2468\", \"4.9999999999997532\"},\n\t\t\t{\"12345\", \"5.000000000000001\", \"2468\", \"4.999999999997532\"},\n\t\t\t{\"12345\", \"5.00000000000001\", \"2468\", \"4.99999999997532\"},\n\t\t\t{\"12345\", \"5.0000000000001\", \"2468\", \"4.9999999997532\"},\n\t\t\t{\"12345\", \"5.000000000001\", \"2468\", \"4.999999997532\"},\n\t\t\t{\"12345\", \"5.00000000001\", \"2468\", \"4.99999997532\"},\n\t\t\t{\"12345\", \"5.0000000001\", \"2468\", \"4.9999997532\"},\n\t\t\t{\"12345\", \"5.000000001\", \"2468\", \"4.999997532\"},\n\t\t\t{\"12345\", \"5.00000001\", \"2468\", \"4.99997532\"},\n\t\t\t{\"12345\", \"5.0000001\", \"2468\", \"4.9997532\"},\n\t\t\t{\"12345\", \"5.000001\", \"2468\", \"4.997532\"},\n\t\t\t{\"12345\", \"5.00001\", \"2468\", \"4.97532\"},\n\t\t\t{\"12345\", \"5.0001\", \"2468\", \"4.7532\"},\n\t\t\t{\"12345\", \"5.001\", \"2468\", \"2.532\"},\n\t\t\t{\"12345\", \"5.01\", \"2464\", \"0.36\"},\n\t\t\t{\"12345\", \"5.1\", \"2420\", \"3.0\"},\n\n\t\t\t// Other tests\n\t\t\t{\"41\", \"21\", \"1\", \"20\"},\n\t\t\t{\"4.2\", \"3.1000003\", \"1\", \"1.0999997\"},\n\t\t\t{\"1.000000000000000000\", \"0.000000000000000003\", \"333333333333333333\", \"0.000000000000000001\"},\n\t\t\t{\"1.000000000000000001\", \"0.000000000000000003\", \"333333333333333333\", \"0.000000000000000002\"},\n\t\t\t{\"3\", \"0.9999999999999999999\", \"3\", \"0.0000000000000000003\"},\n\t\t\t{\"0.9999999999999999999\", \"3\", \"0\", \"0.9999999999999999999\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\te := MustParse(tt.e)\n\t\t\tgotQuo, gotRem, err := d.QuoRem(e)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.QuoRem(%q) failed: %v\", d, e, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twantQuo := MustParse(tt.wantQuo)\n\t\t\twantRem := MustParse(tt.wantRem)\n\t\t\tif gotQuo != wantQuo || gotRem != wantRem {\n\t\t\t\tt.Errorf(\"%q.QuoRem(%q) = (%q, %q), want (%q, %q)\", d, e, gotQuo, gotRem, wantQuo, wantRem)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := map[string]struct {\n\t\t\td, e string\n\t\t}{\n\t\t\t\"zero 1\":     {\"1\", \"0\"},\n\t\t\t\"overflow 1\": {\"9999999999999999999\", \"0.0000000000000000001\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\te := MustParse(tt.e)\n\t\t\t_, _, err := d.QuoRem(e)\n\t\t\tif err == nil {\n\t\t\t\tt.Errorf(\"%q.QuoRem(%q) did not fail\", d, e)\n\t\t\t}\n\t\t}\n\t})\n}\n\nfunc TestDecimal_Cmp(t *testing.T) {\n\ttests := []struct {\n\t\td, e string\n\t\twant int\n\t}{\n\t\t{\"-2\", \"-2\", 0},\n\t\t{\"-2\", \"-1\", -1},\n\t\t{\"-2\", \"0\", -1},\n\t\t{\"-2\", \"1\", -1},\n\t\t{\"-2\", \"2\", -1},\n\t\t{\"-1\", \"-2\", 1},\n\t\t{\"-1\", \"-1\", 0},\n\t\t{\"-1\", \"0\", -1},\n\t\t{\"-1\", \"1\", -1},\n\t\t{\"-1\", \"2\", -1},\n\t\t{\"0\", \"-2\", 1},\n\t\t{\"0\", \"-1\", 1},\n\t\t{\"0\", \"0\", 0},\n\t\t{\"0\", \"1\", -1},\n\t\t{\"0\", \"2\", -1},\n\t\t{\"1\", \"-2\", 1},\n\t\t{\"1\", \"-1\", 1},\n\t\t{\"1\", \"0\", 1},\n\t\t{\"1\", \"1\", 0},\n\t\t{\"1\", \"2\", -1},\n\t\t{\"2\", \"-2\", 1},\n\t\t{\"2\", \"-1\", 1},\n\t\t{\"2\", \"0\", 1},\n\t\t{\"2\", \"1\", 1},\n\t\t{\"2\", \"2\", 0},\n\t\t{\"2\", \"2.0\", 0},\n\t\t{\"2\", \"2.00\", 0},\n\t\t{\"2\", \"2.000\", 0},\n\t\t{\"2\", \"2.0000\", 0},\n\t\t{\"2\", \"2.00000\", 0},\n\t\t{\"2\", \"2.000000\", 0},\n\t\t{\"2\", \"2.0000000\", 0},\n\t\t{\"2\", \"2.00000000\", 0},\n\t\t{\"9999999999999999999\", \"0.9999999999999999999\", 1},\n\t\t{\"0.9999999999999999999\", \"9999999999999999999\", -1},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\te := MustParse(tt.e)\n\t\tgot := d.Cmp(e)\n\t\tif got != tt.want {\n\t\t\tt.Errorf(\"%q.Cmp(%q) = %v, want %v\", d, e, got, tt.want)\n\t\t}\n\t}\n}\n\nfunc TestDecimal_Max(t *testing.T) {\n\ttests := []struct {\n\t\td, e, want string\n\t}{\n\t\t{\"-2\", \"-2\", \"-2\"},\n\t\t{\"-2\", \"-1\", \"-1\"},\n\t\t{\"-2\", \"0\", \"0\"},\n\t\t{\"-2\", \"1\", \"1\"},\n\t\t{\"-2\", \"2\", \"2\"},\n\t\t{\"-1\", \"-2\", \"-1\"},\n\t\t{\"-1\", \"-1\", \"-1\"},\n\t\t{\"-1\", \"0\", \"0\"},\n\t\t{\"-1\", \"1\", \"1\"},\n\t\t{\"-1\", \"2\", \"2\"},\n\t\t{\"0\", \"-2\", \"0\"},\n\t\t{\"0\", \"-1\", \"0\"},\n\t\t{\"0\", \"0\", \"0\"},\n\t\t{\"0\", \"1\", \"1\"},\n\t\t{\"0\", \"2\", \"2\"},\n\t\t{\"1\", \"-2\", \"1\"},\n\t\t{\"1\", \"-1\", \"1\"},\n\t\t{\"1\", \"0\", \"1\"},\n\t\t{\"1\", \"1\", \"1\"},\n\t\t{\"1\", \"2\", \"2\"},\n\t\t{\"2\", \"-2\", \"2\"},\n\t\t{\"2\", \"-1\", \"2\"},\n\t\t{\"2\", \"0\", \"2\"},\n\t\t{\"2\", \"1\", \"2\"},\n\t\t{\"2\", \"2\", \"2\"},\n\t\t{\"0.000\", \"0.0\", \"0.0\"},\n\t\t{\"0.0\", \"0.000\", \"0.0\"},\n\t\t{\"-0.000\", \"-0.0\", \"0.0\"},\n\t\t{\"-0.0\", \"-0.000\", \"0.0\"},\n\t\t{\"1.23\", \"1.2300\", \"1.23\"},\n\t\t{\"1.2300\", \"1.23\", \"1.23\"},\n\t\t{\"-1.23\", \"-1.2300\", \"-1.23\"},\n\t\t{\"-1.2300\", \"-1.23\", \"-1.23\"},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\te := MustParse(tt.e)\n\t\tgot := d.Max(e)\n\t\twant := MustParse(tt.want)\n\t\tif got != want {\n\t\t\tt.Errorf(\"%q.Max(%q) = %q, want %q\", d, e, got, want)\n\t\t}\n\t}\n}\n\nfunc TestDecimal_Min(t *testing.T) {\n\ttests := []struct {\n\t\td, e, want string\n\t}{\n\t\t{\"-2\", \"-2\", \"-2\"},\n\t\t{\"-2\", \"-1\", \"-2\"},\n\t\t{\"-2\", \"0\", \"-2\"},\n\t\t{\"-2\", \"1\", \"-2\"},\n\t\t{\"-2\", \"2\", \"-2\"},\n\t\t{\"-1\", \"-2\", \"-2\"},\n\t\t{\"-1\", \"-1\", \"-1\"},\n\t\t{\"-1\", \"0\", \"-1\"},\n\t\t{\"-1\", \"1\", \"-1\"},\n\t\t{\"-1\", \"2\", \"-1\"},\n\t\t{\"0\", \"-2\", \"-2\"},\n\t\t{\"0\", \"-1\", \"-1\"},\n\t\t{\"0\", \"0\", \"0\"},\n\t\t{\"0\", \"1\", \"0\"},\n\t\t{\"0\", \"2\", \"0\"},\n\t\t{\"1\", \"-2\", \"-2\"},\n\t\t{\"1\", \"-1\", \"-1\"},\n\t\t{\"1\", \"0\", \"0\"},\n\t\t{\"1\", \"1\", \"1\"},\n\t\t{\"1\", \"2\", \"1\"},\n\t\t{\"2\", \"-2\", \"-2\"},\n\t\t{\"2\", \"-1\", \"-1\"},\n\t\t{\"2\", \"0\", \"0\"},\n\t\t{\"2\", \"1\", \"1\"},\n\t\t{\"2\", \"2\", \"2\"},\n\t\t{\"0.000\", \"0.0\", \"0.000\"},\n\t\t{\"0.0\", \"0.000\", \"0.000\"},\n\t\t{\"-0.000\", \"-0.0\", \"0.000\"},\n\t\t{\"-0.0\", \"-0.000\", \"0.000\"},\n\t\t{\"1.23\", \"1.2300\", \"1.2300\"},\n\t\t{\"1.2300\", \"1.23\", \"1.2300\"},\n\t\t{\"-1.23\", \"-1.2300\", \"-1.2300\"},\n\t\t{\"-1.2300\", \"-1.23\", \"-1.2300\"},\n\t}\n\tfor _, tt := range tests {\n\t\td := MustParse(tt.d)\n\t\te := MustParse(tt.e)\n\t\tgot := d.Min(e)\n\t\twant := MustParse(tt.want)\n\t\tif got != want {\n\t\t\tt.Errorf(\"%q.Min(%q) = %q, want %q\", d, e, got, want)\n\t\t}\n\t}\n}\n\n//nolint:revive\nfunc TestDecimal_Clamp(t *testing.T) {\n\tt.Run(\"success\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, min, max, want string\n\t\t}{\n\t\t\t{\"0\", \"-2\", \"-1\", \"-1\"},\n\t\t\t{\"0\", \"-1\", \"1\", \"0\"},\n\t\t\t{\"0\", \"1\", \"2\", \"1\"},\n\t\t\t{\"0.000\", \"0.0\", \"0.000\", \"0.000\"},\n\t\t\t{\"0.000\", \"0.000\", \"0.0\", \"0.000\"},\n\t\t\t{\"0.0\", \"0.0\", \"0.000\", \"0.0\"},\n\t\t\t{\"0.0\", \"0.000\", \"0.0\", \"0.0\"},\n\t\t\t{\"0.000\", \"0.000\", \"1\", \"0.000\"},\n\t\t\t{\"0.000\", \"0.0\", \"1\", \"0.0\"},\n\t\t\t{\"0.0\", \"0.000\", \"1\", \"0.0\"},\n\t\t\t{\"0.0\", \"0.0\", \"1\", \"0.0\"},\n\t\t\t{\"0.000\", \"-1\", \"0.000\", \"0.000\"},\n\t\t\t{\"0.000\", \"-1\", \"0.0\", \"0.000\"},\n\t\t\t{\"0.0\", \"-1\", \"0.000\", \"0.000\"},\n\t\t\t{\"0.0\", \"-1\", \"0.0\", \"0.0\"},\n\t\t\t{\"1.2300\", \"1.2300\", \"2\", \"1.2300\"},\n\t\t\t{\"1.2300\", \"1.23\", \"2\", \"1.23\"},\n\t\t\t{\"1.23\", \"1.2300\", \"2\", \"1.23\"},\n\t\t\t{\"1.23\", \"1.23\", \"2\", \"1.23\"},\n\t\t\t{\"1.2300\", \"1\", \"1.2300\", \"1.2300\"},\n\t\t\t{\"1.2300\", \"1\", \"1.23\", \"1.2300\"},\n\t\t\t{\"1.23\", \"1\", \"1.2300\", \"1.2300\"},\n\t\t\t{\"1.23\", \"1\", \"1.23\", \"1.23\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\tmin := MustParse(tt.min)\n\t\t\tmax := MustParse(tt.max)\n\t\t\tgot, err := d.Clamp(min, max)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.Clamp(%q, %q) failed: %v\", d, min, max, err)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\twant := MustParse(tt.want)\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"%q.Clamp(%q, %q) = %q, want %q\", d, min, max, got, want)\n\t\t\t}\n\t\t}\n\t})\n\n\tt.Run(\"error\", func(t *testing.T) {\n\t\ttests := []struct {\n\t\t\td, min, max string\n\t\t}{\n\t\t\t{\"0\", \"1\", \"-1\"},\n\t\t}\n\t\tfor _, tt := range tests {\n\t\t\td := MustParse(tt.d)\n\t\t\tmin := MustParse(tt.min)\n\t\t\tmax := MustParse(tt.max)\n\t\t\t_, err := d.Clamp(min, max)\n\t\t\tif err == nil {\n\t\t\t\tt.Errorf(\"%q.Clamp(%q, %q) did not fail\", d, min, max)\n\t\t\t}\n\t\t}\n\t})\n}\n\nfunc TestNullDecimal_Interfaces(t *testing.T) {\n\tvar n any = NullDecimal{}\n\t_, ok := n.(driver.Valuer)\n\tif !ok {\n\t\tt.Errorf(\"%T does not implement driver.Valuer\", n)\n\t}\n\n\tn = &NullDecimal{}\n\t_, ok = n.(sql.Scanner)\n\tif !ok {\n\t\tt.Errorf(\"%T does not implement sql.Scanner\", n)\n\t}\n}\n\nfunc TestNullDecimal_Scan(t *testing.T) {\n\tt.Run(\"[]byte\", func(t *testing.T) {\n\t\ttests := []string{\".\"}\n\t\tfor _, tt := range tests {\n\t\t\tgot := NullDecimal{}\n\t\t\terr := got.Scan([]byte(tt))\n\t\t\tif err == nil {\n\t\t\t\tt.Errorf(\"Scan(%q) did not fail\", tt)\n\t\t\t}\n\t\t}\n\t})\n}\n\n/******************************************************\n* Fuzzing\n******************************************************/\n\nvar corpus = []struct {\n\tneg   bool\n\tscale int\n\tcoef  uint64\n}{\n\t// zero\n\t{false, 0, 0},\n\n\t// positive\n\t{false, 0, 1},\n\t{false, 0, 3},\n\t{false, 0, 9999999999999999999},\n\t{false, 19, 3},\n\t{false, 19, 1},\n\t{false, 19, 9999999999999999999},\n\n\t// negative\n\t{true, 0, 1},\n\t{true, 0, 3},\n\t{true, 0, 9999999999999999999},\n\t{true, 19, 1},\n\t{true, 19, 3},\n\t{true, 19, 9999999999999999999},\n}\n\nfunc FuzzParse(f *testing.F) {\n\tfor _, c := range corpus {\n\t\tfor s := range MaxScale + 1 {\n\t\t\td, err := newSafe(c.neg, fint(c.coef), c.scale)\n\t\t\tif err != nil {\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\tf.Add(d.bytes(), s)\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, text []byte, scale int) {\n\t\t\tgot, err := parseFint(text, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := parseBint(text, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"parseBint(%q) failed: %v\", text, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif got.CmpTotal(want) != 0 {\n\t\t\t\tt.Errorf(\"parseBint(%q) = %q, whereas parseFint(%q) = %q\", text, want, text, got)\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzBSON(f *testing.F) {\n\tfor _, c := range corpus {\n\t\td := newUnsafe(c.neg, fint(c.coef), c.scale)\n\t\tf.Add(byte(19), d.ieeeDecimal128())\n\t}\n\tf.Fuzz(\n\t\tfunc(_ *testing.T, typ byte, data []byte) {\n\t\t\tvar d Decimal\n\t\t\t_ = d.UnmarshalBSONValue(typ, data)\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_String_Parse(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tf.Add(d.neg, d.scale, d.coef)\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, neg bool, scale int, coef uint64) {\n\t\t\td, err := newSafe(neg, fint(coef), scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\ts := d.String()\n\t\t\tgot, err := Parse(s)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"Parse(%q) failed: %v\", s, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant := d\n\n\t\t\tif got.CmpTotal(want) != 0 {\n\t\t\t\tt.Errorf(\"Parse(%q) = %v, want %v\", s, got, want)\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_IEEE_ParseIEEE(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tf.Add(d.neg, d.scale, d.coef)\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, neg bool, scale int, coef uint64) {\n\t\t\td, err := newSafe(neg, fint(coef), scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tb := d.ieeeDecimal128()\n\t\t\tgot, err := parseIEEEDecimal128(b)\n\t\t\tif err != nil {\n\t\t\t\tt.Logf(\"%q.ieeeDecimal128() = % x\", d, b)\n\t\t\t\tt.Errorf(\"parseIEEEDecimal128(% x) failed: %v\", b, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant := d\n\n\t\t\tif got.CmpTotal(want) != 0 {\n\t\t\t\tt.Logf(\"%q.ieeeDecimal128() = % x\", d, b)\n\t\t\t\tt.Errorf(\"parseIEEEDecimal128(% x) = %v, want %v\", b, got, want)\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Binary_Text(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tf.Add(d.neg, d.scale, d.coef)\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, neg bool, scale int, coef uint64) {\n\t\t\td, err := newSafe(neg, fint(coef), scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tb, err := d.MarshalBinary()\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.MarshalBinary() failed: %v\", d, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tvar got Decimal\n\t\t\terr = got.UnmarshalText(b)\n\t\t\tif err != nil {\n\t\t\t\tt.Logf(\"%q.MarshalBinary() = % x\", d, b)\n\t\t\t\tt.Errorf(\"UnmarshalText(% x) failed: %v\", b, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant := d\n\n\t\t\tif got.CmpTotal(want) != 0 {\n\t\t\t\tt.Logf(\"%q.MarshalBinary() = % x\", d, b)\n\t\t\t\tt.Errorf(\"UnmarshalText(% x) = %v, want %v\", b, got, want)\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Text_Binary(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tf.Add(d.neg, d.scale, d.coef)\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, neg bool, scale int, coef uint64) {\n\t\t\td, err := newSafe(neg, fint(coef), scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tb, err := d.MarshalText()\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.MarshalText() failed: %v\", d, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tvar got Decimal\n\t\t\terr = got.UnmarshalBinary(b)\n\t\t\tif err != nil {\n\t\t\t\tt.Logf(\"%q.MarshalText() = % x\", d, b)\n\t\t\t\tt.Errorf(\"UnmarshalBinary(% x) failed: %v\", b, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant := d\n\n\t\t\tif got.CmpTotal(want) != 0 {\n\t\t\t\tt.Logf(\"%q.MarshalText() = % x\", d, b)\n\t\t\t\tt.Errorf(\"UnmarshalBinary(% x) = %v, want %v\", b, got, want)\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Int64_NewFromInt64(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor s := range MaxScale + 1 {\n\t\t\tf.Add(d.neg, d.scale, d.coef, s)\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64, scale int) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tw, f, ok := d.Int64(scale)\n\t\t\tif !ok {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tgot, err := NewFromInt64(w, f, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Logf(\"%q.Int64(%v) = (%v, %v)\", d, scale, w, f)\n\t\t\t\tt.Errorf(\"NewFromInt64(%v, %v, %v) failed: %v\", w, f, scale, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant := d.Round(scale)\n\n\t\t\tif got.Cmp(want) != 0 {\n\t\t\t\tt.Logf(\"%q.Int64(%v) = (%v, %v)\", d, scale, w, f)\n\t\t\t\tt.Errorf(\"NewFromInt64(%v, %v, %v) = %v, want %v\", w, f, scale, got, want)\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Float64_NewFromFloat64(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tf.Add(d.neg, d.scale, d.coef)\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil || d.Prec() > 17 {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tf, ok := d.Float64()\n\t\t\tif !ok {\n\t\t\t\tt.Errorf(\"%q.Float64() failed\", d)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tgot, err := NewFromFloat64(f)\n\t\t\tif err != nil {\n\t\t\t\tt.Logf(\"%q.Float64() = %v\", d, f)\n\t\t\t\tt.Errorf(\"NewFromFloat64(%v) failed: %v\", f, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant := d\n\n\t\t\tif got.Cmp(want) != 0 {\n\t\t\t\tt.Errorf(\"NewFromFloat64(%v) = %v, want %v\", f, got, want)\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Mul(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor _, e := range corpus {\n\t\t\tfor s := range MaxScale + 1 {\n\t\t\t\tf.Add(d.neg, d.scale, d.coef, e.neg, e.scale, e.coef, s)\n\t\t\t}\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64, eneg bool, escale int, ecoef uint64, scale int) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\te, err := newSafe(eneg, fint(ecoef), escale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := d.mulFint(e, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := d.mulBint(e, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"mulBint(%q, %q, %v) failed: %v\", d, e, scale, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif got.CmpTotal(want) != 0 {\n\t\t\t\tt.Errorf(\"mulBint(%q, %q, %v) = %q, whereas mulFint(%q, %q, %v) = %q\", d, e, scale, want, d, e, scale, got)\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Mul_Prod(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor _, e := range corpus {\n\t\t\tf.Add(d.neg, d.scale, d.coef, e.neg, e.scale, e.coef)\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64, eneg bool, escale int, ecoef uint64) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\te, err := newSafe(eneg, fint(ecoef), escale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := d.Mul(e)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := Prod(d, e)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"Prod(%q, %q) failed: %v\", d, e, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif got.CmpTotal(want) != 0 {\n\t\t\t\tt.Errorf(\"Prod(%q, %q) = %q, whereas Mul(%q, %q) = %q\", d, e, want, d, e, got)\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_AddMul(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor _, e := range corpus {\n\t\t\tfor _, g := range corpus {\n\t\t\t\tfor s := range MaxScale + 1 {\n\t\t\t\t\tf.Add(d.neg, d.scale, d.coef, e.neg, e.scale, e.coef, g.neg, g.scale, g.coef, s)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64, eneg bool, escale int, ecoef uint64, gneg bool, gscale int, gcoef uint64, scale int) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\te, err := newSafe(eneg, fint(ecoef), escale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tg, err := newSafe(gneg, fint(gcoef), gscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := d.addMulFint(e, g, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := d.addMulBint(e, g, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"addMulBint(%q, %q, %q, %v) failed: %v\", d, e, g, scale, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif got.CmpTotal(want) != 0 {\n\t\t\t\tt.Errorf(\"addMulBint(%q, %q, %q, %v) = %q, whereas addMulFint(%q, %q, %q, %v) = %q\", d, e, g, scale, want, d, e, g, scale, got)\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Add_AddMul(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor _, e := range corpus {\n\t\t\tfor s := range MaxScale + 1 {\n\t\t\t\tf.Add(d.neg, d.scale, d.coef, e.neg, e.scale, e.coef, s)\n\t\t\t}\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64, eneg bool, escale int, ecoef uint64, scale int) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\te, err := newSafe(eneg, fint(ecoef), escale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := d.AddExact(e, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := d.AddMulExact(e, One, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"AddMulExact(%q, %q, %v) failed: %v\", d, e, scale, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif got.CmpTotal(want) != 0 {\n\t\t\t\tt.Errorf(\"AddMulExact(%q, %q, %q, %v) = %q, whereas AddExact(%q, %q, %v) = %q\", d, e, One, scale, want, d, e, scale, got)\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Mul_AddMul(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor _, e := range corpus {\n\t\t\tfor s := range MaxScale + 1 {\n\t\t\t\tf.Add(d.neg, d.scale, d.coef, e.neg, e.scale, e.coef, s)\n\t\t\t}\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64, eneg bool, escale int, ecoef uint64, scale int) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\te, err := newSafe(eneg, fint(ecoef), escale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := d.MulExact(e, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := Zero.AddMulExact(d, e, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"AddMulExact(%q, %q, %v) failed: %v\", d, e, scale, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif got.CmpTotal(want) != 0 {\n\t\t\t\tt.Errorf(\"AddMulExact(%q, %q, %q, %v) = %q, whereas MulExact(%q, %q, %v) = %q\", Zero, d, e, scale, want, d, e, scale, got)\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_AddQuo(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor _, e := range corpus {\n\t\t\tfor _, g := range corpus {\n\t\t\t\tfor s := range MaxScale + 1 {\n\t\t\t\t\tf.Add(d.neg, d.scale, d.coef, e.neg, e.scale, e.coef, g.neg, g.scale, g.coef, s)\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64, eneg bool, escale int, ecoef uint64, gneg bool, gscale int, gcoef uint64, scale int) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\te, err := newSafe(eneg, fint(ecoef), escale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tg, err := newSafe(gneg, fint(gcoef), gscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := d.addQuoFint(e, g, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := d.addQuoBint(e, g, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"addQuoBint(%q, %q, %q, %v) failed: %v\", d, e, g, scale, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif got.Cmp(want) != 0 {\n\t\t\t\tt.Errorf(\"addQuoBint(%q, %q, %q, %v) = %q, whereas addQuoFint(%q, %q, %q, %v) = %q\", d, e, g, scale, want, d, e, g, scale, got)\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Add_AddQuo(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor _, e := range corpus {\n\t\t\tfor s := range MaxScale + 1 {\n\t\t\t\tf.Add(d.neg, d.scale, d.coef, e.neg, e.scale, e.coef, s)\n\t\t\t}\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64, eneg bool, escale int, ecoef uint64, scale int) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\te, err := newSafe(eneg, fint(ecoef), escale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := d.AddExact(e, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := d.AddQuoExact(e, One, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"AddQuoExact(%q, %q, %v) failed: %v\", d, e, scale, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif got.CmpTotal(want) != 0 {\n\t\t\t\tt.Errorf(\"AddQuoExact(%q, %q, %q, %v) = %q, whereas AddExact(%q, %q, %v) = %q\", d, e, One, scale, want, d, e, scale, got)\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Quo_AddQuo(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor _, e := range corpus {\n\t\t\tfor s := 0; s <= MaxScale; s++ {\n\t\t\t\tf.Add(d.neg, d.scale, d.coef, e.neg, e.scale, e.coef, s)\n\t\t\t}\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64, eneg bool, escale int, ecoef uint64, scale int) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\te, err := newSafe(eneg, fint(ecoef), escale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := d.QuoExact(e, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := Zero.AddQuoExact(d, e, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"AddQuoExact(%q, %q, %v) failed: %v\", d, e, scale, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif got.CmpTotal(want) != 0 {\n\t\t\t\tt.Errorf(\"AddQuoExact(%q, %q, %q, %v) = %q, whereas QuoExact(%q, %q, %v) = %q\", Zero, d, e, scale, want, d, e, scale, got)\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Add(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor _, e := range corpus {\n\t\t\tfor s := range MaxScale + 1 {\n\t\t\t\tf.Add(d.neg, d.scale, d.coef, e.neg, e.scale, e.coef, s)\n\t\t\t}\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64, eneg bool, escale int, ecoef uint64, scale int) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\te, err := newSafe(eneg, fint(ecoef), escale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := d.addFint(e, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := d.addBint(e, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"addBint(%q, %q, %v) failed: %v\", d, e, scale, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif got.Cmp(want) != 0 {\n\t\t\t\tt.Errorf(\"addBint(%q, %q, %v) = %q, whereas addFint(%q, %q, %v) = %q\", d, e, scale, want, d, e, scale, got)\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Add_Sum(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor _, e := range corpus {\n\t\t\tf.Add(d.neg, d.scale, d.coef, e.neg, e.scale, e.coef)\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64, eneg bool, escale int, ecoef uint64) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\te, err := newSafe(eneg, fint(ecoef), escale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := d.Add(e)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := Sum(d, e)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"Sum(%q, %q) failed: %v\", d, e, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif got.CmpTotal(want) != 0 {\n\t\t\t\tt.Errorf(\"Sum(%q, %q) = %q, whereas Add(%q, %q) = %q\", d, e, want, d, e, got)\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Quo(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor _, e := range corpus {\n\t\t\tfor s := range MaxScale + 1 {\n\t\t\t\tf.Add(d.neg, d.scale, d.coef, e.neg, e.scale, e.coef, s)\n\t\t\t}\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64, eneg bool, escale int, ecoef uint64, scale int) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\te, err := newSafe(eneg, fint(ecoef), escale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := d.quoFint(e, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := d.quoBint(e, scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"quoBint(%q, %q, %v) failed: %v\", d, e, scale, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif got.Cmp(want) != 0 {\n\t\t\t\tt.Errorf(\"quoBint(%q, %q, %v) = %q, whereas quoFint(%q, %q, %v) = %q\", d, e, scale, want, d, e, scale, got)\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_QuoRem(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor _, e := range corpus {\n\t\t\tf.Add(d.neg, d.scale, d.coef, e.neg, e.scale, e.coef)\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64, eneg bool, escale int, ecoef uint64) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\te, err := newSafe(eneg, fint(ecoef), escale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgotQuo, gotRem, err := d.quoRemFint(e)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif gotQuo.Scale() != 0 {\n\t\t\t\tt.Errorf(\"quoRemFint(%q, %q) = (%q, _), expected integer quotient\", d, e, gotQuo)\n\t\t\t}\n\t\t\tif gotRem.Scale() != max(d.Scale(), e.Scale()) {\n\t\t\t\tt.Errorf(\"quoRemFint(%q, %q) = (_, %q), expected remainder with scale %d\", d, e, gotRem, max(d.Scale(), e.Scale()))\n\t\t\t}\n\t\t\tif !gotRem.IsZero() && gotRem.Sign() != d.Sign() {\n\t\t\t\tt.Errorf(\"quoRemFint(%q, %q) = (_, %q), expected remainder with the same sign as the dividend\", d, e, gotRem)\n\t\t\t}\n\n\t\t\twantQuo, wantRem, err := d.quoRemBint(e)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"quoRemBint(%q, %q) failed: %v\", d, e, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif gotQuo.CmpTotal(wantQuo) != 0 || gotRem.CmpTotal(wantRem) != 0 {\n\t\t\t\tt.Errorf(\"quoRemBint(%q, %q) = (%q, %q), whereas quoRemFint(%q, %q) = (%q, %q)\", d, e, wantQuo, wantRem, d, e, gotQuo, gotRem)\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Cmp(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor _, e := range corpus {\n\t\t\tf.Add(d.neg, d.scale, d.coef, e.neg, e.scale, e.coef)\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64, eneg bool, escale int, ecoef uint64) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\te, err := newSafe(eneg, fint(ecoef), escale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := d.cmpFint(e)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant := d.cmpBint(e)\n\n\t\t\tif got != want {\n\t\t\t\tt.Errorf(\"cmpBint(%q, %q) = %v, whereas cmpFint(%q, %q) = %v\", d, e, want, d, e, got)\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Sqrt_PowInt(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tf.Add(d.neg, d.scale, d.coef)\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, neg bool, scale int, coef uint64) {\n\t\t\td, err := newSafe(neg, fint(coef), scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := d.Sqrt()\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tgot, err = got.PowInt(2)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant := d\n\n\t\t\tif cmp, err := cmpULP(got, want, 3); err != nil {\n\t\t\t\tt.Errorf(\"cmpULP(%q, %q) failed: %v\", got, want, err)\n\t\t\t} else if cmp != 0 {\n\t\t\t\tt.Errorf(\"%q.Sqrt().PowInt(2) = %q, want %q\", want, got, want)\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Pow_Sqrt(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tf.Add(d.neg, d.scale, d.coef)\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, neg bool, scale int, coef uint64) {\n\t\t\td, err := newSafe(neg, fint(coef), scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\thalf := MustNew(5, 1)\n\t\t\tgot, err := d.Pow(half)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := d.Sqrt()\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.Sqrt() failed: %v\", d, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif got.Cmp(want) != 0 {\n\t\t\t\tt.Errorf(\"%q.Pow(%v) = %q, whereas %q.Sqrt() = %q\", d, half, got, d, want)\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Pow_PowInt(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor _, e := range []int{-10, -5, -1, 1, 5, 10} {\n\t\t\tf.Add(d.neg, d.scale, d.coef, e)\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, neg bool, scale int, coef uint64, power int) {\n\t\t\td, err := newSafe(neg, fint(coef), scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\te, err := New(int64(power), 0)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := d.Pow(e)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := d.PowInt(power)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.PowInt(%v) failed: %v\", d, power, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif got.CmpTotal(want) != 0 {\n\t\t\t\tt.Errorf(\"%q.Pow(%v) = %q, whereas %q.PowInt(%v) = %q\", d, power, got, d, power, want)\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Pow_Exp(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tf.Add(d.neg, d.scale, d.coef)\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, neg bool, scale int, coef uint64) {\n\t\t\td, err := newSafe(neg, fint(coef), scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := E.Pow(d)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := d.Exp()\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"%q.Exp() failed: %v\", d, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif cmp, err := cmpULP(got, want, 55); err != nil {\n\t\t\t\tt.Errorf(\"cmpULP(%q, %q) failed: %v\", got, want, err)\n\t\t\t} else if cmp != 0 {\n\t\t\t\tt.Errorf(\"%v.Pow(%q) = %q, whereas %q.Exp() = %q\", E, d, got, d, want)\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Log_Exp(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tf.Add(d.neg, d.scale, d.coef)\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, neg bool, scale int, coef uint64) {\n\t\t\td, err := newSafe(neg, fint(coef), scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := d.Log()\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tgot, err = got.Exp()\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant := d\n\n\t\t\tif cmp, err := cmpULP(got, want, 70); err != nil {\n\t\t\t\tt.Errorf(\"cmpULP(%q, %q) failed: %v\", got, want, err)\n\t\t\t\treturn\n\t\t\t} else if cmp != 0 {\n\t\t\t\tt.Errorf(\"%q.Log().Exp() = %q, want %q\", want, got, want)\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Expm1_Exp(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tf.Add(d.neg, d.scale, d.coef)\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, neg bool, scale int, coef uint64) {\n\t\t\td, err := newSafe(neg, fint(coef), scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := d.Exp()\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tgot, err = got.Sub(One)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := d.Expm1()\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif cmp, err := cmpULP(got, want, 5); err != nil {\n\t\t\t\tt.Errorf(\"cmpULP(%q, %q) failed: %v\", got, want, err)\n\t\t\t\treturn\n\t\t\t} else if cmp != 0 {\n\t\t\t\tt.Errorf(\"%q.Exp().Sub(1) = %q, whereas %q.Expm1() = %q\", d, got, d, want)\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Log1p_Log(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tf.Add(d.neg, d.scale, d.coef)\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, neg bool, scale int, coef uint64) {\n\t\t\td, err := newSafe(neg, fint(coef), scale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot, err := d.Add(One)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tgot, err = got.Log()\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := d.Log1p()\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif cmp, err := cmpULP(got, want, 5); err != nil {\n\t\t\t\tt.Errorf(\"cmpULP(%q, %q) failed: %v\", got, want, err)\n\t\t\t\treturn\n\t\t\t} else if cmp != 0 {\n\t\t\t\tt.Errorf(\"%q.Add(1).Log() = %q, whereas %q.Log1p() = %q\", d, got, d, want)\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\n// cmpULP compares decimals and returns 0 if they are within specified number of ULPs.\nfunc cmpULP(d, e Decimal, ulps int) (int, error) {\n\tn, err := New(int64(ulps), 0)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tdist, err := d.SubAbs(e)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tulp := d.ULP().Min(e.ULP())\n\ttlr, err := ulp.Mul(n)\n\tif err != nil {\n\t\treturn 0, err\n\t}\n\tif dist.Cmp(tlr) <= 0 {\n\t\treturn 0, nil\n\t}\n\treturn d.Cmp(e), nil\n}\n\nfunc FuzzDecimal_Sub_Cmp(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor _, e := range corpus {\n\t\t\tf.Add(d.neg, d.scale, d.coef, e.neg, e.scale, e.coef)\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64, eneg bool, escale int, ecoef uint64) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\te, err := newSafe(eneg, fint(ecoef), escale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tf, err := d.Sub(e)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tgot := f.Sign()\n\n\t\t\twant := d.Cmp(e)\n\n\t\t\tif want != got {\n\t\t\t\tt.Errorf(\"%q.Cmp(%q) = %v, whereas %q.Sub(%q).Sign() = %v\", d, e, want, d, e, got)\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_New(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tf.Add(d.neg, d.scale, d.coef)\n\t}\n\n\ttoBint := func(coef uint64) *bint {\n\t\tb := new(big.Int)\n\t\tb.SetUint64(coef)\n\t\treturn (*bint)(b)\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, neg bool, scale int, coef uint64) {\n\t\t\tgot, err := newFromFint(neg, fint(coef), scale, 0)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\twant, err := newFromBint(neg, toBint(coef), scale, 0)\n\t\t\tif err != nil {\n\t\t\t\tt.Errorf(\"newDecimalFromBint(%v, %v, %v, 0) failed: %v\", neg, coef, scale, err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tif got.CmpTotal(want) != 0 {\n\t\t\t\tt.Errorf(\"newDecimalFromFint(%v, %v, %v, 0) = %q, whereas newDecimalFromBint(%v, %v, %v, 0) = %q\", neg, coef, scale, got, neg, coef, scale, want)\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Pad(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor s := range MaxScale + 1 {\n\t\t\tf.Add(d.neg, d.scale, d.coef, s)\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64, scale int) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot := d.Pad(scale)\n\n\t\t\twant := d\n\n\t\t\tif got.Cmp(want) != 0 {\n\t\t\t\tt.Errorf(\"%q.Pad(%v) = %q\", d, scale, got)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif got.Scale() > MaxScale {\n\t\t\t\tt.Errorf(\"%q.Pad(%v).Scale() = %v\", d, scale, got.Scale())\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n\nfunc FuzzDecimal_Trim(f *testing.F) {\n\tfor _, d := range corpus {\n\t\tfor s := range MaxScale + 1 {\n\t\t\tf.Add(d.neg, d.scale, d.coef, s)\n\t\t}\n\t}\n\n\tf.Fuzz(\n\t\tfunc(t *testing.T, dneg bool, dscale int, dcoef uint64, scale int) {\n\t\t\td, err := newSafe(dneg, fint(dcoef), dscale)\n\t\t\tif err != nil {\n\t\t\t\tt.Skip()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tgot := d.Trim(scale)\n\n\t\t\twant := d\n\n\t\t\tif got.Cmp(want) != 0 {\n\t\t\t\tt.Errorf(\"%q.Trim(%v) = %q\", d, scale, got)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif got.Scale() < MinScale {\n\t\t\t\tt.Errorf(\"%q.Trim(%v).Scale() = %v\", d, scale, got.Scale())\n\t\t\t\treturn\n\t\t\t}\n\t\t},\n\t)\n}\n"
  },
  {
    "path": "doc.go",
    "content": "/*\nPackage decimal implements decimal floating-point numbers with correct rounding.\nIt is specifically designed for transactional financial systems and adheres\nto the principles set by [ANSI X3.274-1996].\n\n# Internal Representation\n\nDecimal is a struct with three fields:\n\n  - Sign:\n    A boolean indicating whether the decimal is negative.\n  - Coefficient:\n    An unsigned integer representing the numeric value of the decimal without\n    the decimal point.\n  - Scale:\n    A non-negative integer indicating the position of the decimal point\n    within the coefficient.\n    For example, a decimal with a coefficient of 12345 and a scale of 2 represents\n    the value 123.45.\n    Conceptually, the scale can be understood as the inverse of the exponent in\n    scientific notation.\n    For example, a scale of 2 corresponds to an exponent of -2.\n    The range of allowed values for the scale is from 0 to 19.\n\nThe numerical value of a decimal is calculated as follows:\n\n  - -Coefficient / 10^Scale if Sign is true.\n  - Coefficient / 10^Scale if Sign is false.\n\nThis approach allows the same numeric value to have multiple representations,\nfor example, 1, 1.0, and 1.00, which represent the same value but have different\nscales and coefficients.\n\n# Constraints Overview\n\nThe range of a decimal is determined by its scale.\nHere are the ranges for frequently used scales:\n\n\t| Example      | Scale | Minimum                              | Maximum                             |\n\t| ------------ | ----- | ------------------------------------ | ----------------------------------- |\n\t| Japanese Yen | 0     | -9,999,999,999,999,999,999           | 9,999,999,999,999,999,999           |\n\t| US Dollar    | 2     |    -99,999,999,999,999,999.99        |    99,999,999,999,999,999.99        |\n\t| Omani Rial   | 3     |     -9,999,999,999,999,999.999       |     9,999,999,999,999,999.999       |\n\t| Bitcoin      | 8     |            -99,999,999,999.99999999  |            99,999,999,999.99999999  |\n\t| Ethereum     | 9     |             -9,999,999,999.999999999 |             9,999,999,999.999999999 |\n\n[Subnormal numbers] are not supported to ensure peak performance.\nConsequently, decimals between -0.00000000000000000005 and 0.00000000000000000005\ninclusive, are rounded to 0.\n\nSpecial values such as [NaN], [Infinity], or [negative zeros] are not supported.\nThis ensures that arithmetic operations always produce either valid decimals\nor errors.\n\n# Arithmetic Operations\n\nEach arithmetic operation occurs in two steps:\n\n 1. The operation is initially performed using uint64 arithmetic.\n    If no overflow occurs, the exact result is immediately returned.\n    If overflow occurs, the operation proceeds to step 2.\n\n 2. The operation is repeated with at least double precision using [big.Int] arithmetic.\n    The result is then rounded to 19 digits.\n    If no significant digits are lost during rounding, the inexact result is returned.\n    If any significant digit is lost, an overflow error is returned.\n\nStep 1 improves performance by avoiding the performance impact associated with [big.Int] arithmetic.\nIt is expected that, in transactional financial systems, most arithmetic operations\nwill compute an exact result during step 1.\n\nThe following rules determine the significance of digits during step 2:\n\n  - For [Decimal.Add], [Decimal.Sub], [Decimal.Mul], [Decimal.Quo], [Decimal.QuoRem], [Decimal.Inv],\n    [Decimal.AddMul], [Decimal.AddQuo], [Decimal.SubMul], [Decimal.SubQuo], [Decimal.SubAbs],\n    [Decimal.PowInt], [Sum], [Mean], [Prod]:\n    All digits in the integer part are significant, while digits in the\n    fractional part are considered insignificant.\n  - For [Decimal.AddExact], [Decimal.SubExact], [Decimal.MulExact], [Decimal.QuoExact],\n    [Decimal.AddMulExact], [Decimal.AddQuoExact], [Decimal.SubMulExact], [Decimal.SubQuoExact]:\n    All digits in the integer part are significant. The significance of digits\n    in the fractional part is determined by the scale argument, which is typically\n    equal to the scale of the currency.\n\n# Transcendental Functions\n\nAll transcendental functions are always computed with at least double precision using [big.Int] arithmetic.\nThe result is then rounded to 19 digits.\nIf no significant digits are lost during rounding, the inexact result is returned.\nIf any significant digit is lost, an overflow error is returned.\n\nThe following rules determine the significance of digits:\n\n  - For [Decimal.Sqrt], [Decimal.Pow], [Decimal.Exp], [Decimal.Log],\n    [Decimal.Log2], [Decimal.Log10], [Decimal.Expm1], [Decimal.Log1p]:\n    All digits in the integer part are significant, while digits in the\n    fractional part are considered insignificant.\n\n# Rounding Methods\n\nFor all operations, the result is the one that would be obtained by computing\nthe exact result with infinite precision and then rounding it to 19 digits\nusing half-to-even rounding.\nThis method ensures that the result is as close as possible to the true\nmathematical value and that rounding errors are evenly distributed between\nrounding up and down.\n\nIn addition to implicit rounding, the package provides several methods for\nexplicit rounding:\n\n  - Half-to-even rounding:\n    [Decimal.Round], [Decimal.Quantize], [Decimal.Rescale].\n  - Rounding towards positive infinity:\n    [Decimal.Ceil].\n  - Rounding towards negative infinity:\n    [Decimal.Floor].\n  - Rounding towards zero:\n    [Decimal.Trunc].\n\nSee the documentation for each method for more details.\n\n# Error Handling\n\nAll methods are panic-free and pure.\nErrors are returned in the following cases:\n\n  - Division by Zero:\n    Unlike Go's standard library, [Decimal.Quo], [Decimal.QuoRem], [Decimal.Inv],\n    [Decimal.AddQuo], [Decimal.SubQuo], do not panic when dividing by 0.\n    Instead, they return an error.\n\n  - Invalid Operation:\n    [Sum], [Mean] and [Prod] return an error if no arguments are provided.\n    [Decimal.PowInt] returns an error if 0 is raised to a negative power.\n    [Decimal.Sqrt] returns an error if the square root of a negative decimal is requested.\n    [Decimal.Log], [Decimal.Log2], [Decimal.Log10] return an error when calculating a logarithm of a non-positive decimal.\n    [Decimal.Log1p] returns an error when calculating a logarithm of a decimal equal to or less than negative one.\n    [Decimal.Pow] returns an error if 0 is raised to a negative powere or a negative decimal is raised to a fractional power.\n\n  - Overflow:\n    Unlike standard integers, decimals do not \"wrap around\" when exceeding their maximum value.\n    For out-of-range values, methods return an error.\n\nErrors are not returned in the following cases:\n\n  - Underflow:\n    Methods do not return an error for decimal underflow.\n    If the result is a decimal between -0.00000000000000000005 and\n    0.00000000000000000005 inclusive, it will be rounded to 0.\n\n# Data Conversion\n\nA. JSON\n\nThe package integrates with standard [encoding/json] through\nthe implementation of [json.Marshaler] and [json.Unmarshaler] interfaces.\nBelow is an example structure:\n\n\ttype Object struct {\n\t  Number decimal.Decimal `json:\"some_number\"`\n\t  // Other fields...\n\t}\n\nThis package marshals decimals as quoted strings, ensuring the preservation of\nthe exact numerical value.\nBelow is an example OpenAPI schema:\n\n\tDecimal:\n\t  type: string\n\t  format: decimal\n\t  pattern: '^(\\-|\\+)?((\\d+(\\.\\d*)?)|(\\.\\d+))$'\n\nB. BSON\n\nThe package integrates with [mongo-driver/bson] via the implementation of\n[v2/bson.ValueMarshaler] and [v2/bson.ValueUnmarshaler] interfaces.\nBelow is an example structure:\n\n\ttype Record struct {\n\t  Number decimal.Decimal `bson:\"some_number\"`\n\t  // Other fields...\n\t}\n\nThis package marshals decimals as [Decimal128], ensuring the preservation of\nthe exact numerical value.\n\nC. XML\n\nThe package integrates with standard [encoding/xml] via the implementation of\n[encoding.TextMarshaller] and [encoding.TextUnmarshaler] interfaces.\nBelow is an example structure:\n\n\ttype Entity struct {\n\t  Number decimal.Decimal `xml:\"SomeNumber\"`\n\t  // Other fields...\n\t}\n\n\"xs:decimal\" type can represent decimals in XML schema.\nIt is possible to impose restrictions on the length of the decimals\nusing the following type:\n\n\t<xs:simpleType name=\"Decimal\">\n\t  <xs:restriction base=\"xs:decimal\">\n\t    <xs:totalDigits value=\"19\"/>\n\t  </xs:restriction>\n\t</xs:simpleType>\n\nD. Protocol Buffers\n\nProtocol Buffers provide two formats to represent decimals.\nThe first format represents decimals as [numerical strings].\nThe main advantage of this format is that it preserves trailing zeros.\nTo convert between this format and decimals, use [Parse] and [Decimal.String].\nBelow is an example of a proto definition:\n\n\tmessage Decimal {\n\t  string value = 1;\n\t}\n\nThe second format represents decimals as [a pair of integers]:\none for the integer part and another for the fractional part.\nThis format does not preserve trailing zeros and rounds decimals\nwith more than nine digits in the fractional part.\nFor conversion between this format and decimals, use [NewFromInt64] and\n[Decimal.Int64] with a scale argument of \"9\".\nBelow is an example of a proto definition:\n\n\tmessage Decimal {\n\t  int64 units = 1;\n\t  int32 nanos = 2;\n\t}\n\nE. SQL\n\nThe package integrates with the standard [database/sql] via the implementation\nof [sql.Scanner] and [driver.Valuer] interfaces.\nTo ensure accurate preservation of decimal scales, it is essential to choose\nappropriate column types:\n\n\t| Database   | Type                          |\n\t| ---------- | ----------------------------- |\n\t| PostgreSQL | DECIMAL                       |\n\t| SQLite     | TEXT                          |\n\t| MySQL      | DECIMAL(19, d) or VARCHAR(22) |\n\nBelow are the reasons for these preferences:\n\n  - PostgreSQL:\n    Always use DECIMAL without precision or scale specifications, that is,\n    avoid DECIMAL(p) or DECIMAL(p, s).\n    DECIMAL accurately preserves the scale of decimals.\n\n  - SQLite:\n    Prefer TEXT, since DECIMAL is just an alias for binary floating-point numbers.\n    TEXT accurately preserves the scale of decimals.\n\n  - MySQL:\n    Use DECIMAL(19, d), as DECIMAL is merely an alias for DECIMAL(10, 0).\n    The downside of this format is that MySQL automatically rescales all decimals:\n    it rounds values with more than d digits in the fractional part (using half\n    away from zero) and pads with trailing zeros those with fewer than d digits\n    in the fractional part.\n    To prevent automatic rescaling, consider using VARCHAR(22), which accurately\n    preserves the scale of decimals.\n\n# Mathematical Context\n\nUnlike many other decimal libraries, this package does not provide\nan explicit mathematical [context].\nInstead, the [context] is implicit and can be approximately equated to\nthe following settings:\n\n\t| Attribute               | Value                                           |\n\t| ----------------------- | ----------------------------------------------- |\n\t| Precision               | 19                                              |\n\t| Maximum Exponent (Emax) | 18                                              |\n\t| Minimum Exponent (Emin) | -19                                             |\n\t| Tiny Exponent (Etiny)   | -19                                             |\n\t| Rounding Method         | Half To Even                                    |\n\t| Enabled Traps           | Division by Zero, Invalid Operation, Overflow   |\n\t| Disabled Traps          | Inexact, Clamped, Rounded, Subnormal, Underflow |\n\nThe equality of Etiny and Emin implies that this package does not support\nsubnormal numbers.\n\n[Infinity]: https://en.wikipedia.org/wiki/Infinity#Computing\n[Subnormal numbers]: https://en.wikipedia.org/wiki/Subnormal_number\n[NaN]: https://en.wikipedia.org/wiki/NaN\n[ANSI X3.274-1996]: https://speleotrove.com/decimal/dax3274.html\n[big.Int]: https://pkg.go.dev/math/big#Int\n[sql.Scanner]: https://pkg.go.dev/database/sql#Scanner\n[negative zeros]: https://en.wikipedia.org/wiki/Signed_zero\n[context]: https://speleotrove.com/decimal/damodel.html\n[numerical strings]: https://github.com/googleapis/googleapis/blob/master/google/type/decimal.proto\n[a pair of integers]: https://github.com/googleapis/googleapis/blob/master/google/type/money.proto\n[json.Marshaler]: https://pkg.go.dev/encoding/json#Marshaler\n[json.Unmarshaler]: https://pkg.go.dev/encoding/json#Unmarshaler\n[mongo-driver/bson]: https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson\n[Decimal128]: https://github.com/mongodb/specifications/blob/master/source/bson-decimal128/decimal128.md\n[v2/bson.ValueMarshaler]: https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#ValueMarshaler\n[v2/bson.ValueUnmarshaler]: https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#ValueUnmarshaler\n*/\npackage decimal\n"
  },
  {
    "path": "doc_test.go",
    "content": "package decimal_test\n\nimport (\n\t\"bytes\"\n\t\"encoding/gob\"\n\t\"encoding/json\"\n\t\"encoding/xml\"\n\t\"fmt\"\n\t\"slices\"\n\t\"strings\"\n\n\t\"github.com/govalues/decimal\"\n)\n\n// This example implements a simple calculator that evaluates mathematical\n// expressions written in [postfix notation].\n// The calculator can handle basic arithmetic operations such as addition,\n// subtraction, multiplication, and division.\n//\n// [postfix notation]: https://en.wikipedia.org/wiki/Reverse_Polish_notation\nfunc Example_postfixCalculator() {\n\tfmt.Println(evaluate(\"1.23 4.56 + 10 *\"))\n\t// Output:\n\t// 57.90 <nil>\n}\n\nfunc evaluate(input string) (decimal.Decimal, error) {\n\ttokens := strings.Fields(input)\n\tif len(tokens) == 0 {\n\t\treturn decimal.Decimal{}, fmt.Errorf(\"no tokens\")\n\t}\n\tstack := make([]decimal.Decimal, 0, len(tokens))\n\tfor i, token := range tokens {\n\t\tvar err error\n\t\tvar result decimal.Decimal\n\t\tif token == \"+\" || token == \"-\" || token == \"*\" || token == \"/\" {\n\t\t\tif len(stack) < 2 {\n\t\t\t\treturn decimal.Decimal{}, fmt.Errorf(\"not enough operands\")\n\t\t\t}\n\t\t\tleft := stack[len(stack)-2]\n\t\t\tright := stack[len(stack)-1]\n\t\t\tstack = stack[:len(stack)-2]\n\t\t\tswitch token {\n\t\t\tcase \"+\":\n\t\t\t\tresult, err = left.Add(right)\n\t\t\tcase \"-\":\n\t\t\t\tresult, err = left.Sub(right)\n\t\t\tcase \"*\":\n\t\t\t\tresult, err = left.Mul(right)\n\t\t\tcase \"/\":\n\t\t\t\tresult, err = left.Quo(right)\n\t\t\t}\n\t\t} else {\n\t\t\tresult, err = decimal.Parse(token)\n\t\t}\n\t\tif err != nil {\n\t\t\treturn decimal.Decimal{}, fmt.Errorf(\"processing token %q at position %v: %w\", token, i, err)\n\t\t}\n\t\tstack = append(stack, result)\n\t}\n\tif len(stack) != 1 {\n\t\treturn decimal.Decimal{}, fmt.Errorf(\"stack contains %v, expected exactly one item\", stack)\n\t}\n\treturn stack[0], nil\n}\n\n// This example calculates an approximate value of π using the [Leibniz formula].\n// The Leibniz formula is an infinite series that converges to π/4, and is\n// given by the equation: 1 - 1/3 + 1/5 - 1/7 + 1/9 - 1/11 + ... = π/4.\n// This example computes the series up to the 500,000th term using decimal arithmetic\n// and returns the approximate value of π.\n//\n// [Leibniz formula]: https://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80\nfunc Example_piApproximation() {\n\tfmt.Println(approximate(500_000))\n\tfmt.Println(decimal.Pi)\n\t// Output:\n\t// 3.141590653589793192 <nil>\n\t// 3.141592653589793238\n}\n\nfunc approximate(terms int) (decimal.Decimal, error) {\n\tpi := decimal.Zero\n\tdenominator := decimal.One\n\tincrement := decimal.Two\n\tmultiplier := decimal.MustParse(\"4\")\n\n\tvar err error\n\tfor range terms {\n\t\tpi, err = pi.AddQuo(multiplier, denominator)\n\t\tif err != nil {\n\t\t\treturn decimal.Decimal{}, err\n\t\t}\n\t\tdenominator, err = denominator.Add(increment)\n\t\tif err != nil {\n\t\t\treturn decimal.Decimal{}, err\n\t\t}\n\t\tmultiplier = multiplier.Neg()\n\t}\n\treturn pi, nil\n}\n\n// This example demonstrates the advantage of decimals for financial calculations.\n// It computes the sum 0.1 + 0.2 using both decimal and float64 arithmetic.\n// In decimal arithmetic, the result is exactly 0.3, as expected.\n// In float64 arithmetic, the result is 0.30000000000000004 due to floating-point inaccuracy.\nfunc Example_floatInaccuracy() {\n\ta := decimal.MustParse(\"0.1\")\n\tb := decimal.MustParse(\"0.2\")\n\tfmt.Println(a.Add(b))\n\n\tx := 0.1\n\ty := 0.2\n\tfmt.Println(x + y)\n\t// Output:\n\t// 0.3 <nil>\n\t// 0.30000000000000004\n}\n\nfunc ExampleSum() {\n\td := decimal.MustParse(\"5.67\")\n\te := decimal.MustParse(\"-8\")\n\tf := decimal.MustParse(\"23\")\n\tfmt.Println(decimal.Sum(d, e, f))\n\t// Output: 20.67 <nil>\n}\n\nfunc ExampleMean() {\n\td := decimal.MustParse(\"5.67\")\n\te := decimal.MustParse(\"-8\")\n\tf := decimal.MustParse(\"23\")\n\tfmt.Println(decimal.Mean(d, e, f))\n\t// Output: 6.89 <nil>\n}\n\nfunc ExampleProd() {\n\td := decimal.MustParse(\"5.67\")\n\te := decimal.MustParse(\"-8\")\n\tf := decimal.MustParse(\"23\")\n\tfmt.Println(decimal.Prod(d, e, f))\n\t// Output: -1043.28 <nil>\n}\n\nfunc ExampleMustNew() {\n\tfmt.Println(decimal.MustNew(567, 0))\n\tfmt.Println(decimal.MustNew(567, 1))\n\tfmt.Println(decimal.MustNew(567, 2))\n\tfmt.Println(decimal.MustNew(567, 3))\n\tfmt.Println(decimal.MustNew(567, 4))\n\t// Output:\n\t// 567\n\t// 56.7\n\t// 5.67\n\t// 0.567\n\t// 0.0567\n}\n\nfunc ExampleNew() {\n\tfmt.Println(decimal.New(567, 0))\n\tfmt.Println(decimal.New(567, 1))\n\tfmt.Println(decimal.New(567, 2))\n\tfmt.Println(decimal.New(567, 3))\n\tfmt.Println(decimal.New(567, 4))\n\t// Output:\n\t// 567 <nil>\n\t// 56.7 <nil>\n\t// 5.67 <nil>\n\t// 0.567 <nil>\n\t// 0.0567 <nil>\n}\n\nfunc ExampleNewFromInt64() {\n\tfmt.Println(decimal.NewFromInt64(5, 6, 1))\n\tfmt.Println(decimal.NewFromInt64(5, 6, 2))\n\tfmt.Println(decimal.NewFromInt64(5, 6, 3))\n\tfmt.Println(decimal.NewFromInt64(5, 6, 4))\n\tfmt.Println(decimal.NewFromInt64(5, 6, 5))\n\t// Output:\n\t// 5.6 <nil>\n\t// 5.06 <nil>\n\t// 5.006 <nil>\n\t// 5.0006 <nil>\n\t// 5.00006 <nil>\n}\n\nfunc ExampleNewFromFloat64() {\n\tfmt.Println(decimal.NewFromFloat64(5.67e-2))\n\tfmt.Println(decimal.NewFromFloat64(5.67e-1))\n\tfmt.Println(decimal.NewFromFloat64(5.67e0))\n\tfmt.Println(decimal.NewFromFloat64(5.67e1))\n\tfmt.Println(decimal.NewFromFloat64(5.67e2))\n\t// Output:\n\t// 0.0567 <nil>\n\t// 0.567 <nil>\n\t// 5.67 <nil>\n\t// 56.7 <nil>\n\t// 567 <nil>\n}\n\nfunc ExampleDecimal_Zero() {\n\td := decimal.MustParse(\"5\")\n\te := decimal.MustParse(\"5.6\")\n\tf := decimal.MustParse(\"5.67\")\n\tfmt.Println(d.Zero())\n\tfmt.Println(e.Zero())\n\tfmt.Println(f.Zero())\n\t// Output:\n\t// 0\n\t// 0.0\n\t// 0.00\n}\n\nfunc ExampleDecimal_One() {\n\td := decimal.MustParse(\"5\")\n\te := decimal.MustParse(\"5.6\")\n\tf := decimal.MustParse(\"5.67\")\n\tfmt.Println(d.One())\n\tfmt.Println(e.One())\n\tfmt.Println(f.One())\n\t// Output:\n\t// 1\n\t// 1.0\n\t// 1.00\n}\n\nfunc ExampleDecimal_ULP() {\n\td := decimal.MustParse(\"5\")\n\te := decimal.MustParse(\"5.6\")\n\tf := decimal.MustParse(\"5.67\")\n\tfmt.Println(d.ULP())\n\tfmt.Println(e.ULP())\n\tfmt.Println(f.ULP())\n\t// Output:\n\t// 1\n\t// 0.1\n\t// 0.01\n}\n\nfunc ExampleParse() {\n\tfmt.Println(decimal.Parse(\"5.67\"))\n\t// Output: 5.67 <nil>\n}\n\nfunc ExampleParseExact() {\n\tfmt.Println(decimal.ParseExact(\"5.67\", 0))\n\tfmt.Println(decimal.ParseExact(\"5.67\", 1))\n\tfmt.Println(decimal.ParseExact(\"5.67\", 2))\n\tfmt.Println(decimal.ParseExact(\"5.67\", 3))\n\tfmt.Println(decimal.ParseExact(\"5.67\", 4))\n\t// Output:\n\t// 5.67 <nil>\n\t// 5.67 <nil>\n\t// 5.67 <nil>\n\t// 5.670 <nil>\n\t// 5.6700 <nil>\n}\n\nfunc ExampleMustParse() {\n\tfmt.Println(decimal.MustParse(\"-1.23\"))\n\t// Output: -1.23\n}\n\nfunc ExampleDecimal_String() {\n\td := decimal.MustParse(\"1234567890.123456789\")\n\tfmt.Println(d.String())\n\t// Output: 1234567890.123456789\n}\n\nfunc ExampleDecimal_UnmarshalBinary_gob() {\n\tdata := []byte{\n\t\t0x12, 0x7f, 0x06, 0x01,\n\t\t0x01, 0x07, 0x44, 0x65,\n\t\t0x63, 0x69, 0x6d, 0x61,\n\t\t0x6c, 0x01, 0xff, 0x80,\n\t\t0x00, 0x00, 0x00, 0x08,\n\t\t0xff, 0x80, 0x00, 0x04,\n\t\t0x35, 0x2e, 0x36, 0x37,\n\t}\n\tfmt.Println(unmarshalGOB(data))\n\t// Output:\n\t// 5.67 <nil>\n}\n\nfunc unmarshalGOB(data []byte) (decimal.Decimal, error) {\n\tvar d decimal.Decimal\n\tdec := gob.NewDecoder(bytes.NewReader(data))\n\terr := dec.Decode(&d)\n\tif err != nil {\n\t\treturn decimal.Decimal{}, err\n\t}\n\treturn d, nil\n}\n\nfunc ExampleDecimal_AppendBinary() {\n\td := decimal.MustParse(\"5.67\")\n\tvar data []byte\n\tdata = append(data, 0x04)\n\tdata, err := d.AppendBinary(data)\n\tdata = append(data, 0x00)\n\tfmt.Printf(\"% x %v\\n\", data, err)\n\t// Output:\n\t// 04 35 2e 36 37 00 <nil>\n}\n\nfunc ExampleDecimal_MarshalBinary_gob() {\n\tdata, err := marshalGOB(\"5.67\")\n\tfmt.Printf(\"[% x] %v\\n\", data, err)\n\t// Output:\n\t// [12 7f 06 01 01 07 44 65 63 69 6d 61 6c 01 ff 80 00 00 00 08 ff 80 00 04 35 2e 36 37] <nil>\n}\n\nfunc marshalGOB(s string) ([]byte, error) {\n\td, err := decimal.Parse(s)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tvar data bytes.Buffer\n\tenc := gob.NewEncoder(&data)\n\terr = enc.Encode(d)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\treturn data.Bytes(), nil\n}\n\nfunc ExampleDecimal_Float64() {\n\td := decimal.MustParse(\"0.1\")\n\te := decimal.MustParse(\"123.456\")\n\tf := decimal.MustParse(\"1234567890.123456789\")\n\tfmt.Println(d.Float64())\n\tfmt.Println(e.Float64())\n\tfmt.Println(f.Float64())\n\t// Output:\n\t// 0.1 true\n\t// 123.456 true\n\t// 1.2345678901234567e+09 true\n}\n\nfunc ExampleDecimal_Int64() {\n\td := decimal.MustParse(\"5.67\")\n\tfmt.Println(d.Int64(0))\n\tfmt.Println(d.Int64(1))\n\tfmt.Println(d.Int64(2))\n\tfmt.Println(d.Int64(3))\n\tfmt.Println(d.Int64(4))\n\t// Output:\n\t// 6 0 true\n\t// 5 7 true\n\t// 5 67 true\n\t// 5 670 true\n\t// 5 6700 true\n}\n\nfunc ExampleDecimal_UnmarshalBSONValue_bson() {\n\tdata := []byte{\n\t\t0x37, 0x02, 0x00, 0x00,\n\t\t0x00, 0x00, 0x00, 0x00,\n\t\t0x00, 0x00, 0x00, 0x00,\n\t\t0x00, 0x00, 0x3c, 0x30,\n\t}\n\n\tvar d decimal.Decimal\n\terr := d.UnmarshalBSONValue(19, data)\n\tfmt.Println(d, err)\n\t// Output:\n\t// 5.67 <nil>\n}\n\nfunc ExampleDecimal_MarshalBSONValue_bson() {\n\td := decimal.MustParse(\"5.67\")\n\tt, data, err := d.MarshalBSONValue()\n\tfmt.Printf(\"%v [% x] %v\\n\", t, data, err)\n\t// Output:\n\t// 19 [37 02 00 00 00 00 00 00 00 00 00 00 00 00 3c 30] <nil>\n}\n\ntype Account struct {\n\tBalance decimal.Decimal `json:\"balance\"`\n}\n\nfunc ExampleDecimal_UnmarshalJSON_json() {\n\tfmt.Println(unmarshalJSON(`{\"balance\":\"5.67\"}`))\n\tfmt.Println(unmarshalJSON(`{\"balance\":\"-5.67\"}`))\n\tfmt.Println(unmarshalJSON(`{\"balance\":5.67e-5}`))\n\tfmt.Println(unmarshalJSON(`{\"balance\":5.67e5}`))\n\t// Output:\n\t// {5.67} <nil>\n\t// {-5.67} <nil>\n\t// {0.0000567} <nil>\n\t// {567000} <nil>\n}\n\nfunc unmarshalJSON(s string) (Account, error) {\n\tvar a Account\n\terr := json.Unmarshal([]byte(s), &a)\n\tif err != nil {\n\t\treturn Account{}, err\n\t}\n\treturn a, nil\n}\n\nfunc ExampleDecimal_MarshalJSON_json() {\n\tfmt.Println(marshalJSON(\"5.67\"))\n\tfmt.Println(marshalJSON(\"-5.67\"))\n\t// Output:\n\t// {\"balance\":\"5.67\"} <nil>\n\t// {\"balance\":\"-5.67\"} <nil>\n}\n\nfunc marshalJSON(s string) (string, error) {\n\td, err := decimal.Parse(s)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tdata, err := json.Marshal(Account{Balance: d})\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treturn string(data), nil\n}\n\ntype Transaction struct {\n\tAmount decimal.Decimal `xml:\"Amount\"`\n}\n\nfunc ExampleDecimal_UnmarshalText_xml() {\n\tfmt.Println(unmarshalXML(`<Transaction><Amount>5.67</Amount></Transaction>`))\n\tfmt.Println(unmarshalXML(`<Transaction><Amount>-5.67</Amount></Transaction>`))\n\tfmt.Println(unmarshalXML(`<Transaction><Amount>5.67e-5</Amount></Transaction>`))\n\tfmt.Println(unmarshalXML(`<Transaction><Amount>5.67e5</Amount></Transaction>`))\n\t// Output:\n\t// {5.67} <nil>\n\t// {-5.67} <nil>\n\t// {0.0000567} <nil>\n\t// {567000} <nil>\n}\n\nfunc unmarshalXML(s string) (Transaction, error) {\n\tvar t Transaction\n\terr := xml.Unmarshal([]byte(s), &t)\n\treturn t, err\n}\n\nfunc ExampleDecimal_AppendText() {\n\tvar text []byte\n\td := decimal.MustParse(\"5.67\")\n\ttext = append(text, \"<Decimal>\"...)\n\ttext, err := d.AppendText(text)\n\ttext = append(text, \"</Decimal>\"...)\n\tfmt.Printf(\"%s %v\\n\", text, err)\n\t// Output:\n\t// <Decimal>5.67</Decimal> <nil>\n}\n\nfunc ExampleDecimal_MarshalText_xml() {\n\tfmt.Println(marshalXML(\"5.67\"))\n\tfmt.Println(marshalXML(\"-5.67\"))\n\tfmt.Println(marshalXML(\"5.67e-5\"))\n\tfmt.Println(marshalXML(\"5.67e5\"))\n\t// Output:\n\t// <Transaction><Amount>5.67</Amount></Transaction> <nil>\n\t// <Transaction><Amount>-5.67</Amount></Transaction> <nil>\n\t// <Transaction><Amount>0.0000567</Amount></Transaction> <nil>\n\t// <Transaction><Amount>567000</Amount></Transaction> <nil>\n}\n\nfunc marshalXML(s string) (string, error) {\n\td, err := decimal.Parse(s)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tdata, err := xml.Marshal(Transaction{Amount: d})\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\treturn string(data), nil\n}\n\nfunc ExampleDecimal_Scan() {\n\tvar d decimal.Decimal\n\t_ = d.Scan(\"5.67\")\n\tfmt.Println(d)\n\t// Output: 5.67\n}\n\nfunc ExampleDecimal_Value() {\n\td := decimal.MustParse(\"5.67\")\n\tfmt.Println(d.Value())\n\t// Output: 5.67 <nil>\n}\n\nfunc ExampleDecimal_Format() {\n\td := decimal.MustParse(\"5.67\")\n\tfmt.Printf(\"%f\\n\", d)\n\tfmt.Printf(\"%k\\n\", d)\n\t// Output:\n\t// 5.67\n\t// 567%\n}\n\nfunc ExampleDecimal_Coef() {\n\td := decimal.MustParse(\"-123\")\n\te := decimal.MustParse(\"5.7\")\n\tf := decimal.MustParse(\"0.4\")\n\tfmt.Println(d.Coef())\n\tfmt.Println(e.Coef())\n\tfmt.Println(f.Coef())\n\t// Output:\n\t// 123\n\t// 57\n\t// 4\n}\n\nfunc ExampleDecimal_Prec() {\n\td := decimal.MustParse(\"-123\")\n\te := decimal.MustParse(\"5.7\")\n\tf := decimal.MustParse(\"0.4\")\n\tfmt.Println(d.Prec())\n\tfmt.Println(e.Prec())\n\tfmt.Println(f.Prec())\n\t// Output:\n\t// 3\n\t// 2\n\t// 1\n}\n\nfunc ExampleDecimal_Mul() {\n\td := decimal.MustParse(\"5.7\")\n\te := decimal.MustParse(\"3\")\n\tfmt.Println(d.Mul(e))\n\t// Output: 17.1 <nil>\n}\n\nfunc ExampleDecimal_MulExact() {\n\td := decimal.MustParse(\"5.7\")\n\te := decimal.MustParse(\"3\")\n\tfmt.Println(d.MulExact(e, 0))\n\tfmt.Println(d.MulExact(e, 1))\n\tfmt.Println(d.MulExact(e, 2))\n\tfmt.Println(d.MulExact(e, 3))\n\tfmt.Println(d.MulExact(e, 4))\n\t// Output:\n\t// 17.1 <nil>\n\t// 17.1 <nil>\n\t// 17.10 <nil>\n\t// 17.100 <nil>\n\t// 17.1000 <nil>\n}\n\nfunc ExampleDecimal_SubMul() {\n\td := decimal.MustParse(\"2\")\n\te := decimal.MustParse(\"3\")\n\tf := decimal.MustParse(\"4\")\n\tfmt.Println(d.SubMul(e, f))\n\t// Output: -10 <nil>\n}\n\nfunc ExampleDecimal_SubMulExact() {\n\td := decimal.MustParse(\"2\")\n\te := decimal.MustParse(\"3\")\n\tf := decimal.MustParse(\"4\")\n\tfmt.Println(d.SubMulExact(e, f, 0))\n\tfmt.Println(d.SubMulExact(e, f, 1))\n\tfmt.Println(d.SubMulExact(e, f, 2))\n\tfmt.Println(d.SubMulExact(e, f, 3))\n\tfmt.Println(d.SubMulExact(e, f, 4))\n\t// Output:\n\t// -10 <nil>\n\t// -10.0 <nil>\n\t// -10.00 <nil>\n\t// -10.000 <nil>\n\t// -10.0000 <nil>\n}\n\nfunc ExampleDecimal_AddMul() {\n\td := decimal.MustParse(\"2\")\n\te := decimal.MustParse(\"3\")\n\tf := decimal.MustParse(\"4\")\n\tfmt.Println(d.AddMul(e, f))\n\t// Output: 14 <nil>\n}\n\nfunc ExampleDecimal_AddMulExact() {\n\td := decimal.MustParse(\"2\")\n\te := decimal.MustParse(\"3\")\n\tf := decimal.MustParse(\"4\")\n\tfmt.Println(d.AddMulExact(e, f, 0))\n\tfmt.Println(d.AddMulExact(e, f, 1))\n\tfmt.Println(d.AddMulExact(e, f, 2))\n\tfmt.Println(d.AddMulExact(e, f, 3))\n\tfmt.Println(d.AddMulExact(e, f, 4))\n\t// Output:\n\t// 14 <nil>\n\t// 14.0 <nil>\n\t// 14.00 <nil>\n\t// 14.000 <nil>\n\t// 14.0000 <nil>\n}\n\nfunc ExampleDecimal_SubQuo() {\n\td := decimal.MustParse(\"2\")\n\te := decimal.MustParse(\"3\")\n\tf := decimal.MustParse(\"4\")\n\tfmt.Println(d.SubQuo(e, f))\n\t// Output: 1.25 <nil>\n}\n\nfunc ExampleDecimal_SubQuoExact() {\n\td := decimal.MustParse(\"2\")\n\te := decimal.MustParse(\"3\")\n\tf := decimal.MustParse(\"4\")\n\tfmt.Println(d.SubQuoExact(e, f, 0))\n\tfmt.Println(d.SubQuoExact(e, f, 1))\n\tfmt.Println(d.SubQuoExact(e, f, 2))\n\tfmt.Println(d.SubQuoExact(e, f, 3))\n\tfmt.Println(d.SubQuoExact(e, f, 4))\n\t// Output:\n\t// 1.25 <nil>\n\t// 1.25 <nil>\n\t// 1.25 <nil>\n\t// 1.250 <nil>\n\t// 1.2500 <nil>\n}\n\nfunc ExampleDecimal_AddQuo() {\n\td := decimal.MustParse(\"2\")\n\te := decimal.MustParse(\"3\")\n\tf := decimal.MustParse(\"4\")\n\tfmt.Println(d.AddQuo(e, f))\n\t// Output: 2.75 <nil>\n}\n\nfunc ExampleDecimal_AddQuoExact() {\n\td := decimal.MustParse(\"2\")\n\te := decimal.MustParse(\"3\")\n\tf := decimal.MustParse(\"4\")\n\tfmt.Println(d.AddQuoExact(e, f, 0))\n\tfmt.Println(d.AddQuoExact(e, f, 1))\n\tfmt.Println(d.AddQuoExact(e, f, 2))\n\tfmt.Println(d.AddQuoExact(e, f, 3))\n\tfmt.Println(d.AddQuoExact(e, f, 4))\n\t// Output:\n\t// 2.75 <nil>\n\t// 2.75 <nil>\n\t// 2.75 <nil>\n\t// 2.750 <nil>\n\t// 2.7500 <nil>\n}\n\nfunc ExampleDecimal_Pow() {\n\td := decimal.MustParse(\"4\")\n\te := decimal.MustParse(\"0.5\")\n\tf := decimal.MustParse(\"-0.5\")\n\tfmt.Println(d.Pow(e))\n\tfmt.Println(d.Pow(f))\n\t// Output:\n\t// 2.000000000000000000 <nil>\n\t// 0.5000000000000000000 <nil>\n}\n\nfunc ExampleDecimal_PowInt() {\n\td := decimal.MustParse(\"2\")\n\tfmt.Println(d.PowInt(-2))\n\tfmt.Println(d.PowInt(-1))\n\tfmt.Println(d.PowInt(0))\n\tfmt.Println(d.PowInt(1))\n\tfmt.Println(d.PowInt(2))\n\t// Output:\n\t// 0.25 <nil>\n\t// 0.5 <nil>\n\t// 1 <nil>\n\t// 2 <nil>\n\t// 4 <nil>\n}\n\nfunc ExampleDecimal_Sqrt() {\n\td := decimal.MustParse(\"1\")\n\te := decimal.MustParse(\"2\")\n\tf := decimal.MustParse(\"3\")\n\tg := decimal.MustParse(\"4\")\n\tfmt.Println(d.Sqrt())\n\tfmt.Println(e.Sqrt())\n\tfmt.Println(f.Sqrt())\n\tfmt.Println(g.Sqrt())\n\t// Output:\n\t// 1 <nil>\n\t// 1.414213562373095049 <nil>\n\t// 1.732050807568877294 <nil>\n\t// 2 <nil>\n}\n\nfunc ExampleDecimal_Exp() {\n\td := decimal.MustParse(\"-2.302585092994045684\")\n\te := decimal.MustParse(\"0\")\n\tf := decimal.MustParse(\"2.302585092994045684\")\n\tfmt.Println(d.Exp())\n\tfmt.Println(e.Exp())\n\tfmt.Println(f.Exp())\n\t// Output:\n\t// 0.1000000000000000000 <nil>\n\t// 1 <nil>\n\t// 10.00000000000000000 <nil>\n}\n\nfunc ExampleDecimal_Expm1() {\n\td := decimal.MustParse(\"-2.302585092994045684\")\n\te := decimal.MustParse(\"0\")\n\tf := decimal.MustParse(\"2.302585092994045684\")\n\tfmt.Println(d.Expm1())\n\tfmt.Println(e.Expm1())\n\tfmt.Println(f.Expm1())\n\t// Output:\n\t// -0.9000000000000000000 <nil>\n\t// 0 <nil>\n\t// 9.000000000000000000 <nil>\n}\n\nfunc ExampleDecimal_Log() {\n\td := decimal.MustParse(\"1\")\n\te := decimal.MustParse(\"2\")\n\tf := decimal.MustParse(\"2.718281828459045236\")\n\tg := decimal.MustParse(\"10\")\n\tfmt.Println(d.Log())\n\tfmt.Println(e.Log())\n\tfmt.Println(f.Log())\n\tfmt.Println(g.Log())\n\t// Output:\n\t// 0 <nil>\n\t// 0.6931471805599453094 <nil>\n\t// 1.000000000000000000 <nil>\n\t// 2.302585092994045684 <nil>\n}\n\nfunc ExampleDecimal_Log1p() {\n\td := decimal.MustParse(\"1\")\n\te := decimal.MustParse(\"2\")\n\tf := decimal.MustParse(\"2.718281828459045236\")\n\tg := decimal.MustParse(\"10\")\n\tfmt.Println(d.Log1p())\n\tfmt.Println(e.Log1p())\n\tfmt.Println(f.Log1p())\n\tfmt.Println(g.Log1p())\n\t// Output:\n\t// 0.6931471805599453094 <nil>\n\t// 1.098612288668109691 <nil>\n\t// 1.313261687518222834 <nil>\n\t// 2.397895272798370544 <nil>\n}\n\nfunc ExampleDecimal_Log2() {\n\td := decimal.MustParse(\"1\")\n\te := decimal.MustParse(\"2\")\n\tf := decimal.MustParse(\"2.718281828459045236\")\n\tg := decimal.MustParse(\"10\")\n\tfmt.Println(d.Log2())\n\tfmt.Println(e.Log2())\n\tfmt.Println(f.Log2())\n\tfmt.Println(g.Log2())\n\t// Output:\n\t// 0 <nil>\n\t// 1 <nil>\n\t// 1.442695040888963408 <nil>\n\t// 3.321928094887362348 <nil>\n}\n\nfunc ExampleDecimal_Log10() {\n\td := decimal.MustParse(\"1\")\n\te := decimal.MustParse(\"2\")\n\tf := decimal.MustParse(\"2.718281828459045236\")\n\tg := decimal.MustParse(\"10\")\n\tfmt.Println(d.Log10())\n\tfmt.Println(e.Log10())\n\tfmt.Println(f.Log10())\n\tfmt.Println(g.Log10())\n\t// Output:\n\t// 0 <nil>\n\t// 0.3010299956639811952 <nil>\n\t// 0.4342944819032518278 <nil>\n\t// 1 <nil>\n}\n\nfunc ExampleDecimal_Add() {\n\td := decimal.MustParse(\"5.67\")\n\te := decimal.MustParse(\"8\")\n\tfmt.Println(d.Add(e))\n\t// Output: 13.67 <nil>\n}\n\nfunc ExampleDecimal_AddExact() {\n\td := decimal.MustParse(\"5.67\")\n\te := decimal.MustParse(\"8\")\n\tfmt.Println(d.AddExact(e, 0))\n\tfmt.Println(d.AddExact(e, 1))\n\tfmt.Println(d.AddExact(e, 2))\n\tfmt.Println(d.AddExact(e, 3))\n\tfmt.Println(d.AddExact(e, 4))\n\t// Output:\n\t// 13.67 <nil>\n\t// 13.67 <nil>\n\t// 13.67 <nil>\n\t// 13.670 <nil>\n\t// 13.6700 <nil>\n}\n\nfunc ExampleDecimal_Sub() {\n\td := decimal.MustParse(\"-5.67\")\n\te := decimal.MustParse(\"8\")\n\tfmt.Println(d.Sub(e))\n\tfmt.Println(e.Sub(d))\n\t// Output:\n\t// -13.67 <nil>\n\t// 13.67 <nil>\n}\n\nfunc ExampleDecimal_SubAbs() {\n\td := decimal.MustParse(\"-5.67\")\n\te := decimal.MustParse(\"8\")\n\tfmt.Println(d.SubAbs(e))\n\tfmt.Println(e.SubAbs(d))\n\t// Output:\n\t// 13.67 <nil>\n\t// 13.67 <nil>\n}\n\nfunc ExampleDecimal_SubExact() {\n\td := decimal.MustParse(\"8\")\n\te := decimal.MustParse(\"5.67\")\n\tfmt.Println(d.SubExact(e, 0))\n\tfmt.Println(d.SubExact(e, 1))\n\tfmt.Println(d.SubExact(e, 2))\n\tfmt.Println(d.SubExact(e, 3))\n\tfmt.Println(d.SubExact(e, 4))\n\t// Output:\n\t// 2.33 <nil>\n\t// 2.33 <nil>\n\t// 2.33 <nil>\n\t// 2.330 <nil>\n\t// 2.3300 <nil>\n}\n\nfunc ExampleDecimal_Quo() {\n\td := decimal.MustParse(\"5.67\")\n\te := decimal.MustParse(\"2\")\n\tfmt.Println(d.Quo(e))\n\t// Output: 2.835 <nil>\n}\n\nfunc ExampleDecimal_QuoExact() {\n\td := decimal.MustParse(\"5.66\")\n\te := decimal.MustParse(\"2\")\n\tfmt.Println(d.QuoExact(e, 0))\n\tfmt.Println(d.QuoExact(e, 1))\n\tfmt.Println(d.QuoExact(e, 2))\n\tfmt.Println(d.QuoExact(e, 3))\n\tfmt.Println(d.QuoExact(e, 4))\n\t// Output:\n\t// 2.83 <nil>\n\t// 2.83 <nil>\n\t// 2.83 <nil>\n\t// 2.830 <nil>\n\t// 2.8300 <nil>\n}\n\nfunc ExampleDecimal_QuoRem() {\n\td := decimal.MustParse(\"5.67\")\n\te := decimal.MustParse(\"2\")\n\tfmt.Println(d.QuoRem(e))\n\t// Output: 2 1.67 <nil>\n}\n\nfunc ExampleDecimal_Inv() {\n\td := decimal.MustParse(\"2\")\n\tfmt.Println(d.Inv())\n\t// Output: 0.5 <nil>\n}\n\nfunc ExampleDecimal_Less() {\n\td := decimal.MustParse(\"-23\")\n\te := decimal.MustParse(\"5.67\")\n\tfmt.Println(d.Less(e))\n\tfmt.Println(e.Less(d))\n\t// Output:\n\t// true\n\t// false\n}\n\nfunc ExampleDecimal_Equal() {\n\td := decimal.MustParse(\"-23\")\n\te := decimal.MustParse(\"5.67\")\n\tfmt.Println(d.Equal(e))\n\tfmt.Println(d.Equal(d))\n\t// Output:\n\t// false\n\t// true\n}\n\nfunc ExampleDecimal_Equal_slices() {\n\ts := []decimal.Decimal{\n\t\tdecimal.MustParse(\"-5.67\"),\n\t\tdecimal.MustParse(\"0\"),\n\t\tdecimal.MustParse(\"0\"),\n\t}\n\tfmt.Println(slices.EqualFunc(s, s, decimal.Decimal.Equal))\n\tfmt.Println(slices.CompactFunc(s, decimal.Decimal.Equal))\n\t// Output:\n\t// true\n\t// [-5.67 0]\n}\n\nfunc ExampleDecimal_Cmp() {\n\td := decimal.MustParse(\"-23\")\n\te := decimal.MustParse(\"5.67\")\n\tfmt.Println(d.Cmp(e))\n\tfmt.Println(d.Cmp(d))\n\tfmt.Println(e.Cmp(d))\n\t// Output:\n\t// -1\n\t// 0\n\t// 1\n}\n\nfunc ExampleDecimal_Cmp_slices() {\n\ts := []decimal.Decimal{\n\t\tdecimal.MustParse(\"-5.67\"),\n\t\tdecimal.MustParse(\"23\"),\n\t\tdecimal.MustParse(\"0\"),\n\t}\n\tfmt.Println(slices.CompareFunc(s, s, decimal.Decimal.Cmp))\n\tfmt.Println(slices.MaxFunc(s, decimal.Decimal.Cmp))\n\tfmt.Println(slices.MinFunc(s, decimal.Decimal.Cmp))\n\tfmt.Println(s, slices.IsSortedFunc(s, decimal.Decimal.Cmp))\n\tslices.SortFunc(s, decimal.Decimal.Cmp)\n\tfmt.Println(s, slices.IsSortedFunc(s, decimal.Decimal.Cmp))\n\tfmt.Println(slices.BinarySearchFunc(s, decimal.MustParse(\"1\"), decimal.Decimal.Cmp))\n\t// Output:\n\t// 0\n\t// 23\n\t// -5.67\n\t// [-5.67 23 0] false\n\t// [-5.67 0 23] true\n\t// 2 false\n}\n\nfunc ExampleDecimal_CmpAbs() {\n\td := decimal.MustParse(\"-23\")\n\te := decimal.MustParse(\"5.67\")\n\tfmt.Println(d.CmpAbs(e))\n\tfmt.Println(d.CmpAbs(d))\n\tfmt.Println(e.CmpAbs(d))\n\t// Output:\n\t// 1\n\t// 0\n\t// -1\n}\n\nfunc ExampleDecimal_CmpAbs_slices() {\n\ts := []decimal.Decimal{\n\t\tdecimal.MustParse(\"-5.67\"),\n\t\tdecimal.MustParse(\"23\"),\n\t\tdecimal.MustParse(\"0\"),\n\t}\n\tfmt.Println(slices.CompareFunc(s, s, decimal.Decimal.CmpAbs))\n\tfmt.Println(slices.MaxFunc(s, decimal.Decimal.CmpAbs))\n\tfmt.Println(slices.MinFunc(s, decimal.Decimal.CmpAbs))\n\tfmt.Println(s, slices.IsSortedFunc(s, decimal.Decimal.CmpAbs))\n\tslices.SortFunc(s, decimal.Decimal.CmpAbs)\n\tfmt.Println(s, slices.IsSortedFunc(s, decimal.Decimal.CmpAbs))\n\tfmt.Println(slices.BinarySearchFunc(s, decimal.MustParse(\"1\"), decimal.Decimal.CmpAbs))\n\t// Output:\n\t// 0\n\t// 23\n\t// 0\n\t// [-5.67 23 0] false\n\t// [0 -5.67 23] true\n\t// 1 false\n}\n\nfunc ExampleDecimal_CmpTotal() {\n\td := decimal.MustParse(\"2.0\")\n\te := decimal.MustParse(\"2.00\")\n\tfmt.Println(d.CmpTotal(e))\n\tfmt.Println(d.CmpTotal(d))\n\tfmt.Println(e.CmpTotal(d))\n\t// Output:\n\t// 1\n\t// 0\n\t// -1\n}\n\nfunc ExampleDecimal_CmpTotal_slices() {\n\ts := []decimal.Decimal{\n\t\tdecimal.MustParse(\"-5.67\"),\n\t\tdecimal.MustParse(\"23\"),\n\t\tdecimal.MustParse(\"0\"),\n\t}\n\tfmt.Println(slices.CompareFunc(s, s, decimal.Decimal.CmpTotal))\n\tfmt.Println(slices.MaxFunc(s, decimal.Decimal.CmpTotal))\n\tfmt.Println(slices.MinFunc(s, decimal.Decimal.CmpTotal))\n\tfmt.Println(s, slices.IsSortedFunc(s, decimal.Decimal.CmpTotal))\n\tslices.SortFunc(s, decimal.Decimal.CmpTotal)\n\tfmt.Println(s, slices.IsSortedFunc(s, decimal.Decimal.CmpTotal))\n\tfmt.Println(slices.BinarySearchFunc(s, decimal.MustParse(\"10\"), decimal.Decimal.CmpTotal))\n\t// Output:\n\t// 0\n\t// 23\n\t// -5.67\n\t// [-5.67 23 0] false\n\t// [-5.67 0 23] true\n\t// 2 false\n}\n\nfunc ExampleDecimal_Max() {\n\td := decimal.MustParse(\"23\")\n\te := decimal.MustParse(\"-5.67\")\n\tfmt.Println(d.Max(e))\n\t// Output: 23\n}\n\nfunc ExampleDecimal_Min() {\n\td := decimal.MustParse(\"23\")\n\te := decimal.MustParse(\"-5.67\")\n\tfmt.Println(d.Min(e))\n\t// Output: -5.67\n}\n\n//nolint:revive\nfunc ExampleDecimal_Clamp() {\n\tmin := decimal.MustParse(\"-20\")\n\tmax := decimal.MustParse(\"20\")\n\td := decimal.MustParse(\"-5.67\")\n\te := decimal.MustParse(\"0\")\n\tf := decimal.MustParse(\"23\")\n\tfmt.Println(d.Clamp(min, max))\n\tfmt.Println(e.Clamp(min, max))\n\tfmt.Println(f.Clamp(min, max))\n\t// Output:\n\t// -5.67 <nil>\n\t// 0 <nil>\n\t// 20 <nil>\n}\n\nfunc ExampleDecimal_Rescale() {\n\td := decimal.MustParse(\"5.678\")\n\tfmt.Println(d.Rescale(0))\n\tfmt.Println(d.Rescale(1))\n\tfmt.Println(d.Rescale(2))\n\tfmt.Println(d.Rescale(3))\n\tfmt.Println(d.Rescale(4))\n\t// Output:\n\t// 6\n\t// 5.7\n\t// 5.68\n\t// 5.678\n\t// 5.6780\n}\n\nfunc ExampleDecimal_Quantize() {\n\td := decimal.MustParse(\"5.678\")\n\tx := decimal.MustParse(\"1\")\n\ty := decimal.MustParse(\"0.1\")\n\tz := decimal.MustParse(\"0.01\")\n\tfmt.Println(d.Quantize(x))\n\tfmt.Println(d.Quantize(y))\n\tfmt.Println(d.Quantize(z))\n\t// Output:\n\t// 6\n\t// 5.7\n\t// 5.68\n}\n\nfunc ExampleDecimal_Pad() {\n\td := decimal.MustParse(\"5.67\")\n\tfmt.Println(d.Pad(0))\n\tfmt.Println(d.Pad(1))\n\tfmt.Println(d.Pad(2))\n\tfmt.Println(d.Pad(3))\n\tfmt.Println(d.Pad(4))\n\t// Output:\n\t// 5.67\n\t// 5.67\n\t// 5.67\n\t// 5.670\n\t// 5.6700\n}\n\nfunc ExampleDecimal_Round() {\n\td := decimal.MustParse(\"5.678\")\n\tfmt.Println(d.Round(0))\n\tfmt.Println(d.Round(1))\n\tfmt.Println(d.Round(2))\n\tfmt.Println(d.Round(3))\n\tfmt.Println(d.Round(4))\n\t// Output:\n\t// 6\n\t// 5.7\n\t// 5.68\n\t// 5.678\n\t// 5.678\n}\n\nfunc ExampleDecimal_Trunc() {\n\td := decimal.MustParse(\"5.678\")\n\tfmt.Println(d.Trunc(0))\n\tfmt.Println(d.Trunc(1))\n\tfmt.Println(d.Trunc(2))\n\tfmt.Println(d.Trunc(3))\n\tfmt.Println(d.Trunc(4))\n\t// Output:\n\t// 5\n\t// 5.6\n\t// 5.67\n\t// 5.678\n\t// 5.678\n}\n\nfunc ExampleDecimal_Ceil() {\n\td := decimal.MustParse(\"5.678\")\n\tfmt.Println(d.Ceil(0))\n\tfmt.Println(d.Ceil(1))\n\tfmt.Println(d.Ceil(2))\n\tfmt.Println(d.Ceil(3))\n\tfmt.Println(d.Ceil(4))\n\t// Output:\n\t// 6\n\t// 5.7\n\t// 5.68\n\t// 5.678\n\t// 5.678\n}\n\nfunc ExampleDecimal_Floor() {\n\td := decimal.MustParse(\"5.678\")\n\tfmt.Println(d.Floor(0))\n\tfmt.Println(d.Floor(1))\n\tfmt.Println(d.Floor(2))\n\tfmt.Println(d.Floor(3))\n\tfmt.Println(d.Floor(4))\n\t// Output:\n\t// 5\n\t// 5.6\n\t// 5.67\n\t// 5.678\n\t// 5.678\n}\n\nfunc ExampleDecimal_Scale() {\n\td := decimal.MustParse(\"23\")\n\te := decimal.MustParse(\"5.67\")\n\tfmt.Println(d.Scale())\n\tfmt.Println(e.Scale())\n\t// Output:\n\t// 0\n\t// 2\n}\n\nfunc ExampleDecimal_SameScale() {\n\ta := decimal.MustParse(\"23\")\n\tb := decimal.MustParse(\"5.67\")\n\tc := decimal.MustParse(\"1.23\")\n\tfmt.Println(a.SameScale(b))\n\tfmt.Println(b.SameScale(c))\n\t// Output:\n\t// false\n\t// true\n}\n\nfunc ExampleDecimal_MinScale() {\n\td := decimal.MustParse(\"23.0000\")\n\te := decimal.MustParse(\"-5.6700\")\n\tfmt.Println(d.MinScale())\n\tfmt.Println(e.MinScale())\n\t// Output:\n\t// 0\n\t// 2\n}\n\nfunc ExampleDecimal_Trim() {\n\td := decimal.MustParse(\"23.400\")\n\tfmt.Println(d.Trim(0))\n\tfmt.Println(d.Trim(1))\n\tfmt.Println(d.Trim(2))\n\tfmt.Println(d.Trim(3))\n\tfmt.Println(d.Trim(4))\n\t// Output:\n\t// 23.4\n\t// 23.4\n\t// 23.40\n\t// 23.400\n\t// 23.400\n}\n\nfunc ExampleDecimal_Abs() {\n\td := decimal.MustParse(\"-5.67\")\n\tfmt.Println(d.Abs())\n\t// Output: 5.67\n}\n\nfunc ExampleDecimal_CopySign() {\n\td := decimal.MustParse(\"23.00\")\n\te := decimal.MustParse(\"-5.67\")\n\tfmt.Println(d.CopySign(e))\n\tfmt.Println(e.CopySign(d))\n\t// Output:\n\t// -23.00\n\t// 5.67\n}\n\nfunc ExampleDecimal_Neg() {\n\td := decimal.MustParse(\"5.67\")\n\tfmt.Println(d.Neg())\n\t// Output: -5.67\n}\n\nfunc ExampleDecimal_Sign() {\n\td := decimal.MustParse(\"-5.67\")\n\te := decimal.MustParse(\"23\")\n\tf := decimal.MustParse(\"0\")\n\tfmt.Println(d.Sign())\n\tfmt.Println(e.Sign())\n\tfmt.Println(f.Sign())\n\t// Output:\n\t// -1\n\t// 1\n\t// 0\n}\n\nfunc ExampleDecimal_IsNeg() {\n\td := decimal.MustParse(\"-5.67\")\n\te := decimal.MustParse(\"23\")\n\tf := decimal.MustParse(\"0\")\n\tfmt.Println(d.IsNeg())\n\tfmt.Println(e.IsNeg())\n\tfmt.Println(f.IsNeg())\n\t// Output:\n\t// true\n\t// false\n\t// false\n}\n\nfunc ExampleDecimal_IsNeg_slices() {\n\ts := []decimal.Decimal{\n\t\tdecimal.MustParse(\"-5.67\"),\n\t\tdecimal.MustParse(\"23\"),\n\t\tdecimal.MustParse(\"0\"),\n\t}\n\tfmt.Println(slices.ContainsFunc(s, decimal.Decimal.IsNeg))\n\tfmt.Println(slices.IndexFunc(s, decimal.Decimal.IsNeg))\n\tfmt.Println(slices.DeleteFunc(s, decimal.Decimal.IsNeg))\n\t// Output:\n\t// true\n\t// 0\n\t// [23 0]\n}\n\nfunc ExampleDecimal_IsPos() {\n\td := decimal.MustParse(\"-5.67\")\n\te := decimal.MustParse(\"23\")\n\tf := decimal.MustParse(\"0\")\n\tfmt.Println(d.IsPos())\n\tfmt.Println(e.IsPos())\n\tfmt.Println(f.IsPos())\n\t// Output:\n\t// false\n\t// true\n\t// false\n}\n\nfunc ExampleDecimal_IsPos_slices() {\n\ts := []decimal.Decimal{\n\t\tdecimal.MustParse(\"-5.67\"),\n\t\tdecimal.MustParse(\"23\"),\n\t\tdecimal.MustParse(\"0\"),\n\t}\n\tfmt.Println(slices.ContainsFunc(s, decimal.Decimal.IsPos))\n\tfmt.Println(slices.IndexFunc(s, decimal.Decimal.IsPos))\n\tfmt.Println(slices.DeleteFunc(s, decimal.Decimal.IsPos))\n\t// Output:\n\t// true\n\t// 1\n\t// [-5.67 0]\n}\n\nfunc ExampleDecimal_IsZero() {\n\td := decimal.MustParse(\"-5.67\")\n\te := decimal.MustParse(\"23\")\n\tf := decimal.MustParse(\"0\")\n\tfmt.Println(d.IsZero())\n\tfmt.Println(e.IsZero())\n\tfmt.Println(f.IsZero())\n\t// Output:\n\t// false\n\t// false\n\t// true\n}\n\nfunc ExampleDecimal_IsZero_slices() {\n\ts := []decimal.Decimal{\n\t\tdecimal.MustParse(\"-5.67\"),\n\t\tdecimal.MustParse(\"23\"),\n\t\tdecimal.MustParse(\"0\"),\n\t}\n\tfmt.Println(slices.ContainsFunc(s, decimal.Decimal.IsZero))\n\tfmt.Println(slices.IndexFunc(s, decimal.Decimal.IsZero))\n\tfmt.Println(slices.DeleteFunc(s, decimal.Decimal.IsZero))\n\t// Output:\n\t// true\n\t// 2\n\t// [-5.67 23]\n}\n\nfunc ExampleDecimal_IsInt() {\n\td := decimal.MustParse(\"1.00\")\n\te := decimal.MustParse(\"1.01\")\n\tfmt.Println(d.IsInt())\n\tfmt.Println(e.IsInt())\n\t// Output:\n\t// true\n\t// false\n}\n\nfunc ExampleDecimal_IsInt_slices() {\n\ts := []decimal.Decimal{\n\t\tdecimal.MustParse(\"-5.67\"),\n\t\tdecimal.MustParse(\"23\"),\n\t\tdecimal.MustParse(\"0\"),\n\t}\n\tfmt.Println(slices.ContainsFunc(s, decimal.Decimal.IsInt))\n\tfmt.Println(slices.IndexFunc(s, decimal.Decimal.IsInt))\n\tfmt.Println(slices.DeleteFunc(s, decimal.Decimal.IsInt))\n\t// Output:\n\t// true\n\t// 1\n\t// [-5.67]\n}\n\nfunc ExampleDecimal_IsOne() {\n\td := decimal.MustParse(\"1\")\n\te := decimal.MustParse(\"2\")\n\tfmt.Println(d.IsOne())\n\tfmt.Println(e.IsOne())\n\t// Output:\n\t// true\n\t// false\n}\n\nfunc ExampleDecimal_IsOne_slices() {\n\ts := []decimal.Decimal{\n\t\tdecimal.MustParse(\"-5.67\"),\n\t\tdecimal.MustParse(\"23\"),\n\t\tdecimal.MustParse(\"1\"),\n\t}\n\tfmt.Println(slices.ContainsFunc(s, decimal.Decimal.IsOne))\n\tfmt.Println(slices.IndexFunc(s, decimal.Decimal.IsOne))\n\tfmt.Println(slices.DeleteFunc(s, decimal.Decimal.IsOne))\n\t// Output:\n\t// true\n\t// 2\n\t// [-5.67 23]\n}\n\nfunc ExampleDecimal_WithinOne() {\n\td := decimal.MustParse(\"1\")\n\te := decimal.MustParse(\"0.9\")\n\tf := decimal.MustParse(\"-0.9\")\n\tg := decimal.MustParse(\"-1\")\n\tfmt.Println(d.WithinOne())\n\tfmt.Println(e.WithinOne())\n\tfmt.Println(f.WithinOne())\n\tfmt.Println(g.WithinOne())\n\t// Output:\n\t// false\n\t// true\n\t// true\n\t// false\n}\n\nfunc ExampleDecimal_WithinOne_slices() {\n\ts := []decimal.Decimal{\n\t\tdecimal.MustParse(\"-5.67\"),\n\t\tdecimal.MustParse(\"23\"),\n\t\tdecimal.MustParse(\"0.1\"),\n\t}\n\tfmt.Println(slices.ContainsFunc(s, decimal.Decimal.WithinOne))\n\tfmt.Println(slices.IndexFunc(s, decimal.Decimal.WithinOne))\n\tfmt.Println(slices.DeleteFunc(s, decimal.Decimal.WithinOne))\n\t// Output:\n\t// true\n\t// 2\n\t// [-5.67 23]\n}\n\nfunc ExampleNullDecimal_Scan() {\n\tvar n decimal.NullDecimal\n\t_ = n.Scan(nil)\n\tfmt.Println(n)\n\n\tvar m decimal.NullDecimal\n\t_ = m.Scan(\"5.67\")\n\tfmt.Println(m)\n\t// Output:\n\t// {0 false}\n\t// {5.67 true}\n}\n\nfunc ExampleNullDecimal_Value() {\n\tn := decimal.NullDecimal{\n\t\tValid: false,\n\t}\n\tfmt.Println(n.Value())\n\n\tm := decimal.NullDecimal{\n\t\tDecimal: decimal.MustParse(\"5.67\"),\n\t\tValid:   true,\n\t}\n\tfmt.Println(m.Value())\n\t// Output:\n\t// <nil> <nil>\n\t// 5.67 <nil>\n}\n\nfunc ExampleNullDecimal_UnmarshalJSON_json() {\n\tvar n decimal.NullDecimal\n\t_ = json.Unmarshal([]byte(`null`), &n)\n\tfmt.Println(n)\n\n\tvar m decimal.NullDecimal\n\t_ = json.Unmarshal([]byte(`\"5.67\"`), &m)\n\tfmt.Println(m)\n\t// Output:\n\t// {0 false}\n\t// {5.67 true}\n}\n\nfunc ExampleNullDecimal_MarshalJSON_json() {\n\tn := decimal.NullDecimal{\n\t\tValid: false,\n\t}\n\tdata, _ := json.Marshal(n)\n\tfmt.Println(string(data))\n\n\tm := decimal.NullDecimal{\n\t\tDecimal: decimal.MustParse(\"5.67\"),\n\t\tValid:   true,\n\t}\n\tdata, _ = json.Marshal(m)\n\tfmt.Println(string(data))\n\t// Output:\n\t// null\n\t// \"5.67\"\n}\n\nfunc ExampleNullDecimal_UnmarshalBSONValue_bson() {\n\tvar n decimal.NullDecimal\n\t_ = n.UnmarshalBSONValue(10, nil)\n\tfmt.Println(n)\n\n\tdata := []byte{\n\t\t0x37, 0x02, 0x00, 0x00,\n\t\t0x00, 0x00, 0x00, 0x00,\n\t\t0x00, 0x00, 0x00, 0x00,\n\t\t0x00, 0x00, 0x3c, 0x30,\n\t}\n\tvar m decimal.NullDecimal\n\t_ = m.UnmarshalBSONValue(19, data)\n\tfmt.Println(m)\n\t// Output:\n\t// {0 false}\n\t// {5.67 true}\n}\n\nfunc ExampleNullDecimal_MarshalBSONValue_bson() {\n\tn := decimal.NullDecimal{\n\t\tValid: false,\n\t}\n\tt, data, _ := n.MarshalBSONValue()\n\tfmt.Printf(\"%v [% x]\\n\", t, data)\n\n\tm := decimal.NullDecimal{\n\t\tDecimal: decimal.MustParse(\"5.67\"),\n\t\tValid:   true,\n\t}\n\tt, data, _ = m.MarshalBSONValue()\n\tfmt.Printf(\"%v [% x]\\n\", t, data)\n\t// Output:\n\t// 10 []\n\t// 19 [37 02 00 00 00 00 00 00 00 00 00 00 00 00 3c 30]\n}\n"
  },
  {
    "path": "go.mod",
    "content": "module github.com/govalues/decimal\n\ngo 1.22\n"
  },
  {
    "path": "integer.go",
    "content": "package decimal\n\nimport (\n\t\"fmt\"\n\t\"math/big\"\n\t\"sync\"\n)\n\n// fint (Fast INTeger) is a wrapper around uint64.\ntype fint uint64\n\n// maxFint is a maximum value of fint.\nconst maxFint = 9_999_999_999_999_999_999\n\n// pow10 is a cache of powers of 10, where pow10[x] = 10^x.\nvar pow10 = [...]fint{\n\t1,                          // 10^0\n\t10,                         // 10^1\n\t100,                        // 10^2\n\t1_000,                      // 10^3\n\t10_000,                     // 10^4\n\t100_000,                    // 10^5\n\t1_000_000,                  // 10^6\n\t10_000_000,                 // 10^7\n\t100_000_000,                // 10^8\n\t1_000_000_000,              // 10^9\n\t10_000_000_000,             // 10^10\n\t100_000_000_000,            // 10^11\n\t1_000_000_000_000,          // 10^12\n\t10_000_000_000_000,         // 10^13\n\t100_000_000_000_000,        // 10^14\n\t1_000_000_000_000_000,      // 10^15\n\t10_000_000_000_000_000,     // 10^16\n\t100_000_000_000_000_000,    // 10^17\n\t1_000_000_000_000_000_000,  // 10^18\n\t10_000_000_000_000_000_000, // 10^19\n}\n\n// add calculates x + y and checks overflow.\nfunc (x fint) add(y fint) (z fint, ok bool) {\n\tif maxFint-x < y {\n\t\treturn 0, false\n\t}\n\tz = x + y\n\treturn z, true\n}\n\n// mul calculates x * y and checks overflow.\nfunc (x fint) mul(y fint) (z fint, ok bool) {\n\tif y == 0 {\n\t\treturn 0, true\n\t}\n\tz = x * y\n\tif z/y != x {\n\t\treturn 0, false\n\t}\n\tif z > maxFint {\n\t\treturn 0, false\n\t}\n\treturn z, true\n}\n\n// quo calculates x / y and checks division by zero and inexact division.\nfunc (x fint) quo(y fint) (z fint, ok bool) {\n\tif y == 0 {\n\t\treturn 0, false\n\t}\n\tz = x / y\n\tif z*y != x {\n\t\treturn 0, false\n\t}\n\treturn z, true\n}\n\n// quoRem calculates q = ⌊x / y⌋, r = x - y * q and checks division by zero.\nfunc (x fint) quoRem(y fint) (q, r fint, ok bool) {\n\tif y == 0 {\n\t\treturn 0, 0, false\n\t}\n\tq = x / y\n\tr = x - q*y\n\treturn q, r, true\n}\n\n// subAbs calculates |x - y|.\nfunc (x fint) subAbs(y fint) fint {\n\tif x > y {\n\t\treturn x - y\n\t}\n\treturn y - x\n}\n\n// lsh (Left Shift) calculates x * 10^shift and checks overflow.\nfunc (x fint) lsh(shift int) (z fint, ok bool) {\n\t// Special cases\n\tswitch {\n\tcase shift <= 0:\n\t\treturn x, true\n\tcase shift == 1 && x < maxFint/10: // to speed up common case\n\t\treturn x * 10, true\n\tcase shift >= len(pow10):\n\t\treturn 0, false\n\t}\n\t// General case\n\ty := pow10[shift]\n\treturn x.mul(y)\n}\n\n// fsa (Fused Shift and Addition) calculates x * 10^shift + b and checks overflow.\nfunc (x fint) fsa(shift int, b byte) (z fint, ok bool) {\n\tz, ok = x.lsh(shift)\n\tif !ok {\n\t\treturn 0, false\n\t}\n\tz, ok = z.add(fint(b))\n\tif !ok {\n\t\treturn 0, false\n\t}\n\treturn z, true\n}\n\nfunc (x fint) isOdd() bool {\n\treturn x&1 != 0\n}\n\n// rshHalfEven (Right Shift) calculates round(x / 10^shift) and rounds result\n// using \"half to even\" rule.\nfunc (x fint) rshHalfEven(shift int) fint {\n\t// Special cases\n\tswitch {\n\tcase x == 0:\n\t\treturn 0\n\tcase shift <= 0:\n\t\treturn x\n\tcase shift >= len(pow10):\n\t\treturn 0\n\t}\n\t// General case\n\ty := pow10[shift]\n\tz := x / y\n\tr := x - z*y                        // r = x % y\n\ty = y >> 1                          // y = y / 2, which is safe as y is a multiple of 10\n\tif y < r || (y == r && z.isOdd()) { // half-to-even\n\t\tz++\n\t}\n\treturn z\n}\n\n// rshUp (Right Shift) calculates ⌈x / 10^shift⌉ and rounds result away from zero.\nfunc (x fint) rshUp(shift int) fint {\n\t// Special cases\n\tswitch {\n\tcase x == 0:\n\t\treturn 0\n\tcase shift <= 0:\n\t\treturn x\n\tcase shift >= len(pow10):\n\t\treturn 1\n\t}\n\t// General case\n\ty := pow10[shift]\n\tz := x / y\n\tr := x - z*y // r = x % y\n\tif r > 0 {\n\t\tz++\n\t}\n\treturn z\n}\n\n// rshDown (Right Shift) calculates ⌊x / 10^shift⌋ and rounds result towards zero.\nfunc (x fint) rshDown(shift int) fint {\n\t// Special cases\n\tswitch {\n\tcase x == 0:\n\t\treturn 0\n\tcase shift <= 0:\n\t\treturn x\n\tcase shift >= len(pow10):\n\t\treturn 0\n\t}\n\t// General case\n\ty := pow10[shift]\n\treturn x / y\n}\n\n// prec returns length of x in decimal digits.\n// prec assumes that 0 has no digits.\nfunc (x fint) prec() int {\n\tleft, right := 0, len(pow10)\n\tfor left < right {\n\t\tmid := (left + right) / 2\n\t\tif x < pow10[mid] {\n\t\t\tright = mid\n\t\t} else {\n\t\t\tleft = mid + 1\n\t\t}\n\t}\n\treturn left\n}\n\n// ntz returns number of trailing zeros in x.\n// ntz assumes that 0 has no trailing zeros.\nfunc (x fint) ntz() int {\n\tleft, right := 1, x.prec()\n\tfor left < right {\n\t\tmid := (left + right) / 2\n\t\tif x%pow10[mid] == 0 {\n\t\t\tleft = mid + 1\n\t\t} else {\n\t\t\tright = mid\n\t\t}\n\t}\n\treturn left - 1\n}\n\n// hasPrec returns true if x has given number of digits or more.\n// hasPrec assumes that 0 has no digits.\n//\n// x.hasPrec(p) is significantly faster than x.prec() >= p.\nfunc (x fint) hasPrec(prec int) bool {\n\t// Special cases\n\tswitch {\n\tcase prec < 1:\n\t\treturn true\n\tcase prec > len(pow10):\n\t\treturn false\n\t}\n\t// General case\n\treturn x >= pow10[prec-1]\n}\n\n// bint (Big INTeger) is a wrapper around big.Int.\ntype bint big.Int\n\n// bpow10 is a cache of powers of 10, where bpow10[x] = 10^x.\nvar bpow10 = [...]*bint{\n\tmustParseBint(\"1\"),\n\tmustParseBint(\"10\"),\n\tmustParseBint(\"100\"),\n\tmustParseBint(\"1000\"),\n\tmustParseBint(\"10000\"),\n\tmustParseBint(\"100000\"),\n\tmustParseBint(\"1000000\"),\n\tmustParseBint(\"10000000\"),\n\tmustParseBint(\"100000000\"),\n\tmustParseBint(\"1000000000\"),\n\tmustParseBint(\"10000000000\"),\n\tmustParseBint(\"100000000000\"),\n\tmustParseBint(\"1000000000000\"),\n\tmustParseBint(\"10000000000000\"),\n\tmustParseBint(\"100000000000000\"),\n\tmustParseBint(\"1000000000000000\"),\n\tmustParseBint(\"10000000000000000\"),\n\tmustParseBint(\"100000000000000000\"),\n\tmustParseBint(\"1000000000000000000\"),\n\tmustParseBint(\"10000000000000000000\"),\n\tmustParseBint(\"100000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n\tmustParseBint(\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"),\n}\n\n// bfact is a cache of factorials, where bfact[x] = x!.\nvar bfact = [...]*bint{\n\tmustParseBint(\"1\"),\n\tmustParseBint(\"1\"),\n\tmustParseBint(\"2\"),\n\tmustParseBint(\"6\"),\n\tmustParseBint(\"24\"),\n\tmustParseBint(\"120\"),\n\tmustParseBint(\"720\"),\n\tmustParseBint(\"5040\"),\n\tmustParseBint(\"40320\"),\n\tmustParseBint(\"362880\"),\n\tmustParseBint(\"3628800\"),\n\tmustParseBint(\"39916800\"),\n\tmustParseBint(\"479001600\"),\n\tmustParseBint(\"6227020800\"),\n\tmustParseBint(\"87178291200\"),\n\tmustParseBint(\"1307674368000\"),\n\tmustParseBint(\"20922789888000\"),\n\tmustParseBint(\"355687428096000\"),\n\tmustParseBint(\"6402373705728000\"),\n\tmustParseBint(\"121645100408832000\"),\n\tmustParseBint(\"2432902008176640000\"),\n\tmustParseBint(\"51090942171709440000\"),\n\tmustParseBint(\"1124000727777607680000\"),\n\tmustParseBint(\"25852016738884976640000\"),\n\tmustParseBint(\"620448401733239439360000\"),\n\tmustParseBint(\"15511210043330985984000000\"),\n\tmustParseBint(\"403291461126605635584000000\"),\n\tmustParseBint(\"10888869450418352160768000000\"),\n\tmustParseBint(\"304888344611713860501504000000\"),\n\tmustParseBint(\"8841761993739701954543616000000\"),\n\tmustParseBint(\"265252859812191058636308480000000\"),\n\tmustParseBint(\"8222838654177922817725562880000000\"),\n\tmustParseBint(\"263130836933693530167218012160000000\"),\n\tmustParseBint(\"8683317618811886495518194401280000000\"),\n\tmustParseBint(\"295232799039604140847618609643520000000\"),\n\tmustParseBint(\"10333147966386144929666651337523200000000\"),\n\tmustParseBint(\"371993326789901217467999448150835200000000\"),\n\tmustParseBint(\"13763753091226345046315979581580902400000000\"),\n\tmustParseBint(\"523022617466601111760007224100074291200000000\"),\n\tmustParseBint(\"20397882081197443358640281739902897356800000000\"),\n\tmustParseBint(\"815915283247897734345611269596115894272000000000\"),\n\tmustParseBint(\"33452526613163807108170062053440751665152000000000\"),\n\tmustParseBint(\"1405006117752879898543142606244511569936384000000000\"),\n\tmustParseBint(\"60415263063373835637355132068513997507264512000000000\"),\n\tmustParseBint(\"2658271574788448768043625811014615890319638528000000000\"),\n\tmustParseBint(\"119622220865480194561963161495657715064383733760000000000\"),\n\tmustParseBint(\"5502622159812088949850305428800254892961651752960000000000\"),\n\tmustParseBint(\"258623241511168180642964355153611979969197632389120000000000\"),\n\tmustParseBint(\"12413915592536072670862289047373375038521486354677760000000000\"),\n\tmustParseBint(\"608281864034267560872252163321295376887552831379210240000000000\"),\n\tmustParseBint(\"30414093201713378043612608166064768844377641568960512000000000000\"),\n\tmustParseBint(\"1551118753287382280224243016469303211063259720016986112000000000000\"),\n\tmustParseBint(\"80658175170943878571660636856403766975289505440883277824000000000000\"),\n\tmustParseBint(\"4274883284060025564298013753389399649690343788366813724672000000000000\"),\n\tmustParseBint(\"230843697339241380472092742683027581083278564571807941132288000000000000\"),\n\tmustParseBint(\"12696403353658275925965100847566516959580321051449436762275840000000000000\"),\n\tmustParseBint(\"710998587804863451854045647463724949736497978881168458687447040000000000000\"),\n\tmustParseBint(\"40526919504877216755680601905432322134980384796226602145184481280000000000000\"),\n\tmustParseBint(\"2350561331282878571829474910515074683828862318181142924420699914240000000000000\"),\n\tmustParseBint(\"138683118545689835737939019720389406345902876772687432540821294940160000000000000\"),\n\tmustParseBint(\"8320987112741390144276341183223364380754172606361245952449277696409600000000000000\"),\n\tmustParseBint(\"507580213877224798800856812176625227226004528988036003099405939480985600000000000000\"),\n\tmustParseBint(\"31469973260387937525653122354950764088012280797258232192163168247821107200000000000000\"),\n\tmustParseBint(\"1982608315404440064116146708361898137544773690227268628106279599612729753600000000000000\"),\n\tmustParseBint(\"126886932185884164103433389335161480802865516174545192198801894375214704230400000000000000\"),\n\tmustParseBint(\"8247650592082470666723170306785496252186258551345437492922123134388955774976000000000000000\"),\n\tmustParseBint(\"544344939077443064003729240247842752644293064388798874532860126869671081148416000000000000000\"),\n\tmustParseBint(\"36471110918188685288249859096605464427167635314049524593701628500267962436943872000000000000000\"),\n\tmustParseBint(\"2480035542436830599600990418569171581047399201355367672371710738018221445712183296000000000000000\"),\n\tmustParseBint(\"171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000\"),\n\tmustParseBint(\"11978571669969891796072783721689098736458938142546425857555362864628009582789845319680000000000000000\"),\n\tmustParseBint(\"850478588567862317521167644239926010288584608120796235886430763388588680378079017697280000000000000000\"),\n\tmustParseBint(\"61234458376886086861524070385274672740778091784697328983823014963978384987221689274204160000000000000000\"),\n\tmustParseBint(\"4470115461512684340891257138125051110076800700282905015819080092370422104067183317016903680000000000000000\"),\n\tmustParseBint(\"330788544151938641225953028221253782145683251820934971170611926835411235700971565459250872320000000000000000\"),\n\tmustParseBint(\"24809140811395398091946477116594033660926243886570122837795894512655842677572867409443815424000000000000000000\"),\n\tmustParseBint(\"1885494701666050254987932260861146558230394535379329335672487982961844043495537923117729972224000000000000000000\"),\n\tmustParseBint(\"145183092028285869634070784086308284983740379224208358846781574688061991349156420080065207861248000000000000000000\"),\n\tmustParseBint(\"11324281178206297831457521158732046228731749579488251990048962825668835325234200766245086213177344000000000000000000\"),\n\tmustParseBint(\"894618213078297528685144171539831652069808216779571907213868063227837990693501860533361810841010176000000000000000000\"),\n\tmustParseBint(\"71569457046263802294811533723186532165584657342365752577109445058227039255480148842668944867280814080000000000000000000\"),\n\tmustParseBint(\"5797126020747367985879734231578109105412357244731625958745865049716390179693892056256184534249745940480000000000000000000\"),\n\tmustParseBint(\"475364333701284174842138206989404946643813294067993328617160934076743994734899148613007131808479167119360000000000000000000\"),\n\tmustParseBint(\"39455239697206586511897471180120610571436503407643446275224357528369751562996629334879591940103770870906880000000000000000000\"),\n\tmustParseBint(\"3314240134565353266999387579130131288000666286242049487118846032383059131291716864129885722968716753156177920000000000000000000\"),\n\tmustParseBint(\"281710411438055027694947944226061159480056634330574206405101912752560026159795933451040286452340924018275123200000000000000000000\"),\n\tmustParseBint(\"24227095383672732381765523203441259715284870552429381750838764496720162249742450276789464634901319465571660595200000000000000000000\"),\n\tmustParseBint(\"2107757298379527717213600518699389595229783738061356212322972511214654115727593174080683423236414793504734471782400000000000000000000\"),\n\tmustParseBint(\"185482642257398439114796845645546284380220968949399346684421580986889562184028199319100141244804501828416633516851200000000000000000000\"),\n\tmustParseBint(\"16507955160908461081216919262453619309839666236496541854913520707833171034378509739399912570787600662729080382999756800000000000000000000\"),\n\tmustParseBint(\"1485715964481761497309522733620825737885569961284688766942216863704985393094065876545992131370884059645617234469978112000000000000000000000\"),\n\tmustParseBint(\"135200152767840296255166568759495142147586866476906677791741734597153670771559994765685283954750449427751168336768008192000000000000000000000\"),\n\tmustParseBint(\"12438414054641307255475324325873553077577991715875414356840239582938137710983519518443046123837041347353107486982656753664000000000000000000000\"),\n\tmustParseBint(\"1156772507081641574759205162306240436214753229576413535186142281213246807121467315215203289516844845303838996289387078090752000000000000000000000\"),\n\tmustParseBint(\"108736615665674308027365285256786601004186803580182872307497374434045199869417927630229109214583415458560865651202385340530688000000000000000000000\"),\n\tmustParseBint(\"10329978488239059262599702099394727095397746340117372869212250571234293987594703124871765375385424468563282236864226607350415360000000000000000000000\"),\n\tmustParseBint(\"991677934870949689209571401541893801158183648651267795444376054838492222809091499987689476037000748982075094738965754305639874560000000000000000000000\"),\n\tmustParseBint(\"96192759682482119853328425949563698712343813919172976158104477319333745612481875498805879175589072651261284189679678167647067832320000000000000000000000\"),\n\tmustParseBint(\"9426890448883247745626185743057242473809693764078951663494238777294707070023223798882976159207729119823605850588608460429412647567360000000000000000000000\"),\n}\n\n// bscale is a scale of precomputed values in bexp, blog and bnlog10.\nconst bscale = 41\n\n// bexp is a cache of powers of e, where bexp[x] = round(exp(x) * 10^41).\nvar bexp = [...]*bint{\n\tmustParseBint(\"100000000000000000000000000000000000000000\"),\n\tmustParseBint(\"271828182845904523536028747135266249775725\"),\n\tmustParseBint(\"738905609893065022723042746057500781318032\"),\n\tmustParseBint(\"2008553692318766774092852965458171789698791\"),\n\tmustParseBint(\"5459815003314423907811026120286087840279074\"),\n\tmustParseBint(\"14841315910257660342111558004055227962348767\"),\n\tmustParseBint(\"40342879349273512260838718054338827960589990\"),\n\tmustParseBint(\"109663315842845859926372023828812143244221913\"),\n\tmustParseBint(\"298095798704172827474359209945288867375596794\"),\n\tmustParseBint(\"810308392757538400770999668943275996501147609\"),\n\tmustParseBint(\"2202646579480671651695790064528424436635351262\"),\n\tmustParseBint(\"5987414171519781845532648579225778161426107970\"),\n\tmustParseBint(\"16275479141900392080800520489848678317020928448\"),\n\tmustParseBint(\"44241339200892050332610277594908828178439130606\"),\n\tmustParseBint(\"120260428416477677774923677076785944941248654338\"),\n\tmustParseBint(\"326901737247211063930185504609172131550573854382\"),\n\tmustParseBint(\"888611052050787263676302374078145035080271982186\"),\n\tmustParseBint(\"2415495275357529821477543518038582387986756735272\"),\n\tmustParseBint(\"6565996913733051113878650325906003356921635578619\"),\n\tmustParseBint(\"17848230096318726084491003378872270388361973316517\"),\n\tmustParseBint(\"48516519540979027796910683054154055868463898894485\"),\n\tmustParseBint(\"131881573448321469720999888374530278509144443738048\"),\n\tmustParseBint(\"358491284613159156168115994597842068922269306503727\"),\n\tmustParseBint(\"974480344624890260003463268482297527764938776403601\"),\n\tmustParseBint(\"2648912212984347229413916215281188234087019861924853\"),\n\tmustParseBint(\"7200489933738587252416135146612615791522353381339528\"),\n\tmustParseBint(\"19572960942883876426977639787609534279203610095069759\"),\n\tmustParseBint(\"53204824060179861668374730434117744165925580428368881\"),\n\tmustParseBint(\"144625706429147517367704742299692885690206232950992288\"),\n\tmustParseBint(\"393133429714404207438862058084352768579694233344390219\"),\n\tmustParseBint(\"1068647458152446214699046865074140165002449500547305499\"),\n\tmustParseBint(\"2904884966524742523108568211167982566676469509029698025\"),\n\tmustParseBint(\"7896296018268069516097802263510822421995619511535233066\"),\n\tmustParseBint(\"21464357978591606462429776153126088036922590605479789726\"),\n\tmustParseBint(\"58346174252745488140290273461039101900365923894110810578\"),\n\tmustParseBint(\"158601345231343072812964462577466012517620395013452615427\"),\n\tmustParseBint(\"431123154711519522711342229285692539078886361678034773077\"),\n\tmustParseBint(\"1171914237280261130877293979119019452167536369446182238348\"),\n\tmustParseBint(\"3185593175711375622032867170129864599954220990518100775324\"),\n\tmustParseBint(\"8659340042399374695360693271926493424970185470019598659152\"),\n\tmustParseBint(\"23538526683701998540789991074903480450887161725455546723665\"),\n\tmustParseBint(\"63984349353005494922266340351557081887933662139685527945496\"),\n\tmustParseBint(\"173927494152050104739468130361123522614798405772500840103706\"),\n\tmustParseBint(\"472783946822934656147445756274428037081975196238093817096720\"),\n\tmustParseBint(\"1285160011435930827580929963214309925780114322075882587192003\"),\n\tmustParseBint(\"3493427105748509534803479723340609953341165649751815426012609\"),\n\tmustParseBint(\"9496119420602448874513364911711832310181715892107998785043817\"),\n\tmustParseBint(\"25813128861900673962328580021527338043163708299304406081061397\"),\n\tmustParseBint(\"70167359120976317386547159988611740545593799872532198375454888\"),\n\tmustParseBint(\"190734657249509969052509984095384844738818973054378340247523471\"),\n\tmustParseBint(\"518470552858707246408745332293348538482746910058384640190405693\"),\n\tmustParseBint(\"1409349082426938796449214331237016878868476079006371401705261930\"),\n\tmustParseBint(\"3831008000716576849303569548786199389870559745511657759083460282\"),\n\tmustParseBint(\"10413759433029087797183472933493796439804671331549132480520877196\"),\n\tmustParseBint(\"28307533032746939004420635480140745408503258935359068407207313389\"),\n\tmustParseBint(\"76947852651420171381827455901293939920707675726508409192316811729\"),\n\tmustParseBint(\"209165949601299615390707115721467377815296684749926726566766760571\"),\n\tmustParseBint(\"568571999933593222264034882063325330337215833448821774348912207348\"),\n\tmustParseBint(\"1545538935590103930353076691117462006836371709693083024671167680619\"),\n\tmustParseBint(\"4201210403790514254956593430719161768411111973299096786464257294200\"),\n\tmustParseBint(\"11420073898156842836629571831447656301980459595563958395650279917582\"),\n\tmustParseBint(\"31042979357019199087073421411071003720629501767637088151075640107741\"),\n\tmustParseBint(\"84383566687414544890733294803731179600806926796674104046181781869882\"),\n\tmustParseBint(\"229378315946960987909935284026861360046327934090304823013811995111671\"),\n\tmustParseBint(\"623514908081161688290923870892846974483139184623579991438859169901398\"),\n\tmustParseBint(\"1694889244410333714141783611437197494892623622551650491315726964531624\"),\n\tmustParseBint(\"4607186634331291542677318442806008689334900303709604073064405455741671\"),\n\tmustParseBint(\"12523631708422137805135219607443657675348852740449748164080228572102416\"),\n\tmustParseBint(\"34042760499317405213769071870043505953738761399456516360515457366001246\"),\n\tmustParseBint(\"92537817255877876002423979166873458734765992072084131193538452395984132\"),\n\tmustParseBint(\"251543867091916700626578117425211296140741297338314051382184015698611046\"),\n\tmustParseBint(\"683767122976274386675589282667771095594583593128908772566867276581148527\"),\n\tmustParseBint(\"1858671745284127980340370181254541194694639669623280326839338508664990931\"),\n\tmustParseBint(\"5052393630276104194557038332185764648536724497561717707892131665519301059\"),\n\tmustParseBint(\"13733829795401761877841885298085389315799830792499374638225617048580357052\"),\n\tmustParseBint(\"37332419967990016402549083172647001434277836869160000233938286724489039463\"),\n\tmustParseBint(\"101480038811388872783246178413171697577666481516811788087636356532265354778\"),\n\tmustParseBint(\"275851345452317020628646981990266194334152017524870885909958836251105051085\"),\n\tmustParseBint(\"749841699699012043467563059122406045470465897778615881301712227912805589523\"),\n\tmustParseBint(\"2038281066512668766832313753717263237469736486152421023534282361781159646993\"),\n\tmustParseBint(\"5540622384393510052571173395831661292485672883268532287030018828204570044975\"),\n\tmustParseBint(\"15060973145850305483525941301676749818993964921282654216298674950430270913981\"),\n\tmustParseBint(\"40939969621274546966609142293278290432005379219385277776474289917001253733742\"),\n\tmustParseBint(\"111286375479175941208707147818394080573407692072049303419300322944399234801420\"),\n\tmustParseBint(\"302507732220114233826656639644342874246903222230408816021160842116018977688417\"),\n\tmustParseBint(\"822301271462291351030432801640777469548628618847627403952393384974416103487573\"),\n\tmustParseBint(\"2235246603734715047443065732332714739877539251320997394294418376804179728019707\"),\n\tmustParseBint(\"6076030225056872149522328938130276075261375325962121014840857614538080439681426\"),\n\tmustParseBint(\"16516362549940018555283297962648587670696288420000448138888115075308155590848548\"),\n\tmustParseBint(\"44896128191743452462842455796453162777659805863718515260493172176526871508945617\"),\n\tmustParseBint(\"122040329431784080200271003513636975397074642109976754624434382982431272735857720\"),\n\tmustParseBint(\"331740009833574262575551610785259190960301458118233082704880726006914701279896785\"),\n\tmustParseBint(\"901762840503429893140099598217090525912874611320072683317921490664655375792186090\"),\n\tmustParseBint(\"2451245542920085785552772943110915342348756414964690609545833883604150632588240812\"),\n\tmustParseBint(\"6663176216410895834244814050240873262687388754209656559399850257165488523386744387\"),\n\tmustParseBint(\"18112390828890232821937987580988159250478971745441286187030605794738143642445974469\"),\n\tmustParseBint(\"49234582860120583997548620591133044948377995712526602794095096218650199367793067780\"),\n\tmustParseBint(\"133833471920426950046173640870611502907671745721364460012055487319044738767664950934\"),\n\tmustParseBint(\"363797094760880457928774382676018572989310125586408296287549241498281217782703355658\"),\n\tmustParseBint(\"988903031934694677056003096713803710140508260719933517340199715371109444700740600601\"),\n}\n\n// blog is a cache of natural logarithms, where blog[x] = round(ln(x) * 10^41).\nvar blog = [...]*bint{\n\tnil,\n\tmustParseBint(\"0\"),\n\tmustParseBint(\"69314718055994530941723212145817656807550\"),\n\tmustParseBint(\"109861228866810969139524523692252570464749\"),\n\tmustParseBint(\"138629436111989061883446424291635313615100\"),\n\tmustParseBint(\"160943791243410037460075933322618763952560\"),\n\tmustParseBint(\"179175946922805500081247735838070227272299\"),\n\tmustParseBint(\"194591014905531330510535274344317972963708\"),\n\tmustParseBint(\"207944154167983592825169636437452970422650\"),\n\tmustParseBint(\"219722457733621938279049047384505140929498\"),\n\tmustParseBint(\"230258509299404568401799145468436420760110\"),\n\tmustParseBint(\"239789527279837054406194357796512929982171\"),\n\tmustParseBint(\"248490664978800031022970947983887884079849\"),\n\tmustParseBint(\"256494935746153673605348744156531860480527\"),\n\tmustParseBint(\"263905732961525861452258486490135629771258\"),\n\tmustParseBint(\"270805020110221006599600457014871334417309\"),\n\tmustParseBint(\"277258872223978123766892848583270627230200\"),\n\tmustParseBint(\"283321334405621608024953461787312653558820\"),\n\tmustParseBint(\"289037175789616469220772259530322797737048\"),\n\tmustParseBint(\"294443897916644046000902743188785353723738\"),\n\tmustParseBint(\"299573227355399099343522357614254077567660\"),\n\tmustParseBint(\"304452243772342299650059798036570543428458\"),\n\tmustParseBint(\"309104245335831585347917569942330586789721\"),\n\tmustParseBint(\"313549421592914969080675283181019611844238\"),\n\tmustParseBint(\"317805383034794561964694160129705540887399\"),\n\tmustParseBint(\"321887582486820074920151866645237527905120\"),\n\tmustParseBint(\"325809653802148204547071956302349517288077\"),\n\tmustParseBint(\"329583686600432907418573571076757711394247\"),\n\tmustParseBint(\"333220451017520392393981698635953286578808\"),\n\tmustParseBint(\"336729582998647402718327203236191160549451\"),\n\tmustParseBint(\"340119738166215537541323669160688991224859\"),\n\tmustParseBint(\"343398720448514624592916432454235721044994\"),\n\tmustParseBint(\"346573590279972654708616060729088284037750\"),\n\tmustParseBint(\"349650756146648023545718881488765500446920\"),\n\tmustParseBint(\"352636052461616138966676673933130310366370\"),\n\tmustParseBint(\"355534806148941367970611207666936736916269\"),\n\tmustParseBint(\"358351893845611000162495471676140454544598\"),\n\tmustParseBint(\"361091791264422444436809567103144716390008\"),\n\tmustParseBint(\"363758615972638576942625955334603010531288\"),\n\tmustParseBint(\"366356164612964642744873267848784430945276\"),\n\tmustParseBint(\"368887945411393630285245569760071734375210\"),\n\tmustParseBint(\"371357206670430780386676337303740758837641\"),\n\tmustParseBint(\"373766961828336830591783010182388200236008\"),\n\tmustParseBint(\"376120011569356242347284251334584703555914\"),\n\tmustParseBint(\"378418963391826116289640782088148243597271\"),\n\tmustParseBint(\"380666248977031975739124980707123904882058\"),\n\tmustParseBint(\"382864139648909500022398495326837268651788\"),\n\tmustParseBint(\"385014760171005858682095066977217370889605\"),\n\tmustParseBint(\"387120101090789092906417372275523197694949\"),\n\tmustParseBint(\"389182029811062661021070548688635945927417\"),\n\tmustParseBint(\"391202300542814605861875078791055184712670\"),\n\tmustParseBint(\"393182563272432577164477985479565224023569\"),\n\tmustParseBint(\"395124371858142735488795168448167174095627\"),\n\tmustParseBint(\"397029191355212183414446913902905777035998\"),\n\tmustParseBint(\"398898404656427438360296783222575368201797\"),\n\tmustParseBint(\"400733318523247091866270291119131693934731\"),\n\tmustParseBint(\"402535169073514923335704910781770943386359\"),\n\tmustParseBint(\"404305126783455015140427266881037924188487\"),\n\tmustParseBint(\"406044301054641933660050415382008817357001\"),\n\tmustParseBint(\"407753744390571945061605037371969762406335\"),\n\tmustParseBint(\"409434456222210068483046881306506648032409\"),\n\tmustParseBint(\"411087386417331124875138910342561474631568\"),\n\tmustParseBint(\"412713438504509155534639644600053377852544\"),\n\tmustParseBint(\"414313472639153268789584321728823113893207\"),\n\tmustParseBint(\"415888308335967185650339272874905940845300\"),\n\tmustParseBint(\"417438726989563711065424677479150624433087\"),\n\tmustParseBint(\"418965474202642554487442093634583157254470\"),\n\tmustParseBint(\"420469261939096605967007199636372275056693\"),\n\tmustParseBint(\"421950770517610669908399886078947967173920\"),\n\tmustParseBint(\"423410650459725938220199806873272182308987\"),\n\tmustParseBint(\"424849524204935898912334419812754393723819\"),\n\tmustParseBint(\"426267987704131542132945453251303409675958\"),\n\tmustParseBint(\"427666611901605531104218683821958111352148\"),\n\tmustParseBint(\"429045944114839112909210885743854257090475\"),\n\tmustParseBint(\"430406509320416975378532779248962373197558\"),\n\tmustParseBint(\"431748811353631044059676390337490098369869\"),\n\tmustParseBint(\"433073334028633107884349167480420667338838\"),\n\tmustParseBint(\"434380542185368384916729632140830902945879\"),\n\tmustParseBint(\"435670882668959173686596479994602087752826\"),\n\tmustParseBint(\"436944785246702149417294554148141092217354\"),\n\tmustParseBint(\"438202663467388161226968781905889391182760\"),\n\tmustParseBint(\"439444915467243876558098094769010281858996\"),\n\tmustParseBint(\"440671924726425311328399549449558415645191\"),\n\tmustParseBint(\"441884060779659792347547222329137045302931\"),\n\tmustParseBint(\"443081679884331361533506222328205857043558\"),\n\tmustParseBint(\"444265125649031645485029395109931417511380\"),\n\tmustParseBint(\"445434729625350773289007463480402360363464\"),\n\tmustParseBint(\"446590811865458371857851726928443731014200\"),\n\tmustParseBint(\"447733681447820647231363994233965900404821\"),\n\tmustParseBint(\"448863636973213983831781554066984921940466\"),\n\tmustParseBint(\"449980967033026506680848192852941561689608\"),\n\tmustParseBint(\"451085950651685004115884018500849833444235\"),\n\tmustParseBint(\"452178857704904030964121707472654925459338\"),\n\tmustParseBint(\"453259949315325593732440956146488291509743\"),\n\tmustParseBint(\"454329478227000389623818279123035027697155\"),\n\tmustParseBint(\"455387689160054083460978676511404117676298\"),\n\tmustParseBint(\"456434819146783623848140584421340854502499\"),\n\tmustParseBint(\"457471097850338282211672162170396171380891\"),\n\tmustParseBint(\"458496747867057191962793760834453602734967\"),\n\tmustParseBint(\"459511985013458992685243405181018070911669\"),\n}\n\n// bnlog10 is a cache of  multiples of the natural logarithm of 10, where bnlog10[x] = round(x * ln(10) * 10^41).\nvar bnlog10 = [...]*bint{\n\tmustParseBint(\"0\"),\n\tmustParseBint(\"230258509299404568401799145468436420760110\"),\n\tmustParseBint(\"460517018598809136803598290936872841520220\"),\n\tmustParseBint(\"690775527898213705205397436405309262280330\"),\n\tmustParseBint(\"921034037197618273607196581873745683040441\"),\n\tmustParseBint(\"1151292546497022842008995727342182103800551\"),\n\tmustParseBint(\"1381551055796427410410794872810618524560661\"),\n\tmustParseBint(\"1611809565095831978812594018279054945320771\"),\n\tmustParseBint(\"1842068074395236547214393163747491366080881\"),\n\tmustParseBint(\"2072326583694641115616192309215927786840991\"),\n\tmustParseBint(\"2302585092994045684017991454684364207601101\"),\n\tmustParseBint(\"2532843602293450252419790600152800628361212\"),\n\tmustParseBint(\"2763102111592854820821589745621237049121322\"),\n\tmustParseBint(\"2993360620892259389223388891089673469881432\"),\n\tmustParseBint(\"3223619130191663957625188036558109890641542\"),\n\tmustParseBint(\"3453877639491068526026987182026546311401652\"),\n\tmustParseBint(\"3684136148790473094428786327494982732161762\"),\n\tmustParseBint(\"3914394658089877662830585472963419152921873\"),\n\tmustParseBint(\"4144653167389282231232384618431855573681983\"),\n\tmustParseBint(\"4374911676688686799634183763900291994442093\"),\n\tmustParseBint(\"4605170185988091368035982909368728415202203\"),\n\tmustParseBint(\"4835428695287495936437782054837164835962313\"),\n\tmustParseBint(\"5065687204586900504839581200305601256722423\"),\n\tmustParseBint(\"5295945713886305073241380345774037677482533\"),\n\tmustParseBint(\"5526204223185709641643179491242474098242644\"),\n\tmustParseBint(\"5756462732485114210044978636710910519002754\"),\n\tmustParseBint(\"5986721241784518778446777782179346939762864\"),\n\tmustParseBint(\"6216979751083923346848576927647783360522974\"),\n\tmustParseBint(\"6447238260383327915250376073116219781283084\"),\n\tmustParseBint(\"6677496769682732483652175218584656202043194\"),\n\tmustParseBint(\"6907755278982137052053974364053092622803304\"),\n\tmustParseBint(\"7138013788281541620455773509521529043563415\"),\n\tmustParseBint(\"7368272297580946188857572654989965464323525\"),\n\tmustParseBint(\"7598530806880350757259371800458401885083635\"),\n\tmustParseBint(\"7828789316179755325661170945926838305843745\"),\n\tmustParseBint(\"8059047825479159894062970091395274726603855\"),\n\tmustParseBint(\"8289306334778564462464769236863711147363965\"),\n\tmustParseBint(\"8519564844077969030866568382332147568124076\"),\n\tmustParseBint(\"8749823353377373599268367527800583988884186\"),\n\tmustParseBint(\"8980081862676778167670166673269020409644296\"),\n\tmustParseBint(\"9210340371976182736071965818737456830404406\"),\n\tmustParseBint(\"9440598881275587304473764964205893251164516\"),\n\tmustParseBint(\"9670857390574991872875564109674329671924626\"),\n\tmustParseBint(\"9901115899874396441277363255142766092684736\"),\n\tmustParseBint(\"10131374409173801009679162400611202513444847\"),\n\tmustParseBint(\"10361632918473205578080961546079638934204957\"),\n\tmustParseBint(\"10591891427772610146482760691548075354965067\"),\n\tmustParseBint(\"10822149937072014714884559837016511775725177\"),\n\tmustParseBint(\"11052408446371419283286358982484948196485287\"),\n\tmustParseBint(\"11282666955670823851688158127953384617245397\"),\n\tmustParseBint(\"11512925464970228420089957273421821038005507\"),\n\tmustParseBint(\"11743183974269632988491756418890257458765618\"),\n\tmustParseBint(\"11973442483569037556893555564358693879525728\"),\n\tmustParseBint(\"12203700992868442125295354709827130300285838\"),\n\tmustParseBint(\"12433959502167846693697153855295566721045948\"),\n\tmustParseBint(\"12664218011467251262098953000764003141806058\"),\n\tmustParseBint(\"12894476520766655830500752146232439562566168\"),\n\tmustParseBint(\"13124735030066060398902551291700875983326278\"),\n\tmustParseBint(\"13354993539365464967304350437169312404086389\"),\n\tmustParseBint(\"13585252048664869535706149582637748824846499\"),\n\tmustParseBint(\"13815510557964274104107948728106185245606609\"),\n\tmustParseBint(\"14045769067263678672509747873574621666366719\"),\n\tmustParseBint(\"14276027576563083240911547019043058087126829\"),\n\tmustParseBint(\"14506286085862487809313346164511494507886939\"),\n\tmustParseBint(\"14736544595161892377715145309979930928647050\"),\n\tmustParseBint(\"14966803104461296946116944455448367349407160\"),\n\tmustParseBint(\"15197061613760701514518743600916803770167270\"),\n\tmustParseBint(\"15427320123060106082920542746385240190927380\"),\n\tmustParseBint(\"15657578632359510651322341891853676611687490\"),\n\tmustParseBint(\"15887837141658915219724141037322113032447600\"),\n\tmustParseBint(\"16118095650958319788125940182790549453207710\"),\n\tmustParseBint(\"16348354160257724356527739328258985873967821\"),\n\tmustParseBint(\"16578612669557128924929538473727422294727931\"),\n\tmustParseBint(\"16808871178856533493331337619195858715488041\"),\n\tmustParseBint(\"17039129688155938061733136764664295136248151\"),\n\tmustParseBint(\"17269388197455342630134935910132731557008261\"),\n\tmustParseBint(\"17499646706754747198536735055601167977768371\"),\n\tmustParseBint(\"17729905216054151766938534201069604398528481\"),\n\tmustParseBint(\"17960163725353556335340333346538040819288592\"),\n\tmustParseBint(\"18190422234652960903742132492006477240048702\"),\n\tmustParseBint(\"18420680743952365472143931637474913660808812\"),\n\tmustParseBint(\"18650939253251770040545730782943350081568922\"),\n\tmustParseBint(\"18881197762551174608947529928411786502329032\"),\n\tmustParseBint(\"19111456271850579177349329073880222923089142\"),\n\tmustParseBint(\"19341714781149983745751128219348659343849253\"),\n\tmustParseBint(\"19571973290449388314152927364817095764609363\"),\n\tmustParseBint(\"19802231799748792882554726510285532185369473\"),\n\tmustParseBint(\"20032490309048197450956525655753968606129583\"),\n\tmustParseBint(\"20262748818347602019358324801222405026889693\"),\n\tmustParseBint(\"20493007327647006587760123946690841447649803\"),\n\tmustParseBint(\"20723265836946411156161923092159277868409913\"),\n\tmustParseBint(\"20953524346245815724563722237627714289170024\"),\n\tmustParseBint(\"21183782855545220292965521383096150709930134\"),\n\tmustParseBint(\"21414041364844624861367320528564587130690244\"),\n\tmustParseBint(\"21644299874144029429769119674033023551450354\"),\n\tmustParseBint(\"21874558383443433998170918819501459972210464\"),\n\tmustParseBint(\"22104816892742838566572717964969896392970574\"),\n\tmustParseBint(\"22335075402042243134974517110438332813730684\"),\n\tmustParseBint(\"22565333911341647703376316255906769234490795\"),\n\tmustParseBint(\"22795592420641052271778115401375205655250905\"),\n}\n\n// mustParseBint converts a string to *big.Int, panicking on error.\n// Use only for package variable initialization and test code!\nfunc mustParseBint(s string) *bint {\n\tz, ok := new(big.Int).SetString(s, 10)\n\tif !ok {\n\t\tpanic(fmt.Errorf(\"mustParseBint(%q) failed: parsing error\", s))\n\t}\n\tif z.Sign() < 0 {\n\t\tpanic(fmt.Errorf(\"mustParseBint(%q) failed: negative number\", s))\n\t}\n\treturn (*bint)(z)\n}\n\nfunc (z *bint) sign() int {\n\treturn (*big.Int)(z).Sign()\n}\n\nfunc (z *bint) cmp(x *bint) int {\n\treturn (*big.Int)(z).Cmp((*big.Int)(x))\n}\n\nfunc (z *bint) string() string {\n\treturn (*big.Int)(z).String()\n}\n\nfunc (z *bint) setBint(x *bint) {\n\t(*big.Int)(z).Set((*big.Int)(x))\n}\n\nfunc (z *bint) setInt64(x int64) {\n\t(*big.Int)(z).SetInt64(x)\n}\n\nfunc (z *bint) setBytes(buf []byte) {\n\t(*big.Int)(z).SetBytes(buf)\n}\n\nfunc (z *bint) setFint(x fint) {\n\t(*big.Int)(z).SetUint64(uint64(x))\n}\n\n// fint converts *big.Int to uint64.\n// If z cannot be represented as uint64, the result is undefined.\nfunc (z *bint) fint() fint {\n\tf := (*big.Int)(z).Uint64()\n\treturn fint(f)\n}\n\n// add calculates z = x + y.\nfunc (z *bint) add(x, y *bint) {\n\t(*big.Int)(z).Add((*big.Int)(x), (*big.Int)(y))\n}\n\n// inc calcualtes z = x + 1.\nfunc (z *bint) inc(x *bint) {\n\ty := bpow10[0]\n\tz.add(x, y)\n}\n\n// sub calculates z = x - y.\nfunc (z *bint) sub(x, y *bint) {\n\t(*big.Int)(z).Sub((*big.Int)(x), (*big.Int)(y))\n}\n\n// subAbs calculates z = |x - y|.\nfunc (z *bint) subAbs(x, y *bint) {\n\tswitch x.cmp(y) {\n\tcase 1:\n\t\tz.sub(x, y)\n\tdefault:\n\t\tz.sub(y, x)\n\t}\n}\n\n// dbl (Double) calculates z = x * 2.\nfunc (z *bint) dbl(x *bint) {\n\t(*big.Int)(z).Lsh((*big.Int)(x), 1)\n}\n\n// hlf (Half) calculates z = ⌊x / 2⌋.\nfunc (z *bint) hlf(x *bint) {\n\t(*big.Int)(z).Rsh((*big.Int)(x), 1)\n}\n\n// mul calculates z = x * y.\nfunc (z *bint) mul(x, y *bint) {\n\t// Copying x, y to prevent heap allocations.\n\tif z == x {\n\t\tb := getBint()\n\t\tdefer putBint(b)\n\t\tb.setBint(x)\n\t\tx = b\n\t}\n\tif z == y {\n\t\tb := getBint()\n\t\tdefer putBint(b)\n\t\tb.setBint(y)\n\t\ty = b\n\t}\n\t(*big.Int)(z).Mul((*big.Int)(x), (*big.Int)(y))\n}\n\n// pow calculates z = x^y.\n// If y is negative, the result is unpredictable.\nfunc (z *bint) pow(x, y *bint) {\n\t(*big.Int)(z).Exp((*big.Int)(x), (*big.Int)(y), nil)\n}\n\n// pow10 calculates z = 10^power.\n// If power is negative, the result is unpredictable.\nfunc (z *bint) pow10(power int) {\n\tx := getBint()\n\tdefer putBint(x)\n\tx.setInt64(10)\n\ty := getBint()\n\tdefer putBint(y)\n\ty.setInt64(int64(power))\n\tz.pow(x, y)\n}\n\n// quo calculates z = ⌊x / y⌋.\nfunc (z *bint) quo(x, y *bint) {\n\t// Passing r to prevent heap allocations.\n\tr := getBint()\n\tdefer putBint(r)\n\tz.quoRem(x, y, r)\n}\n\n// quoRem calculates z = ⌊x / y⌋, r = x - y * z.\nfunc (z *bint) quoRem(x, y, r *bint) {\n\t(*big.Int)(z).QuoRem((*big.Int)(x), (*big.Int)(y), (*big.Int)(r))\n}\n\nfunc (z *bint) isOdd() bool {\n\treturn (*big.Int)(z).Bit(0) != 0\n}\n\n// lsh (Left Shift) calculates z = x * 10^shift.\nfunc (z *bint) lsh(x *bint, shift int) {\n\tvar y *bint\n\tif shift < len(bpow10) {\n\t\ty = bpow10[shift]\n\t} else {\n\t\ty = getBint()\n\t\tdefer putBint(y)\n\t\ty.pow10(shift)\n\t}\n\tz.mul(x, y)\n}\n\n// fsa (Fused Shift and Addition) calculates z = x * 10^shift + f.\nfunc (z *bint) fsa(x *bint, shift int, f fint) {\n\ty := getBint()\n\tdefer putBint(y)\n\ty.setFint(f)\n\tz.lsh(x, shift)\n\tz.add(z, y)\n}\n\n// rshDown (Right Shift) calculates z = ⌊x / 10^shift⌋ and rounds\n// result towards zero.\nfunc (z *bint) rshDown(x *bint, shift int) {\n\t// Special cases\n\tswitch {\n\tcase x.sign() == 0:\n\t\tz.setFint(0)\n\t\treturn\n\tcase shift <= 0:\n\t\tz.setBint(x)\n\t\treturn\n\t}\n\t// General case\n\tvar y *bint\n\tif shift < len(bpow10) {\n\t\ty = bpow10[shift]\n\t} else {\n\t\ty = getBint()\n\t\tdefer putBint(y)\n\t\ty.pow10(shift)\n\t}\n\tz.quo(x, y)\n}\n\n// rshHalfEven (Right Shift) calculates z = round(x / 10^shift) and\n// rounds result using \"half to even\" rule.\nfunc (z *bint) rshHalfEven(x *bint, shift int) {\n\t// Special cases\n\tswitch {\n\tcase x.sign() == 0:\n\t\tz.setFint(0)\n\t\treturn\n\tcase shift <= 0:\n\t\tz.setBint(x)\n\t\treturn\n\t}\n\t// General case\n\tvar y, r *bint\n\tr = getBint()\n\tdefer putBint(r)\n\tif shift < len(bpow10) {\n\t\ty = bpow10[shift]\n\t} else {\n\t\ty = getBint()\n\t\tdefer putBint(y)\n\t\ty.pow10(shift)\n\t}\n\tz.quoRem(x, y, r)\n\tr.dbl(r) // r = r * 2\n\tswitch y.cmp(r) {\n\tcase -1:\n\t\tz.inc(z) // z = z + 1\n\tcase 0:\n\t\t// half-to-even\n\t\tif z.isOdd() {\n\t\t\tz.inc(z) // z = z + 1\n\t\t}\n\t}\n}\n\n// prec returns length of z in decimal digits.\n// prec assumes that 0 has no digits.\n// If z is negative, the result is unpredictable.\n//\n// z.prec() is significantly faster than len(z.string()),\n// if z has less than len(bpow10) digits.\nfunc (z *bint) prec() int {\n\t// Special case\n\tif z.cmp(bpow10[len(bpow10)-1]) > 0 {\n\t\treturn len(z.string())\n\t}\n\t// General case\n\tleft, right := 0, len(bpow10)\n\tfor left < right {\n\t\tmid := (left + right) / 2\n\t\tif z.cmp(bpow10[mid]) < 0 {\n\t\t\tright = mid\n\t\t} else {\n\t\t\tleft = mid + 1\n\t\t}\n\t}\n\treturn left\n}\n\n// hasPrec checks if z has a given number of digits or more.\n// hasPrec assumes that 0 has no digits.\n// If z is negative, the result is unpredictable.\n//\n// z.hasPrec(p) is significantly faster than z.prec() >= p,\n// if z has no more than len(bpow10) digits.\nfunc (z *bint) hasPrec(prec int) bool {\n\t// Special cases\n\tswitch {\n\tcase prec < 1:\n\t\treturn true\n\tcase prec > len(bpow10):\n\t\treturn len(z.string()) >= prec\n\t}\n\t// General case\n\treturn z.cmp(bpow10[prec-1]) >= 0\n}\n\n// bpool is a cache of reusable *big.Int instances.\nvar bpool = sync.Pool{\n\tNew: func() any {\n\t\treturn (*bint)(new(big.Int))\n\t},\n}\n\n// getBint obtains a *big.Int from the pool.\nfunc getBint() *bint {\n\treturn bpool.Get().(*bint)\n}\n\n// putBint returns the *big.Int into the pool.\nfunc putBint(b *bint) {\n\tbpool.Put(b)\n}\n"
  },
  {
    "path": "integer_test.go",
    "content": "package decimal\n\nimport (\n\t\"math\"\n\t\"testing\"\n)\n\nfunc TestFint_add(t *testing.T) {\n\tcases := []struct {\n\t\tx, y, wantCoef fint\n\t\twantOk         bool\n\t}{\n\t\t{0, 0, 0, true},\n\t\t{maxFint, 1, 0, false},\n\t}\n\tfor _, tt := range cases {\n\t\tx, y := tt.x, tt.y\n\t\tgotCoef, gotOk := x.add(y)\n\t\tif gotCoef != tt.wantCoef || gotOk != tt.wantOk {\n\t\t\tt.Errorf(\"%v.add(%v) = %v, %v, want %v, %v\", x, y, gotCoef, gotOk, tt.wantCoef, tt.wantOk)\n\t\t}\n\t}\n}\n\nfunc TestFint_mul(t *testing.T) {\n\tcases := []struct {\n\t\tx, y, wantCoef fint\n\t\twantOk         bool\n\t}{\n\t\t{0, 0, 0, true},\n\t\t{10, 10, 100, true},\n\t\t{maxFint, 2, 0, false},\n\t}\n\tfor _, tt := range cases {\n\t\tx, y := tt.x, tt.y\n\t\tgotCoef, gotOk := x.mul(y)\n\t\tif gotCoef != tt.wantCoef || gotOk != tt.wantOk {\n\t\t\tt.Errorf(\"%v.mul(%v) = %v, %v, want %v, %v\", x, y, gotCoef, gotOk, tt.wantCoef, tt.wantOk)\n\t\t}\n\t}\n}\n\nfunc TestFint_quo(t *testing.T) {\n\tcases := []struct {\n\t\tx, y, wantCoef fint\n\t\twantOk         bool\n\t}{\n\t\t{1, 0, 0, false},\n\t\t{1, 1, 1, true},\n\t\t{2, 4, 0, false},\n\t\t{20, 4, 5, true},\n\t\t{20, 3, 0, false},\n\t\t{maxFint, 2, 0, false},\n\t}\n\tfor _, tt := range cases {\n\t\tx, y := tt.x, tt.y\n\t\tgotCoef, gotOk := x.quo(y)\n\t\tif gotCoef != tt.wantCoef || gotOk != tt.wantOk {\n\t\t\tt.Errorf(\"%v.quo(%v) = %v, %v, want %v, %v\", x, y, gotCoef, gotOk, tt.wantCoef, tt.wantOk)\n\t\t}\n\t}\n}\n\nfunc TestFint_quoRem(t *testing.T) {\n\tcases := []struct {\n\t\tx, y, wantQuo, wantRem fint\n\t\twantOk                 bool\n\t}{\n\t\t{1, 0, 0, 0, false},\n\t\t{1, 1, 1, 0, true},\n\t\t{2, 4, 0, 2, true},\n\t\t{20, 4, 5, 0, true},\n\t\t{20, 3, 6, 2, true},\n\t\t{maxFint, 2, maxFint / 2, 1, true},\n\t}\n\tfor _, tt := range cases {\n\t\tx, y := tt.x, tt.y\n\t\tgotQuo, gotRem, gotOk := x.quoRem(y)\n\t\tif gotQuo != tt.wantQuo || gotRem != tt.wantRem || gotOk != tt.wantOk {\n\t\t\tt.Errorf(\"%v.quoRem(%v) = %v, %v, %v, want %v, %v, %v\", x, y, gotQuo, gotRem, gotOk, tt.wantQuo, tt.wantRem, tt.wantOk)\n\t\t}\n\t}\n}\n\nfunc TestFint_subAbs(t *testing.T) {\n\tcases := []struct {\n\t\tx, y, wantCoef fint\n\t}{\n\t\t{1, 0, 1},\n\t\t{1, 1, 0},\n\t\t{2, 4, 2},\n\t\t{20, 4, 16},\n\t\t{20, 3, 17},\n\t\t{maxFint, 2, 9_999_999_999_999_999_997},\n\t\t{maxFint, 1, 9_999_999_999_999_999_998},\n\t\t{maxFint, 0, maxFint},\n\t}\n\tfor _, tt := range cases {\n\t\tx, y := tt.x, tt.y\n\t\tgotCoef := x.subAbs(y)\n\t\tif gotCoef != tt.wantCoef {\n\t\t\tt.Errorf(\"%v.subAbs(%v) = %v, want %v\", x, y, gotCoef, tt.wantCoef)\n\t\t}\n\t}\n}\n\nfunc TestFint_lsh(t *testing.T) {\n\tcases := []struct {\n\t\tx        fint\n\t\tshift    int\n\t\twantCoef fint\n\t\twantOk   bool\n\t}{\n\t\t{0, 0, 0, true},\n\t\t{10, 0, 10, true},\n\t\t{0, 1, 0, true},\n\t\t{10, 1, 100, true},\n\t\t{1, 20, 0, false},\n\t}\n\tfor _, tt := range cases {\n\t\tx := tt.x\n\t\tgotCoef, gotOk := x.lsh(tt.shift)\n\t\tif gotCoef != tt.wantCoef || gotOk != tt.wantOk {\n\t\t\tt.Errorf(\"%v.lsh(%v) = %v, %v, want %v, %v\", x, tt.shift, gotCoef, gotOk, tt.wantCoef, tt.wantOk)\n\t\t}\n\t}\n}\n\nfunc TestFint_fsa(t *testing.T) {\n\tcases := []struct {\n\t\tx        fint\n\t\tshift    int\n\t\ty        byte\n\t\twantCoef fint\n\t\twantOk   bool\n\t}{\n\t\t{0, 0, 0, 0, true},\n\t\t{1, 1, 1, 11, true},\n\t\t{2, 2, 2, 202, true},\n\t\t{3, 3, 3, 3_003, true},\n\t\t{1, 20, 0, 0, false},\n\t\t{maxFint, 0, 1, 0, false},\n\t}\n\tfor _, tt := range cases {\n\t\tx, y, shift := tt.x, tt.y, tt.shift\n\t\tgotCoef, gotOk := x.fsa(shift, y)\n\t\tif gotCoef != tt.wantCoef || gotOk != tt.wantOk {\n\t\t\tt.Errorf(\"%v.fsa(%v, %v) = %v, %v, want %v, %v\", x, shift, y, gotCoef, gotOk, tt.wantCoef, tt.wantOk)\n\t\t}\n\t}\n}\n\nfunc TestFint_rshHalfEven(t *testing.T) {\n\tcases := []struct {\n\t\tx     fint\n\t\tshift int\n\t\twant  fint\n\t}{\n\t\t// Negative shift\n\t\t{1, -1, 1},\n\n\t\t// Rounding\n\t\t{1, 0, 1},\n\t\t{20, 1, 2},\n\t\t{18, 1, 2},\n\t\t{15, 1, 2},\n\t\t{12, 1, 1},\n\t\t{10, 1, 1},\n\t\t{8, 1, 1},\n\t\t{5, 1, 0},\n\t\t{2, 1, 0},\n\t\t{maxFint, 19, 1},\n\n\t\t// Large shifts\n\t\t{0, 17, 0},\n\t\t{0, 18, 0},\n\t\t{0, 19, 0},\n\t\t{0, 20, 0},\n\t\t{0, 21, 0},\n\n\t\t{1, 17, 0},\n\t\t{1, 18, 0},\n\t\t{1, 19, 0},\n\t\t{1, 20, 0},\n\t\t{1, 21, 0},\n\n\t\t{5_000_000_000_000_000_000, 17, 50},\n\t\t{5_000_000_000_000_000_000, 18, 5},\n\t\t{5_000_000_000_000_000_000, 19, 0},\n\t\t{5_000_000_000_000_000_000, 20, 0},\n\t\t{5_000_000_000_000_000_000, 21, 0},\n\n\t\t{5_000_000_000_000_000_001, 17, 50},\n\t\t{5_000_000_000_000_000_001, 18, 5},\n\t\t{5_000_000_000_000_000_001, 19, 1},\n\t\t{5_000_000_000_000_000_001, 20, 0},\n\t\t{5_000_000_000_000_000_001, 21, 0},\n\n\t\t{maxFint, 17, 100},\n\t\t{maxFint, 18, 10},\n\t\t{maxFint, 19, 1},\n\t\t{maxFint, 20, 0},\n\t\t{maxFint, 21, 0},\n\n\t\t{10_000_000_000_000_000_000, 17, 100},\n\t\t{10_000_000_000_000_000_000, 18, 10},\n\t\t{10_000_000_000_000_000_000, 19, 1},\n\t\t{10_000_000_000_000_000_000, 20, 0},\n\t\t{10_000_000_000_000_000_000, 21, 0},\n\n\t\t{14_999_999_999_999_999_999, 17, 150},\n\t\t{14_999_999_999_999_999_999, 18, 15},\n\t\t{14_999_999_999_999_999_999, 19, 1},\n\t\t{14_999_999_999_999_999_999, 20, 0},\n\t\t{14_999_999_999_999_999_999, 21, 0},\n\n\t\t{15_000_000_000_000_000_000, 17, 150},\n\t\t{15_000_000_000_000_000_000, 18, 15},\n\t\t{15_000_000_000_000_000_000, 19, 2},\n\t\t{15_000_000_000_000_000_000, 20, 0},\n\t\t{15_000_000_000_000_000_000, 21, 0},\n\n\t\t{math.MaxUint64, 17, 184},\n\t\t{math.MaxUint64, 18, 18},\n\t\t{math.MaxUint64, 19, 2},\n\t\t{math.MaxUint64, 20, 0},\n\t\t{math.MaxUint64, 21, 0},\n\t}\n\tfor _, tt := range cases {\n\t\tgot := tt.x.rshHalfEven(tt.shift)\n\t\tif got != tt.want {\n\t\t\tt.Errorf(\"%v.rshHalfEven(%v) = %v, want %v\", tt.x, tt.shift, got, tt.want)\n\t\t}\n\t}\n}\n\nfunc TestFint_rshUp(t *testing.T) {\n\tcases := []struct {\n\t\tx     fint\n\t\tshift int\n\t\twant  fint\n\t}{\n\t\t// Negative shift\n\t\t{1, -1, 1},\n\n\t\t// Rounding\n\t\t{20, 1, 2},\n\t\t{18, 1, 2},\n\t\t{15, 1, 2},\n\t\t{12, 1, 2},\n\t\t{10, 1, 1},\n\t\t{8, 1, 1},\n\t\t{5, 1, 1},\n\t\t{2, 1, 1},\n\n\t\t// Large shifts\n\t\t{0, 17, 0},\n\t\t{0, 18, 0},\n\t\t{0, 19, 0},\n\t\t{0, 20, 0},\n\t\t{0, 21, 0},\n\n\t\t{1, 17, 1},\n\t\t{1, 18, 1},\n\t\t{1, 19, 1},\n\t\t{1, 20, 1},\n\t\t{1, 21, 1},\n\n\t\t{maxFint, 17, 100},\n\t\t{maxFint, 18, 10},\n\t\t{maxFint, 19, 1},\n\t\t{maxFint, 20, 1},\n\t\t{maxFint, 21, 1},\n\n\t\t{10_000_000_000_000_000_000, 17, 100},\n\t\t{10_000_000_000_000_000_000, 18, 10},\n\t\t{10_000_000_000_000_000_000, 19, 1},\n\t\t{10_000_000_000_000_000_000, 20, 1},\n\t\t{10_000_000_000_000_000_000, 21, 1},\n\n\t\t{math.MaxUint64, 17, 185},\n\t\t{math.MaxUint64, 18, 19},\n\t\t{math.MaxUint64, 19, 2},\n\t\t{math.MaxUint64, 20, 1},\n\t\t{math.MaxUint64, 21, 1},\n\t}\n\tfor _, tt := range cases {\n\t\tgot := tt.x.rshUp(tt.shift)\n\t\tif got != tt.want {\n\t\t\tt.Errorf(\"%v.rshUp(%v) = %v, want %v\", tt.x, tt.shift, got, tt.want)\n\t\t}\n\t}\n}\n\nfunc TestFint_rshDown(t *testing.T) {\n\tcases := []struct {\n\t\tx     fint\n\t\tshift int\n\t\twant  fint\n\t}{\n\t\t// Negative shift\n\t\t{1, -1, 1},\n\t\t// Rounding\n\t\t{1, 0, 1},\n\t\t{20, 1, 2},\n\t\t{18, 1, 1},\n\t\t{15, 1, 1},\n\t\t{12, 1, 1},\n\t\t{10, 1, 1},\n\t\t{8, 1, 0},\n\t\t{5, 1, 0},\n\t\t{2, 1, 0},\n\n\t\t// Large shifts\n\t\t{0, 17, 0},\n\t\t{0, 18, 0},\n\t\t{0, 19, 0},\n\t\t{0, 20, 0},\n\t\t{0, 21, 0},\n\n\t\t{1, 17, 0},\n\t\t{1, 18, 0},\n\t\t{1, 19, 0},\n\t\t{1, 20, 0},\n\t\t{1, 21, 0},\n\n\t\t{maxFint, 17, 99},\n\t\t{maxFint, 18, 9},\n\t\t{maxFint, 19, 0},\n\t\t{maxFint, 20, 0},\n\t\t{maxFint, 21, 0},\n\n\t\t{10_000_000_000_000_000_000, 17, 100},\n\t\t{10_000_000_000_000_000_000, 18, 10},\n\t\t{10_000_000_000_000_000_000, 19, 1},\n\t\t{10_000_000_000_000_000_000, 20, 0},\n\t\t{10_000_000_000_000_000_000, 21, 0},\n\n\t\t{math.MaxUint64, 17, 184},\n\t\t{math.MaxUint64, 18, 18},\n\t\t{math.MaxUint64, 19, 1},\n\t\t{math.MaxUint64, 20, 0},\n\t\t{math.MaxUint64, 21, 0},\n\t}\n\tfor _, tt := range cases {\n\t\tgot := tt.x.rshDown(tt.shift)\n\t\tif got != tt.want {\n\t\t\tt.Errorf(\"%v.rshDown(%v) = %v, want %v\", tt.x, tt.shift, got, tt.want)\n\t\t}\n\t}\n}\n\nfunc TestFint_prec(t *testing.T) {\n\tcases := []struct {\n\t\tx    fint\n\t\twant int\n\t}{\n\t\t{0, 0},\n\t\t{1, 1},\n\t\t{9, 1},\n\t\t{10, 2},\n\t\t{99, 2},\n\t\t{100, 3},\n\t\t{999, 3},\n\t\t{1_000, 4},\n\t\t{9_999, 4},\n\t\t{10_000, 5},\n\t\t{99_999, 5},\n\t\t{100_000, 6},\n\t\t{999_999, 6},\n\t\t{1_000_000, 7},\n\t\t{9_999_999, 7},\n\t\t{10_000_000, 8},\n\t\t{99_999_999, 8},\n\t\t{100_000_000, 9},\n\t\t{999_999_999, 9},\n\t\t{1_000_000_000, 10},\n\t\t{9_999_999_999, 10},\n\t\t{10_000_000_000, 11},\n\t\t{99_999_999_999, 11},\n\t\t{100_000_000_000, 12},\n\t\t{999_999_999_999, 12},\n\t\t{1_000_000_000_000, 13},\n\t\t{9_999_999_999_999, 13},\n\t\t{10_000_000_000_000, 14},\n\t\t{99_999_999_999_999, 14},\n\t\t{100_000_000_000_000, 15},\n\t\t{999_999_999_999_999, 15},\n\t\t{1_000_000_000_000_000, 16},\n\t\t{9_999_999_999_999_999, 16},\n\t\t{10_000_000_000_000_000, 17},\n\t\t{99_999_999_999_999_999, 17},\n\t\t{100_000_000_000_000_000, 18},\n\t\t{999_999_999_999_999_999, 18},\n\t\t{1_000_000_000_000_000_000, 19},\n\t\t{maxFint, 19},\n\t\t{10_000_000_000_000_000_000, 20},\n\t\t{math.MaxUint64, 20},\n\t}\n\tfor _, tt := range cases {\n\t\tgot := tt.x.prec()\n\t\tif got != tt.want {\n\t\t\tt.Errorf(\"%v.prec() = %v, want %v\", tt.x, got, tt.want)\n\t\t}\n\t}\n}\n\nfunc TestFint_ntz(t *testing.T) {\n\tcases := []struct {\n\t\tx    fint\n\t\twant int\n\t}{\n\t\t{0, 0},\n\t\t{1, 0},\n\t\t{9, 0},\n\t\t{10, 1},\n\t\t{99, 0},\n\t\t{100, 2},\n\t\t{999, 0},\n\t\t{1_000, 3},\n\t\t{9_999, 0},\n\t\t{10_000, 4},\n\t\t{99_999, 0},\n\t\t{100_000, 5},\n\t\t{999_999, 0},\n\t\t{1_000_000, 6},\n\t\t{9_999_999, 0},\n\t\t{10_000_000, 7},\n\t\t{99_999_999, 0},\n\t\t{100_000_000, 8},\n\t\t{999_999_999, 0},\n\t\t{1_000_000_000, 9},\n\t\t{9_999_999_999, 0},\n\t\t{10_000_000_000, 10},\n\t\t{99_999_999_999, 0},\n\t\t{100_000_000_000, 11},\n\t\t{999_999_999_999, 0},\n\t\t{1_000_000_000_000, 12},\n\t\t{9_999_999_999_999, 0},\n\t\t{10_000_000_000_000, 13},\n\t\t{99_999_999_999_999, 0},\n\t\t{100_000_000_000_000, 14},\n\t\t{999_999_999_999_999, 0},\n\t\t{1_000_000_000_000_000, 15},\n\t\t{9_999_999_999_999_999, 0},\n\t\t{10_000_000_000_000_000, 16},\n\t\t{99_999_999_999_999_999, 0},\n\t\t{100_000_000_000_000_000, 17},\n\t\t{999_999_999_999_999_999, 0},\n\t\t{1_000_000_000_000_000_000, 18},\n\t\t{1_000_000_000_000_000_001, 0},\n\t\t{maxFint, 0},\n\t\t{10_000_000_000_000_000_000, 19},\n\t\t{math.MaxUint64, 0},\n\t}\n\tfor _, tt := range cases {\n\t\tgot := tt.x.ntz()\n\t\tif got != tt.want {\n\t\t\tt.Errorf(\"%v.ntz() = %v, want %v\", tt.x, got, tt.want)\n\t\t}\n\t}\n}\n\nfunc TestFint_hasPrec(t *testing.T) {\n\tcases := []struct {\n\t\tx    fint\n\t\tprec int\n\t\twant bool\n\t}{\n\t\t{0, 0, true},\n\t\t{0, 1, false},\n\t\t{0, 2, false},\n\n\t\t{1, 0, true},\n\t\t{1, 1, true},\n\t\t{1, 2, false},\n\n\t\t{9, 0, true},\n\t\t{9, 1, true},\n\t\t{9, 2, false},\n\n\t\t{10, 0, true},\n\t\t{10, 1, true},\n\t\t{10, 2, true},\n\t\t{10, 3, false},\n\n\t\t{99, 0, true},\n\t\t{99, 1, true},\n\t\t{99, 2, true},\n\t\t{99, 3, false},\n\n\t\t{100_000_000_000_000, 17, false},\n\t\t{1_000_000_000_000_000, 17, false},\n\t\t{10_000_000_000_000_000, 17, true},\n\t\t{100_000_000_000_000_000, 17, true},\n\t\t{1_000_000_000_000_000_000, 17, true},\n\n\t\t{1_000_000_000_000_000_000, 17, true},\n\t\t{1_000_000_000_000_000_000, 18, true},\n\t\t{1_000_000_000_000_000_000, 19, true},\n\t\t{1_000_000_000_000_000_000, 20, false},\n\t\t{1_000_000_000_000_000_000, 21, false},\n\n\t\t{maxFint, 17, true},\n\t\t{maxFint, 18, true},\n\t\t{maxFint, 19, true},\n\t\t{maxFint, 20, false},\n\t\t{maxFint, 21, false},\n\n\t\t{10_000_000_000_000_000_000, 17, true},\n\t\t{10_000_000_000_000_000_000, 18, true},\n\t\t{10_000_000_000_000_000_000, 19, true},\n\t\t{10_000_000_000_000_000_000, 20, true},\n\t\t{10_000_000_000_000_000_000, 21, false},\n\n\t\t{math.MaxUint64, 17, true},\n\t\t{math.MaxUint64, 18, true},\n\t\t{math.MaxUint64, 19, true},\n\t\t{math.MaxUint64, 20, true},\n\t\t{math.MaxUint64, 21, false},\n\t}\n\tfor _, tt := range cases {\n\t\tgot := tt.x.hasPrec(tt.prec)\n\t\tif got != tt.want {\n\t\t\tt.Errorf(\"%v.hasPrec(%v) = %v, want %v\", tt.x, tt.prec, got, tt.want)\n\t\t}\n\t}\n}\n\nfunc TestBint_rshDown(t *testing.T) {\n\tcases := []struct {\n\t\tz     string\n\t\tshift int\n\t\twant  string\n\t}{\n\t\t// Rounding\n\t\t{\"1\", 0, \"1\"},\n\t\t{\"20\", 1, \"2\"},\n\t\t{\"18\", 1, \"1\"},\n\t\t{\"15\", 1, \"1\"},\n\t\t{\"12\", 1, \"1\"},\n\t\t{\"10\", 1, \"1\"},\n\t\t{\"8\", 1, \"0\"},\n\t\t{\"5\", 1, \"0\"},\n\t\t{\"2\", 1, \"0\"},\n\t\t{\"9999999999999999999\", 19, \"0\"},\n\t\t{\"9999999999999999999\", 100, \"0\"},\n\n\t\t// Large shifts\n\t\t{\"0\", 17, \"0\"},\n\t\t{\"0\", 18, \"0\"},\n\t\t{\"0\", 19, \"0\"},\n\t\t{\"0\", 20, \"0\"},\n\t\t{\"0\", 21, \"0\"},\n\n\t\t{\"1\", 17, \"0\"},\n\t\t{\"1\", 18, \"0\"},\n\t\t{\"1\", 19, \"0\"},\n\t\t{\"1\", 20, \"0\"},\n\t\t{\"1\", 21, \"0\"},\n\n\t\t{\"5000000000000000000\", 17, \"50\"},\n\t\t{\"5000000000000000000\", 18, \"5\"},\n\t\t{\"5000000000000000000\", 19, \"0\"},\n\t\t{\"5000000000000000000\", 20, \"0\"},\n\t\t{\"5000000000000000000\", 21, \"0\"},\n\n\t\t{\"5000000000000000001\", 17, \"50\"},\n\t\t{\"5000000000000000001\", 18, \"5\"},\n\t\t{\"5000000000000000001\", 19, \"0\"},\n\t\t{\"5000000000000000001\", 20, \"0\"},\n\t\t{\"5000000000000000001\", 21, \"0\"},\n\n\t\t{\"9999999999999999999\", 17, \"99\"},\n\t\t{\"9999999999999999999\", 18, \"9\"},\n\t\t{\"9999999999999999999\", 19, \"0\"},\n\t\t{\"9999999999999999999\", 20, \"0\"},\n\t\t{\"9999999999999999999\", 21, \"0\"},\n\n\t\t{\"10000000000000000000\", 17, \"100\"},\n\t\t{\"10000000000000000000\", 18, \"10\"},\n\t\t{\"10000000000000000000\", 19, \"1\"},\n\t\t{\"10000000000000000000\", 20, \"0\"},\n\t\t{\"10000000000000000000\", 21, \"0\"},\n\n\t\t{\"14999999999999999999\", 17, \"149\"},\n\t\t{\"14999999999999999999\", 18, \"14\"},\n\t\t{\"14999999999999999999\", 19, \"1\"},\n\t\t{\"14999999999999999999\", 20, \"0\"},\n\t\t{\"14999999999999999999\", 21, \"0\"},\n\n\t\t{\"15000000000000000000\", 17, \"150\"},\n\t\t{\"15000000000000000000\", 18, \"15\"},\n\t\t{\"15000000000000000000\", 19, \"1\"},\n\t\t{\"15000000000000000000\", 20, \"0\"},\n\t\t{\"15000000000000000000\", 21, \"0\"},\n\n\t\t{\"18446744073709551615\", 17, \"184\"},\n\t\t{\"18446744073709551615\", 18, \"18\"},\n\t\t{\"18446744073709551615\", 19, \"1\"},\n\t\t{\"18446744073709551615\", 20, \"0\"},\n\t\t{\"18446744073709551615\", 21, \"0\"},\n\t}\n\tfor _, tt := range cases {\n\t\tgot := mustParseBint(tt.z)\n\t\tgot.rshDown(got, tt.shift)\n\t\twant := mustParseBint(tt.want)\n\t\tif got.cmp(want) != 0 {\n\t\t\tt.Errorf(\"%v.rshDown(%v) = %v, want %v\", tt.z, tt.shift, got, want)\n\t\t}\n\t}\n}\n\nfunc TestBint_rshHalfEven(t *testing.T) {\n\tcases := []struct {\n\t\tz     string\n\t\tshift int\n\t\twant  string\n\t}{\n\t\t// Rounding\n\t\t{\"1\", 0, \"1\"},\n\t\t{\"20\", 1, \"2\"},\n\t\t{\"18\", 1, \"2\"},\n\t\t{\"15\", 1, \"2\"},\n\t\t{\"12\", 1, \"1\"},\n\t\t{\"10\", 1, \"1\"},\n\t\t{\"8\", 1, \"1\"},\n\t\t{\"5\", 1, \"0\"},\n\t\t{\"2\", 1, \"0\"},\n\t\t{\"9999999999999999999\", 19, \"1\"},\n\t\t{\"9999999999999999999\", 100, \"0\"},\n\n\t\t// Large shifts\n\t\t{\"0\", 17, \"0\"},\n\t\t{\"0\", 18, \"0\"},\n\t\t{\"0\", 19, \"0\"},\n\t\t{\"0\", 20, \"0\"},\n\t\t{\"0\", 21, \"0\"},\n\n\t\t{\"1\", 17, \"0\"},\n\t\t{\"1\", 18, \"0\"},\n\t\t{\"1\", 19, \"0\"},\n\t\t{\"1\", 20, \"0\"},\n\t\t{\"1\", 21, \"0\"},\n\n\t\t{\"5000000000000000000\", 17, \"50\"},\n\t\t{\"5000000000000000000\", 18, \"5\"},\n\t\t{\"5000000000000000000\", 19, \"0\"},\n\t\t{\"5000000000000000000\", 20, \"0\"},\n\t\t{\"5000000000000000000\", 21, \"0\"},\n\n\t\t{\"5000000000000000001\", 17, \"50\"},\n\t\t{\"5000000000000000001\", 18, \"5\"},\n\t\t{\"5000000000000000001\", 19, \"1\"},\n\t\t{\"5000000000000000001\", 20, \"0\"},\n\t\t{\"5000000000000000001\", 21, \"0\"},\n\n\t\t{\"9999999999999999999\", 17, \"100\"},\n\t\t{\"9999999999999999999\", 18, \"10\"},\n\t\t{\"9999999999999999999\", 19, \"1\"},\n\t\t{\"9999999999999999999\", 20, \"0\"},\n\t\t{\"9999999999999999999\", 21, \"0\"},\n\n\t\t{\"10000000000000000000\", 17, \"100\"},\n\t\t{\"10000000000000000000\", 18, \"10\"},\n\t\t{\"10000000000000000000\", 19, \"1\"},\n\t\t{\"10000000000000000000\", 20, \"0\"},\n\t\t{\"10000000000000000000\", 21, \"0\"},\n\n\t\t{\"14999999999999999999\", 17, \"150\"},\n\t\t{\"14999999999999999999\", 18, \"15\"},\n\t\t{\"14999999999999999999\", 19, \"1\"},\n\t\t{\"14999999999999999999\", 20, \"0\"},\n\t\t{\"14999999999999999999\", 21, \"0\"},\n\n\t\t{\"15000000000000000000\", 17, \"150\"},\n\t\t{\"15000000000000000000\", 18, \"15\"},\n\t\t{\"15000000000000000000\", 19, \"2\"},\n\t\t{\"15000000000000000000\", 20, \"0\"},\n\t\t{\"15000000000000000000\", 21, \"0\"},\n\n\t\t{\"18446744073709551615\", 17, \"184\"},\n\t\t{\"18446744073709551615\", 18, \"18\"},\n\t\t{\"18446744073709551615\", 19, \"2\"},\n\t\t{\"18446744073709551615\", 20, \"0\"},\n\t\t{\"18446744073709551615\", 21, \"0\"},\n\t}\n\tfor _, tt := range cases {\n\t\tgot := mustParseBint(tt.z)\n\t\tgot.rshHalfEven(got, tt.shift)\n\t\twant := mustParseBint(tt.want)\n\t\tif got.cmp(want) != 0 {\n\t\t\tt.Errorf(\"%v.rshHalfEven(%v) = %v, want %v\", tt.z, tt.shift, got, want)\n\t\t}\n\t}\n}\n\nfunc TestBint_lsh(t *testing.T) {\n\tcases := []struct {\n\t\tz     string\n\t\tshift int\n\t\twant  string\n\t}{\n\t\t{\"0\", 1, \"0\"},\n\t\t{\"1\", 1, \"10\"},\n\t\t{\"1\", 20, \"100000000000000000000\"},\n\t\t{\"1\", 100, \"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"},\n\t}\n\tfor _, tt := range cases {\n\t\tgot := mustParseBint(tt.z)\n\t\tgot.lsh(got, tt.shift)\n\t\twant := mustParseBint(tt.want)\n\t\tif got.cmp(want) != 0 {\n\t\t\tt.Errorf(\"%v.lsh(%v) = %v, want %v\", tt.z, tt.shift, got, want)\n\t\t}\n\t}\n}\n\nfunc TestBint_prec(t *testing.T) {\n\tcases := []struct {\n\t\tz    string\n\t\twant int\n\t}{\n\t\t{\"0\", 0},\n\t\t{\"1\", 1},\n\t\t{\"9\", 1},\n\t\t{\"10\", 2},\n\t\t{\"99\", 2},\n\t\t{\"100\", 3},\n\t\t{\"999\", 3},\n\t\t{\"1000\", 4},\n\t\t{\"9999\", 4},\n\t\t{\"10000\", 5},\n\t\t{\"99999\", 5},\n\t\t{\"100000\", 6},\n\t\t{\"999999\", 6},\n\t\t{\"1000000\", 7},\n\t\t{\"9999999\", 7},\n\t\t{\"10000000\", 8},\n\t\t{\"99999999\", 8},\n\t\t{\"100000000\", 9},\n\t\t{\"999999999\", 9},\n\t\t{\"1000000000\", 10},\n\t\t{\"9999999999\", 10},\n\t\t{\"10000000000\", 11},\n\t\t{\"99999999999\", 11},\n\t\t{\"100000000000\", 12},\n\t\t{\"999999999999\", 12},\n\t\t{\"1000000000000\", 13},\n\t\t{\"9999999999999\", 13},\n\t\t{\"10000000000000\", 14},\n\t\t{\"99999999999999\", 14},\n\t\t{\"100000000000000\", 15},\n\t\t{\"999999999999999\", 15},\n\t\t{\"1000000000000000\", 16},\n\t\t{\"9999999999999999\", 16},\n\t\t{\"10000000000000000\", 17},\n\t\t{\"99999999999999999\", 17},\n\t\t{\"100000000000000000\", 18},\n\t\t{\"999999999999999999\", 18},\n\t\t{\"1000000000000000000\", 19},\n\t\t{\"9999999999999999999\", 19},\n\t\t{\"10000000000000000000\", 20},\n\t\t{\"99999999999999999999\", 20},\n\t\t{\"100000000000000000000\", 21},\n\t\t{\"999999999999999999999\", 21},\n\t\t{\"1000000000000000000000\", 22},\n\t\t{\"9999999999999999999999\", 22},\n\t\t{\"10000000000000000000000\", 23},\n\t\t{\"99999999999999999999999\", 23},\n\t\t{\"100000000000000000000000\", 24},\n\t\t{\"999999999999999999999999\", 24},\n\t\t{\"1000000000000000000000000\", 25},\n\t\t{\"9999999999999999999999999\", 25},\n\t\t{\"10000000000000000000000000\", 26},\n\t\t{\"99999999999999999999999999\", 26},\n\t\t{\"100000000000000000000000000\", 27},\n\t\t{\"999999999999999999999999999\", 27},\n\t\t{\"1000000000000000000000000000\", 28},\n\t\t{\"9999999999999999999999999999\", 28},\n\t\t{\"10000000000000000000000000000\", 29},\n\t\t{\"99999999999999999999999999999\", 29},\n\t\t{\"100000000000000000000000000000\", 30},\n\t\t{\"999999999999999999999999999999\", 30},\n\t\t{\"1000000000000000000000000000000\", 31},\n\t\t{\"9999999999999999999999999999999\", 31},\n\t\t{\"10000000000000000000000000000000\", 32},\n\t\t{\"99999999999999999999999999999999\", 32},\n\t\t{\"100000000000000000000000000000000\", 33},\n\t\t{\"999999999999999999999999999999999\", 33},\n\t\t{\"1000000000000000000000000000000000\", 34},\n\t\t{\"9999999999999999999999999999999999\", 34},\n\t\t{\"10000000000000000000000000000000000\", 35},\n\t\t{\"99999999999999999999999999999999999\", 35},\n\t\t{\"100000000000000000000000000000000000\", 36},\n\t\t{\"999999999999999999999999999999999999\", 36},\n\t\t{\"1000000000000000000000000000000000000\", 37},\n\t\t{\"9999999999999999999999999999999999999\", 37},\n\t\t{\"10000000000000000000000000000000000000\", 38},\n\t\t{\"99999999999999999999999999999999999999\", 38},\n\t\t{\"100000000000000000000000000000000000000\", 39},\n\t\t{\"999999999999999999999999999999999999999\", 39},\n\t\t{\"1000000000000000000000000000000000000000\", 40},\n\t\t{\"9999999999999999999999999999999999999999\", 40},\n\t\t{\"10000000000000000000000000000000000000000\", 41},\n\t\t{\"99999999999999999999999999999999999999999\", 41},\n\t\t{\"100000000000000000000000000000000000000000\", 42},\n\t\t{\"999999999999999999999999999999999999999999\", 42},\n\t\t{\"1000000000000000000000000000000000000000000\", 43},\n\t\t{\"9999999999999999999999999999999999999999999\", 43},\n\t\t{\"10000000000000000000000000000000000000000000\", 44},\n\t\t{\"99999999999999999999999999999999999999999999\", 44},\n\t\t{\"100000000000000000000000000000000000000000000\", 45},\n\t\t{\"999999999999999999999999999999999999999999999\", 45},\n\t\t{\"1000000000000000000000000000000000000000000000\", 46},\n\t\t{\"9999999999999999999999999999999999999999999999\", 46},\n\t\t{\"10000000000000000000000000000000000000000000000\", 47},\n\t\t{\"99999999999999999999999999999999999999999999999\", 47},\n\t\t{\"100000000000000000000000000000000000000000000000\", 48},\n\t\t{\"999999999999999999999999999999999999999999999999\", 48},\n\t\t{\"1000000000000000000000000000000000000000000000000\", 49},\n\t\t{\"9999999999999999999999999999999999999999999999999\", 49},\n\t\t{\"10000000000000000000000000000000000000000000000000\", 50},\n\t\t{\"99999999999999999999999999999999999999999999999999\", 50},\n\t\t{\"100000000000000000000000000000000000000000000000000\", 51},\n\t\t{\"999999999999999999999999999999999999999999999999999\", 51},\n\t\t{\"1000000000000000000000000000000000000000000000000000\", 52},\n\t\t{\"9999999999999999999999999999999999999999999999999999\", 52},\n\t\t{\"10000000000000000000000000000000000000000000000000000\", 53},\n\t\t{\"99999999999999999999999999999999999999999999999999999\", 53},\n\t\t{\"100000000000000000000000000000000000000000000000000000\", 54},\n\t\t{\"999999999999999999999999999999999999999999999999999999\", 54},\n\t\t{\"1000000000000000000000000000000000000000000000000000000\", 55},\n\t\t{\"9999999999999999999999999999999999999999999999999999999\", 55},\n\t\t{\"10000000000000000000000000000000000000000000000000000000\", 56},\n\t\t{\"99999999999999999999999999999999999999999999999999999999\", 56},\n\t\t{\"100000000000000000000000000000000000000000000000000000000\", 57},\n\t\t{\"999999999999999999999999999999999999999999999999999999999\", 57},\n\t\t{\"1000000000000000000000000000000000000000000000000000000000\", 58},\n\t\t{\"9999999999999999999999999999999999999999999999999999999999\", 58},\n\t\t{\"10000000000000000000000000000000000000000000000000000000000\", 59},\n\t\t{\"99999999999999999999999999999999999999999999999999999999999\", 59},\n\t\t{\"100000000000000000000000000000000000000000000000000000000000\", 60},\n\t\t{\"999999999999999999999999999999999999999999999999999999999999\", 60},\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000\", 61},\n\t\t{\"9999999999999999999999999999999999999999999999999999999999999\", 61},\n\t\t{\"10000000000000000000000000000000000000000000000000000000000000\", 62},\n\t\t{\"99999999999999999999999999999999999999999999999999999999999999\", 62},\n\t\t{\"100000000000000000000000000000000000000000000000000000000000000\", 63},\n\t\t{\"999999999999999999999999999999999999999999999999999999999999999\", 63},\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000000\", 64},\n\t\t{\"9999999999999999999999999999999999999999999999999999999999999999\", 64},\n\t\t{\"10000000000000000000000000000000000000000000000000000000000000000\", 65},\n\t\t{\"99999999999999999999999999999999999999999999999999999999999999999\", 65},\n\t\t{\"100000000000000000000000000000000000000000000000000000000000000000\", 66},\n\t\t{\"999999999999999999999999999999999999999999999999999999999999999999\", 66},\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000000000\", 67},\n\t\t{\"9999999999999999999999999999999999999999999999999999999999999999999\", 67},\n\t\t{\"10000000000000000000000000000000000000000000000000000000000000000000\", 68},\n\t\t{\"99999999999999999999999999999999999999999999999999999999999999999999\", 68},\n\t\t{\"100000000000000000000000000000000000000000000000000000000000000000000\", 69},\n\t\t{\"999999999999999999999999999999999999999999999999999999999999999999999\", 69},\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000000000000\", 70},\n\t\t{\"9999999999999999999999999999999999999999999999999999999999999999999999\", 70},\n\t\t{\"10000000000000000000000000000000000000000000000000000000000000000000000\", 71},\n\t\t{\"99999999999999999999999999999999999999999999999999999999999999999999999\", 71},\n\t\t{\"100000000000000000000000000000000000000000000000000000000000000000000000\", 72},\n\t\t{\"999999999999999999999999999999999999999999999999999999999999999999999999\", 72},\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000000000000000\", 73},\n\t\t{\"9999999999999999999999999999999999999999999999999999999999999999999999999\", 73},\n\t\t{\"10000000000000000000000000000000000000000000000000000000000000000000000000\", 74},\n\t\t{\"99999999999999999999999999999999999999999999999999999999999999999999999999\", 74},\n\t\t{\"100000000000000000000000000000000000000000000000000000000000000000000000000\", 75},\n\t\t{\"999999999999999999999999999999999999999999999999999999999999999999999999999\", 75},\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000000000000000000\", 76},\n\t\t{\"9999999999999999999999999999999999999999999999999999999999999999999999999999\", 76},\n\t\t{\"10000000000000000000000000000000000000000000000000000000000000000000000000000\", 77},\n\t\t{\"99999999999999999999999999999999999999999999999999999999999999999999999999999\", 77},\n\t\t{\"100000000000000000000000000000000000000000000000000000000000000000000000000000\", 78},\n\t\t{\"999999999999999999999999999999999999999999999999999999999999999999999999999999\", 78},\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000000000000000000000\", 79},\n\t\t{\"9999999999999999999999999999999999999999999999999999999999999999999999999999999\", 79},\n\t\t{\"10000000000000000000000000000000000000000000000000000000000000000000000000000000\", 80},\n\t\t{\"99999999999999999999999999999999999999999999999999999999999999999999999999999999\", 80},\n\t\t{\"100000000000000000000000000000000000000000000000000000000000000000000000000000000\", 81},\n\t\t{\"999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 81},\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 82},\n\t\t{\"9999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 82},\n\t\t{\"10000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 83},\n\t\t{\"99999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 83},\n\t\t{\"100000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 84},\n\t\t{\"999999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 84},\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 85},\n\t\t{\"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 85},\n\t\t{\"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 86},\n\t\t{\"99999999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 86},\n\t\t{\"100000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 87},\n\t\t{\"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 87},\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 88},\n\t\t{\"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 88},\n\t\t{\"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 89},\n\t\t{\"99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 89},\n\t\t{\"100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 90},\n\t\t{\"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 90},\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 91},\n\t\t{\"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 91},\n\t\t{\"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 92},\n\t\t{\"99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 92},\n\t\t{\"100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 93},\n\t\t{\"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 93},\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 94},\n\t\t{\"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 94},\n\t\t{\"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 95},\n\t\t{\"99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 95},\n\t\t{\"100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 96},\n\t\t{\"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 96},\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 97},\n\t\t{\"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 97},\n\t\t{\"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 98},\n\t\t{\"99999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 98},\n\t\t{\"100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 99},\n\t\t{\"999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 99},\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 100},\n\t\t{\"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\", 100},\n\t\t{\"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 101},\n\t}\n\tfor _, tt := range cases {\n\t\tz := mustParseBint(tt.z)\n\t\tgot := z.prec()\n\t\tif got != tt.want {\n\t\t\tt.Errorf(\"%q.prec() = %v, want %v\", tt.z, got, tt.want)\n\t\t}\n\t}\n}\n\nfunc TestBint_hasPrec(t *testing.T) {\n\tcases := []struct {\n\t\tz    string\n\t\tprec int\n\t\twant bool\n\t}{\n\t\t{\"0\", -1, true},\n\t\t{\"0\", 0, true},\n\t\t{\"0\", 1, false},\n\t\t{\"1\", 0, true},\n\t\t{\"1\", 1, true},\n\t\t{\"1\", 2, false},\n\t\t{\"10\", 1, true},\n\t\t{\"10\", 2, true},\n\t\t{\"10\", 3, false},\n\n\t\t{\"100000000000000000\", 19, false},  // 18 digits\n\t\t{\"1000000000000000000\", 19, true},  // 19 digits\n\t\t{\"10000000000000000000\", 19, true}, // 20 digits\n\n\t\t{\"1000000000000000000\", 18, true},  // 19 digits\n\t\t{\"1000000000000000000\", 19, true},  // 19 digits\n\t\t{\"1000000000000000000\", 20, false}, // 19 digits\n\n\t\t{\"100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 100, false},  // 99 digits\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 100, true},  // 100 digits\n\t\t{\"10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 100, true}, // 101 digits\n\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 99, true},   // 100 digits\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 100, true},  // 100 digits\n\t\t{\"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\", 101, false}, // 100 digits\n\t}\n\tfor _, tt := range cases {\n\t\tz := mustParseBint(tt.z)\n\t\tgot := z.hasPrec(tt.prec)\n\t\tif got != tt.want {\n\t\t\tt.Errorf(\"%v.hasPrec(%v) = %v, want %v\", tt.z, tt.prec, got, tt.want)\n\t\t}\n\t}\n}\n"
  }
]