Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any equivalent of "extended" for C#?

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.

like image 583
Bevan Avatar asked Sep 23 '12 01:09

Bevan


People also ask

What is long long in C?

Long long signed integer type. Capable of containing at least the [−9,223,372,036,854,775,807, +9,223,372,036,854,775,807] range. Specified since the C99 version of the standard.

What is C# extension?

Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are static methods, but they're called as if they were instance methods on the extended type.

What is the size of long int in C?

Long Integer Size The size is typically about 32-bits or 4 bytes on a 16/ 32-bit compiler.

What is double in C?

The double in C is a data type that is used to store high-precision floating-point data or numbers (up to 15 to 17 digits). It is used to store large values of decimal numbers. Values that are stored are double the size of data that can be stored in the float data type. Thus it is named a double data type.


1 Answers

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.

like image 146
jorel Avatar answered Oct 09 '22 17:10

jorel