implemented ISignedNumber
.NET Test / .NET tests (push) Successful in 4m27s

This commit is contained in:
2026-09-13 23:08:27 +04:00
parent 082fd84c87
commit e51874b0c3
13 changed files with 1286 additions and 43 deletions
+33 -7
View File
@@ -63,6 +63,23 @@ has not been benchmarked, including the allocating exponent-boundary path.
0999; other standard and custom formats throw `FormatException`. Default
`G32` is **not** shortest-round-trip formatting. NaN, infinities, and signed
zero are supported without converting through decimal.
- `TryFormat(Span<char>, ...)` implements `ISpanFormattable` with the same formats.
It currently allocates via `ToString`; insufficient space returns `false`, writes
zero characters, and leaves the destination unchanged.
`DoubleDouble` implements `ISignedNumber<DoubleDouble>`, including the inherited
`INumberBase` contracts: binary radix, classification, absolute value, magnitude
selection, increment/decrement, and generic numeric conversions. Integer/parity
tests and magnitude comparisons retain both components. Magnitude ties prefer
positive values for maximum and negative values for minimum, including signed zero;
the `Number` variants prefer a number over NaN.
`CreateChecked`, `CreateSaturating`, and `CreateTruncating` support built-in numeric
types and `BigInteger`. Floating overflow produces signed infinity in all modes.
Finite integer output truncates the exact sum, then throws on overflow, clamps,
or retains the low destination-width bits, respectively. Decimal nonchecked output
clamps out-of-range values and maps NaN to zero. These policies are distinct from
the existing casts and `IConvertible` conversions above.
Conversions, parsing, and formatting use allocating `BigInteger` intermediates
where needed to preserve precision; no additional dependency is required.
@@ -87,16 +104,24 @@ bool success = DoubleDouble.TryParse("1.25e-2".AsSpan(), CultureInfo.InvariantCu
out DoubleDouble parsed);
```
- Supported grammar: optional sign, ASCII decimal digits with an optional decimal
- Provider-only finite grammar: optional sign, ASCII decimal digits with an optional decimal
separator, and optional `e`/`E` exponent with sign and digits. At least one
mantissa digit is required; `.5` and `1.` are accepted with invariant culture.
Surrounding whitespace is allowed; internal whitespace is not.
- Signs and the decimal separator come from the supplied culture; a null or
omitted provider uses the current culture. Culture-specific NaN and infinity
symbols are recognized case-insensitively. Signed zero is preserved.
- Group separators, currency, parentheses, hexadecimal notation, digit separators,
and `NumberStyles` overloads are not supported.
- Input is limited to **4096 characters**, including surrounding whitespace.
symbols are recognized case-insensitively. The additional alias `inf` accepts an
optional culture-specific sign (`inf`, `+inf`, `-inf` with invariant culture).
Exact custom special symbols take precedence over the alias. Special values accept
surrounding whitespace and signs even with `NumberStyles.None`; ordinary finite
numbers still obey the supplied style flags. Signed zero is preserved.
- Provider-only overloads reject grouping, currency, and parentheses. Explicit
`NumberStyles` overloads support decimal flags through `NumberStyles.Any`, including
grouping, currency, parentheses, and trailing signs; group sizes are not validated.
Hexadecimal, binary, and undefined style flags throw `ArgumentException`, including
in `TryParse`. Hexadecimal notation and programming-language digit separators
remain unsupported.
- Input is limited to **2048 characters**, including surrounding whitespace.
Huge exponents are bounded before constructing powers of ten. Well-formed
overflow succeeds with signed infinity; underflow rounds to a subnormal or
signed zero. A second rounding just below the overflow midpoint stays finite.
@@ -107,8 +132,9 @@ bool success = DoubleDouble.TryParse("1.25e-2".AsSpan(), CultureInfo.InvariantCu
## Deferred scope
The planned `PreciseMath` static class and its `Abs`, `Sqrt`, `Pow`, `Exp`, and
`Log` functions are not implemented. Broader generic-math interfaces, expanded
parsing/round-trip formatting, and performance benchmarks remain deferred.
`Log` functions are not implemented. Generic-math interfaces beyond `ISignedNumber`,
additional text formats/general round-trip formatting, and performance benchmarks
remain deferred.
Replacing allocating arithmetic boundary fallbacks is also deferred; the current
`BigInteger` paths remain in place. That optimization does not require removing
`BigInteger` from conversions, parsing, formatting, or independent test oracles.