Re: Decimal: fixed-point or floating-point

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 08/22/04


Date: Sun, 22 Aug 2004 18:58:37 +0100

Jay B. Harlow [MVP - Outlook] <Jay_Harlow_MVP@msn.com> wrote:
> I agree its confusing.
>
> I thought floating point numbers (Single/Double) have the entire number to
> the right of the decimal point (1.xyz) with an implied 1 where as fixed
> point (Decimal) has the entire number to the left of the decimal point
> (xyz.) (ala Integer).

No, floating-point just means that the location of the point is
specified by the value, whereas fixed-point means that the scaling
factor is specified by the type itself. For instance, you could have a
fixed-point representation which *always* has exactly two digits to the
right of the decimal point.

Indeed, this is how the Numeric type in SQL works - you specify the
scale and the precision of the number when defining the column, and you
always know how many decimal places there will be.

> For example the number 123 is:
>
> 1.23 E2 in (base 10) floating point, while its 123 E0 in decimal
>
> Basically its how the scale is represented.

That's just a bias though - work out how long the mantissa is, add or
subtract the appropriate number of powers, and there's no difference.

Imagine that all decimal numbers were of the form

0.xxx

and that the scaling factor is the same minus 28 or 29. That might
work. I think. Possibly they *are* fundamentally different - but I
think they're both *floating* point because the position of the point
is specified by the value rather than the type itself.

> I thought Decimal was Fixed point because the decimal point is all the way
> on the right just like Integer. Then that number is scaled.
>
> If that made any sense...

Binary floating point is exactly the same as that though - you take a
binary integer, optionally (depending on other things) add a leading 1,
and then scale it by an amount specified by the exponent part.

The Decimal type admittedly doesn't have the leading digit implied
(because it can't), but they're the same principal otherwise, just with
a different base and with different ranges of values. (Decimal also
doesn't have the various things like NaN, infinity, denormal/subnormal,
but that's a different matter.)

I could be wrong about some of this - I'm currently somewhat shattered
- but I *think* that's about right.

-- 
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Relevant Pages

  • Re: Float comparison
    ... the floating point object doesn't specify a range. ... to store a value, but only one value at a time. ... You just attempted to specify the programming. ...
    (comp.lang.c)
  • Re: Float comparison
    ... the floating point object doesn't specify a range. ... You just attempted to specify the programming. ... are having trouble understanding it. ...
    (comp.lang.c)
  • Re: Decimal: fixed-point or floating-point
    ... The reason I consider Single & Double floating point is the normalization ... point circle & the IEEE floating point circle, ... this is how the Numeric type in SQL works - you specify the ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Decimal: fixed-point or floating-point
    ... System.Double defines there to be 52 bits of mantissa, 11 bits of scale ... point rather than floating point. ... that quote to support this quote: ... you specify the scale when you create the instance - either ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Avoiding floating points
    ... "Add Fixed and Floating Decimal Point Numbers to Delphi" ... fraction numbers. ... And if you do allow for rounding the result into a ... then you need to specify or know what ...
    (borland.public.delphi.non-technical)