Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does decimal math use the FPU

Tags:

decimal

fpu

Does decimal math use the FPU?

I would think that the answer is yes, but I'm not sure, since a decimal is not a floating point, but a fixed precision number.

I'm looking mostly for .NET, but a general answer would be useful too.

like image 236
CodeMonkey1313 Avatar asked Oct 08 '22 18:10

CodeMonkey1313


2 Answers

With regards to .NET and more specifically C#, no, System.Decimal does not use the FPU because the type is emulated in software.

Also, System.Decimal is a floating point number, not a fixed precision number like commonly found in a database. The type is actually a decimal floating point that uses 10 for its base as opposed to a binary floating point (i.e. System.Single or System.Double) which uses 2 as its base. It still has the same precision problems if you attempt to store a fraction that cannot be exactly represented, for example, 1/3.

like image 193
John Rasch Avatar answered Oct 12 '22 11:10

John Rasch


Yes, modern languages in general support floating point math and integer math, and that's it; there's no direct support for fixed point, BCD, etc. Floating-point math is going to be done using floating-point processor instructions; modern architectures don't include a separate FPU.

like image 43
Ernest Friedman-Hill Avatar answered Oct 12 '22 12:10

Ernest Friedman-Hill