任何等同的“扩展”对于C#? [英] Any equivalent of "extended" for C#?

查看:129
本文介绍了任何等同的“扩展”对于C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发新版本的 Mandelbrot屏保,我正在运行浮点精度 - 简单的 double 值不足以满足我的需求。



更重要的数字=更大的缩放到分形的水平



当我在Delphi 7中编写这个屏幕保护程序的版本时,我使用了扩展浮点类型,大小为80位。



在.NET中,我可以切换到十进制,但是这样的性能命中是可怕的,将分形生成减慢了20倍左右。 / p>

.NET有哪些相当于扩展?或者,也可以选择具有比 double 更高精度的数字类型,仍然使用FPU进行评估,因此没有十进制的高性能命中? p>

更新



我的屏幕保护程序已经设法放大了许多分数(很多! )数量级目前,只有当使用的数字类型无法分离相邻像素的纵坐标时,才会将其重新设置为基本分形。从双重扩展的改进中,额外的16位精度将使我接近16倍的大小。



关于性能,我的算法已经设法消除95-需要99%的数学(与计算许多像素的天真的实现相比),同时保留分形的完整性。

解决方案


在64位平台上, Extended type是Double的别名,
只有8个字节。在32位平台上, Extended 号表示为10字节(80位)。


这意味着即使您的Delphi程序在64位平台上也可能无法正常运行。



如果您需要一个数字数据类型超过64位,那么去 decimal 并优化您的算法以提高性能。


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.

解决方案

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.

这篇关于任何等同的“扩展”对于C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆