Bug or what?
- Hello, This is my serious problem: (In Visual Studio 2005 Fwrk 2 and Visual C# 2008 Express Fwrk 3.5)
For example:
double myvar = 0.78+1.33;
myvar = 2.1100000000000003
instead:
myvar = 2.11
And in my project, I can't use round function, and I don't want use float, because I need ALL decimals...
Saludos!
Réponses
- Computers represent everything using binary. For decimal, use the Decimal type. Try Wikipedia for clarification of binary arimethic.
- Marqué comme réponseRudedog2Modérateurmercredi 11 novembre 2009 14:02
- Hi,
That's because machine use binary to store data.
double is store in:
1bit for sign
11 bits for Exponent
52 bits for Mantissa
double 0.78 in memory is :
3f e8 f5 c2 8f 5c 28 f6
0[011 1111 1110 ] [1000 1111 0101 1100 0010 1000 1111 ........
+ 127-1=126 Mantissa is -1 1.000111101011100001010001111......
0.110001111......
0.5+0.25+0.15625+....=approximately 0.78 ,so there is rounding error and relative error in memory .
For more information , please see What every computer scientist should know about floating-point arithmetic
Harry
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marqué comme réponseRudedog2Modérateurmercredi 11 novembre 2009 14:02
Toutes les réponses
- Computers represent everything using binary. For decimal, use the Decimal type. Try Wikipedia for clarification of binary arimethic.
- Marqué comme réponseRudedog2Modérateurmercredi 11 novembre 2009 14:02
- Hi,
That's because machine use binary to store data.
double is store in:
1bit for sign
11 bits for Exponent
52 bits for Mantissa
double 0.78 in memory is :
3f e8 f5 c2 8f 5c 28 f6
0[011 1111 1110 ] [1000 1111 0101 1100 0010 1000 1111 ........
+ 127-1=126 Mantissa is -1 1.000111101011100001010001111......
0.110001111......
0.5+0.25+0.15625+....=approximately 0.78 ,so there is rounding error and relative error in memory .
For more information , please see What every computer scientist should know about floating-point arithmetic
Harry
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marqué comme réponseRudedog2Modérateurmercredi 11 novembre 2009 14:02
Computers represent everything using binary. For decimal, use the Decimal type. Try Wikipedia for clarification of binary arimethic.
Ok, but how I use, Math library of C#, if it returns double values type... Is there an alternative to this library that works in decimal?
Which functions do you need to call in the Math library?
There's a few overloaded methods.
Mark the best replies as answers. "Fooling computers since 1971."- Trigonometrics, Logarithmics, Sqrt, etc. Thanks for your time!!
- This is my application, enjoy it! sorry by the language... ;)
Resolve ecuations like this for example:
-50+(20+10)-10*8E-13+54^2*(12-5)+cos5-sen84+Ln(23)
http://rapidshare.com/files/305665135/Calculadora.rar.html - This is my application, enjoy it! sorry by the language... ;)
Resolve ecuations like this for example:
-50+(20+10)-10*8E-13+54^2*(12-5)+cos5-sen84+Ln(23)
http://rapidshare.com/files/305665135/Calculadora.rar.html - Since it is scientific math, you'll want to use doubles. Format your answers as you feel is necessary.

