|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Floating Point Calculation ProblemHello,
In an application that worked fine until recently I have started to have problems with calculations involving two doubles. For example: -24.708 + 26.0 = 1.2920000000000016, however, -24.708 + 8.0 = -16.708. What would cause this? I don't think the numbers are so large that it would be the usual floating point calculation error because of rounding. How can I fix it? I'd rather not change every calcuation in my program to include a math.round... ..Net Framework 1.1 version 1.1.4322 SP1 Visual Basic - Visual Studio .Net 2003 Windows XP Thanks, The size of your numbers are not relevant to this issue.
Here is an URL with an article you should probably read if you wish to better understand this issue: http://docs.sun.com/source/806-3568/ncg_goldberg.html I know nothing about your application but you may indeed need something along the lines you suggested. Regards Chris Saunders Show quote "DJ" <D*@discussions.microsoft.com> wrote in message news:9B524941-7ACC-4D2F-9773-B12C9AB48AB9@microsoft.com... > Hello, > > In an application that worked fine until recently I have started to have > problems with calculations involving two doubles. For example: -24.708 + > 26.0 = 1.2920000000000016, however, -24.708 + 8.0 = -16.708. What would > cause this? I don't think the numbers are so large that it would be the > usual floating point calculation error because of rounding. How can I fix > it? I'd rather not change every calcuation in my program to include a > math.round... > > .Net Framework 1.1 version 1.1.4322 SP1 > Visual Basic - Visual Studio .Net 2003 > Windows XP > > Thanks, DJ <D*@discussions.microsoft.com> wrote:
> In an application that worked fine until recently I have started to have See http://www.pobox.com/~skeet/csharp/floatingpoint.html> problems with calculations involving two doubles. For example: -24.708 + > 26.0 = 1.2920000000000016, however, -24.708 + 8.0 = -16.708. What would > cause this? I don't think the numbers are so large that it would be the > usual floating point calculation error because of rounding. How can I fix > it? I'd rather not change every calcuation in my program to include a > math.round... -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too "DJ" <D*@discussions.microsoft.com> wrote in message I don't see a problem here. Why do you?news:9B524941-7ACC-4D2F-9773-B12C9AB48AB9@microsoft.com... > Hello, > > In an application that worked fine until recently I have started to have > problems with calculations involving two doubles. For example: -24.708 + > 26.0 = 1.2920000000000016, however, -24.708 + 8.0 = -16.708. What would > cause this? > I don't think the numbers are so large that it would be the Who said size has anything at all to do with this calculation? Rounding > usual floating point calculation error because of rounding. doesn't just happen for very large numbers. It happens for all of them. > How can I fix Decimal datatype> it? Show quote > I'd rather not change every calcuation in my program to include a > math.round... > > .Net Framework 1.1 version 1.1.4322 SP1 > Visual Basic - Visual Studio .Net 2003 > Windows XP > > Thanks, |
|||||||||||||||||||||||