Replies: 1 comment 9 replies
-
Reiterating what I said in #74475, this is not something the BCL would be interested in providing. Having a type that takes a Providing non-standard or largely deprecated formats, such as the 80-bit "extended-precision" format provided by the x87 FPU, is a non-goal of the BCL. Adding more "custom" formats is likewise problematic and comes with many negative downsides. We may in the future provide an IEEE 754 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to propose a template solution to support IEEE 754 floating-point and decimal types in arbitrary size.
A implementation for floating-point already exists and can be tested: Generic.Float.cs.
(It is currently part of a project for arbitrary arithmetic in general that can be compiled for NET6 and NET7.)
The function set is identical to the system's other floating-point types and current NET7 naming conventions.
INumber
/IBinaryFloatingPointIeee754
is fully supported.For the user it is easy to use and to define number types in any desired precision:
Difference to the system types are only the constants implemented as static properties.
It's not all about to have floating-point for higher precision. It is also to support old and new special formats like Extended Float80 or to emulate the processors with specific internal precisision, rounding modes etc.
To make this easy the solution includes a
IFloat<T>
template that allows to implement new special number types based onFloat<T>
that inherit the base functionality inclusive all theINumber
interfaces.Examples for this can be found here: Generic.Types.cs
How it works
The template type definition is simple as possible.
The template parameter defines the struct size and the struct size the default IEEE 735 floating-point type and the binary layout:
Based on this principle, a set of number type templates are possible, which could stay in a namespace
System.Numerics.Generic
:(The implementation for
Decimal<T>
is already in work.)Internally, all template-based number types can use the same calculation core. Once initialized, this core does not require any further memory allocation at runtime. Since the number data is stored in the fixed size defined in the template, calculations with such number types can be performed without memory allocations. This is in contrast to other arbitrary number types such as BigInteger or BigRational, where dynamic buffers are required.
Beta Was this translation helpful? Give feedback.
All reactions