Re: Decimal: fixed-point or floating-point
From: Jon Skeet [C# MVP] (skeet_at_pobox.com)
Date: 08/22/04
- Next message: Jon Skeet [C# MVP]: "Re: Decimal: fixed-point or floating-point"
- Previous message: Jay B. Harlow [MVP - Outlook]: "Re: Decimal: fixed-point or floating-point"
- In reply to: Jay B. Harlow [MVP - Outlook]: "Re: Decimal: fixed-point or floating-point"
- Next in thread: Jay B. Harlow [MVP - Outlook]: "Re: Decimal: fixed-point or floating-point"
- Reply: Jay B. Harlow [MVP - Outlook]: "Re: Decimal: fixed-point or floating-point"
- Messages sorted by: [ date ] [ thread ]
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
- Next message: Jon Skeet [C# MVP]: "Re: Decimal: fixed-point or floating-point"
- Previous message: Jay B. Harlow [MVP - Outlook]: "Re: Decimal: fixed-point or floating-point"
- In reply to: Jay B. Harlow [MVP - Outlook]: "Re: Decimal: fixed-point or floating-point"
- Next in thread: Jay B. Harlow [MVP - Outlook]: "Re: Decimal: fixed-point or floating-point"
- Reply: Jay B. Harlow [MVP - Outlook]: "Re: Decimal: fixed-point or floating-point"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|