Click here to Skip to main content
15,889,876 members
Home / Discussions / C#
   

C#

 
AnswerRe: can floats be multiplied and come up with a fraction? Pin
Richard MacCutchan26-Feb-13 6:26
mveRichard MacCutchan26-Feb-13 6:26 
AnswerRe: can floats be multiplied and come up with a fraction? Pin
notahack26-Feb-13 6:35
notahack26-Feb-13 6:35 
GeneralRe: can floats be multiplied and come up with a fraction? Pin
Richard Deeming26-Feb-13 7:39
mveRichard Deeming26-Feb-13 7:39 
GeneralRe: can floats be multiplied and come up with a fraction? Pin
notahack26-Feb-13 7:44
notahack26-Feb-13 7:44 
GeneralRe: can floats be multiplied and come up with a fraction? Pin
Richard Deeming26-Feb-13 8:03
mveRichard Deeming26-Feb-13 8:03 
GeneralRe: can floats be multiplied and come up with a fraction? Pin
notahack26-Feb-13 8:13
notahack26-Feb-13 8:13 
GeneralRe: can floats be multiplied and come up with a fraction? Pin
Dave Kreskowiak26-Feb-13 9:03
mveDave Kreskowiak26-Feb-13 9:03 
GeneralRe: can floats be multiplied and come up with a fraction? Pin
Dave Kreskowiak26-Feb-13 8:58
mveDave Kreskowiak26-Feb-13 8:58 
Yes, but a type like float cannot represent all of the numbers in that range since there are an infinite number of them!

How it works is there are a finite number of bits (32 in this case) to store a floating point value, split into 3 seections. The first bit is the sign bit. The next 8 bits are the exponent value and the remaining 23 bits are the fraction value. This gives you a sum total of 7 digits of numeric representation.

What does that mean? Well, if you want to represent a very large number, the format sacrifices accuracy by rounding off the least significant digits of the fraction value and increasing the value of the exponent to scale the fractional part of the number to the appropriate range.

decimal 10 = 0000001 * 10 ^ 1     (10 ^ 1) = 10
                ^           ^
                |           |
            fraction     exponent


decimal 1234567 = 12D687 * 10 ^ 0     (10 ^ 0) = 1
           1234567 can be represented by 21 bits: 1 0010 1101 0110 1000 0111
           so it fits inside the 23 bits available for the fraction part.

decimal 12345678 = ??????
            Hmmmm...  This requires 24 bits to represent: 1011 1100 0110 0001 0100 1110
            This won't fit inside the 23 bit fraction part!

            What to do, what to do, .... ??

The answer to this little problem is simple. Sacrifice a little precision and use scientific notation! Divide the number by 10 (remember what the exponent is raising) and round it off! This gives us 1234567.8 = 1234568.0. Now, we've got a 7 digit number that fits inside 23 bits. But there's that pesky division we did. Since we divided by 10, we have to raise the value of the exponent to compensate: 10 ^ 1. Now our number looks like this: 1234568.0 * 10 ^ 1, or 1.234568 * 10 ^ 7.

That's the quick'n'grossly simplified version of what's going on. For more read this[^]


modified 26-Feb-13 15:17pm.

QuestionC# EF5 List<ENum> Persisting ? Pin
Khorne26-Feb-13 4:01
Khorne26-Feb-13 4:01 
AnswerRe: C# EF5 List<ENum> Persisting ? Pin
Ssyxz26-Feb-13 15:14
Ssyxz26-Feb-13 15:14 
GeneralRe: C# EF5 List<ENum> Persisting ? Pin
Khorne26-Feb-13 20:41
Khorne26-Feb-13 20:41 
AnswerRe: C# EF5 List<ENum> Persisting ? Pin
Jegan Thiyagesan27-Feb-13 6:42
Jegan Thiyagesan27-Feb-13 6:42 
QuestionNeed code Pin
jelintaric25-Feb-13 22:41
jelintaric25-Feb-13 22:41 
AnswerRe: Need code Pin
Manfred Rudolf Bihy25-Feb-13 23:06
professionalManfred Rudolf Bihy25-Feb-13 23:06 
AnswerRe: Need code Pin
Mycroft Holmes25-Feb-13 23:43
professionalMycroft Holmes25-Feb-13 23:43 
AnswerRe: Need code Pin
Amir Mohammad Nasrollahi29-Jul-13 21:33
professionalAmir Mohammad Nasrollahi29-Jul-13 21:33 
Questionformatting issue with iTextSharp Pin
krishnapnv25-Feb-13 19:10
krishnapnv25-Feb-13 19:10 
QuestionRe: formatting issue with iTextSharp Pin
Richard MacCutchan25-Feb-13 21:55
mveRichard MacCutchan25-Feb-13 21:55 
AnswerRe: formatting issue with iTextSharp Pin
krishnapnv28-Feb-13 18:03
krishnapnv28-Feb-13 18:03 
Questionexport or save as pdf format Pin
abhishek91111925-Feb-13 17:50
abhishek91111925-Feb-13 17:50 
AnswerRe: export or save as pdf format Pin
Pete O'Hanlon25-Feb-13 20:02
mvePete O'Hanlon25-Feb-13 20:02 
AnswerRe: export or save as pdf format Pin
Abhinav S25-Feb-13 20:22
Abhinav S25-Feb-13 20:22 
QuestionChanging tabbed form over to tiled Pin
MichCl25-Feb-13 9:27
MichCl25-Feb-13 9:27 
AnswerRe: Changing tabbed form over to tiled Pin
Dave Kreskowiak25-Feb-13 9:33
mveDave Kreskowiak25-Feb-13 9:33 
GeneralRe: Changing tabbed form over to tiled Pin
MichCl26-Feb-13 9:16
MichCl26-Feb-13 9:16 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.