5

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.

CodeMonkey1313
  • 15,717
  • 17
  • 76
  • 109

2 Answers2

3

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.

John Rasch
  • 62,489
  • 19
  • 106
  • 139
  • I wonder why `Decimal` uses floating point? A 128-bit fixed point type could guarantee that a+b-a will in all cases either yield b or throw an exception, but for `Decimal` that equality doesn't hold. – supercat Oct 14 '14 at 03:00
1

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.

Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186