使用 C# 实现的 Ryu ,一个高性能浮点数转换为字符串的算法。
Ryu, implemented by C#, a high-performance algorithm for converting floats to strings.
- To avoid managed memory fragmentation, the implementation was changed from pointers to references. (The difference between pointer and reference is that the former is an unmanaged pointer and the latter is a managed pointer.)
- Inherit the open source license of the parent project to make it easier for everyone to use.
- fix bugs.
- Publish nuget package.
{// Arraychar[]charArray=newchar[32];// Need to ensure that the memory size is sufficient.varwrittenLength=Ryu.d2s_buffered_n(3.1415926D,refcharArray[0]);Console.WriteLine(newstring(charArray,0,writtenLength));// Output: 3.1415926E0}{// SpanSpan<char>charSpan=(newchar[32]).AsSpan();varwrittenLength=Ryu.d2s_buffered_n(3.1415926D,refcharSpan[0]);Console.WriteLine(charSpan.Slice(0,writtenLength).ToString());// Output: 3.1415926E0}{// Pointerchar*pChars=stackallocchar[32];Ryu.d2s_buffered(3.1415926D,ref*pChars);Console.WriteLine(newstring(pChars));// Output: 3.1415926E0}