A new BigRational class - in short:
BigRat.cs (single file solution, just copy and try)
- No stack-machine, no nested classes.
- No static members, no shared buffers, no cache.
- No bad tricks, no hacks.
- Conforms to the .NET Framework Design Guidelines.
- Performance 30-50% less compared to stack-machine (only - currently).
- In assembly size ~28 KB.
- Tested for .NET 6, 7, 8 alpha, (ARM without INumber interfaces)
New approach:
- Using processor stack
stackalloc
instead of a stack-machine.
(This due to the observation that the performance breaks down to an unusable level long before stackalloc becomes critical.) - Normalization only on user request.
(This due to the observation that normalization often reduces the size less but cost performance) - Exceptions instead of
NaN
orInfinity
. (Makes not much sense to emulate floating-point behavior)
This as a first reference version. Major improvements/optimizations are possible. Of course, the stackallocs will be secured.