10

(while trying to analyze how decimal works ) && after reading @jonskeet article and seeing msdn , and thinking for the last 4 hours , I have some questions :

in this link they say something very simple :

1.5 x 10^2 has 2 significant figures

1.50 x 10^2 has 3 significant figures.

1.500 x 10^2 has 4 significant figures etc...

ok...we get the idea.

from jon's article :

 sign * mantissa / 10^exponent 

As usual, the sign is just a single bit, but there are 96 bits of mantissa and 5 bits of exponent

 ^ _ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^___ ^^^^^ 1 _ 96 5 

ok

so max mantiss val = 2^96-1 = 79228162514264337593543950335 which is : 7.9228162514264*10^28 (according to my iphone... could'nt see exponent representation in windows calc.)

notice :

7.9228162514264*10^28 has 14 significant figures (according to examples above)

now the part with the 5 bit in exponent is irrelevant because its in the denominator - so i need the min val which is 2^0

question #1 :

msdn say : enter image description here 28-29 significant digits

but according to my sample (1.500 x 10^2 has 4 significant figures) they have 2 significant figures which is 7.9 ( 7 and 9).

if msdn would have written :

±79228162514264337593543950335 × 10^0 

i would understand this , since all significant digits are in the expression.

why do they write 28-29 but display 2 ?

question #2 :

how will decimal representation ( mantiss && exponent) will be displayed for the value 0.5 ?

the max denominator can be 2^32-1 --> 31

thanks guys.

question #3 :

1+96+5 = 102 bits.

msdn says :

The decimal keyword denotes a 128-bit data type.

128-102 = 26 

could understnad from article why there isnt a usage to those 26 bits

2 Answers 2

7

They've given the range to just two significant digits, but specified the precision separately. That's why the range is listed as "approximate range".

The decimal representation of 0.5 would be a mantissa of 5 and an exponent of 1 (which is treated in the inverse sense to normal, i.e. it's effectively -1).

Sign up to request clarification or add additional context in comments.

7 Comments

@RoyiNamir: No, the mantissa is 5. What made you think it's got anything to do with 2^5? I suspect you've misunderstood what a mantissa is.
oh sorry...:) after 4 hours of searching im thinking in base 2 :)
@RoyiNamir: The base is irrelevant though - you never raise a base to the power of a mantissa; that's what an exponent is for.
can i say that the precision ( decimal digits at the right to the point) is accurate within 28 digits ? so if i have 2 fractions of 28 decimals being added - the result will be accurate ? is it true to say ?
@RoyiNamir The decimal fraction's precision is accurate within a range of 2^96/10 providing the number is between 0 and 1.
|
3

why do they write 28-29 but display 2?

For readability. It says "Approximate range" and 7.9E28 is more readable than 79228162514264337593543950335 (E0 here, not E1).

how will decimal representation ( mantiss && exponent) will be displayed for the value 0.5 ?

The exponent's range is -28...0, however, it is stored (and received via constructor parameters) as an absolute value of 0...28.

So 0.5 Would have the same mantissa representation as 5 with an exponent of -1 (stored as 1).

7 Comments

You're getting confused between exponent and mantissa in the "if the exponent is 5 bits" part. Which exact bit of MSDN do you believe to be inaccurate?
a. The mantissa is 96bits, the exponent is 5 - where exactly did I confuse the two. b. "The scaling factor is implicitly the number 10, raised to an exponent ranging from 0 to 28." - There is no mention of negative exponents.
So the exponent doesn't have its own sign? - How do you know if you have to use E+n or E-n then?
(I was just in the middle of adding another comment, btw.) The exponent for decimal is always in the range 0-28, as specified in the documentation. It's then used in the inverse sense of a tradtional exponent, as documented (value = sign * mantissa / 10^exponent)
I still think your statement of "If the exponent is 5bits and is signed, then the full range is -2^31 .. 2^31 - 1" is extremely confused and/or confusing. I certainly don't know what you mean by it, despite having a pretty good understanding of decimal. Note that the range depends on the size of the mantissa as well as the exponent.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.