Any equivalent of “extended” for C#?

纵然是瞬间 提交于 2020-01-03 08:39:26

问题


I'm working on a new version of my Mandelbrot screensaver and I'm running out of floating point accuracy - simple double values don't have enough significant figures for my needs.

More significant figures = greater levels of zooming into the fractal

Back when I wrote a version of this screensaver in Delphi 7, I used the extended floating point type, 80 bits in size.

In .NET, I could switch to decimal, but the performance hit for this is terrible, slowing down fractal generation by a factor of 20 or so.

Is there any equivalent of extended for .NET? Or, alternatively, are there any numeric types with higher precision than double that still use the FPU for evaluation and therefore don't have the high performance hit of decimal?

Update

My screensaver already manages to zoom into the fractal by many (many!) orders of magnitude; currently it resets to the base fractal only when the numeric type in use is unable to separate the ordinates for adjacent pixels. The extra 16 bits of precision from the double-extended improvement would give me close to 16 more doublings of size.

As to performance, my algorithm already manages to eliminate 95-99% of the math required (as compared to a naive implementation that calculates many pixels), while retaining the integrity of the fractal.


回答1:


On 64-bit platforms, the Extended type is an alias for Double, which is only 8 bytes. On 32-bit platforms, an Extended number is represented as 10 bytes (80 bits).

That means even your Delphi program may not perform well in 64bit platforms.

If you need a numeric data type with more than 64bits then go for decimal and optimize your algorithms to improve performance.



来源:https://stackoverflow.com/questions/12549000/any-equivalent-of-extended-for-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!