473,388 Members | 1,352 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Are System.Double operators overloaded for epsilon?

Are System.Double operators overloaded to perform epsilon comparisons, or do
these comparisons have to be performed by the programmer. In other words, if
I have two doubles, A and B, and I test "A > B", does C# do a strict
mathematical comparison, or does it do a "A - B > Double.Epsilon"
comparison? Thanks
Nov 17 '05 #1
4 1788
David,

I don't believe that epsilon is used in comparisons. If you need to
assure a degree of precision, then use the Decimal class, which will
guarantee precision (and therefore, remove the need for epsilons).

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"David Veeneman" <da****@nospam.com> wrote in message
news:ub**************@TK2MSFTNGP14.phx.gbl...
Are System.Double operators overloaded to perform epsilon comparisons, or
do these comparisons have to be performed by the programmer. In other
words, if I have two doubles, A and B, and I test "A > B", does C# do a
strict mathematical comparison, or does it do a "A - B > Double.Epsilon"
comparison? Thanks

Nov 17 '05 #2
David,

I believe the equality comparison is based on the binary pattern of the
operands, except for special cases (NaN).
It is programmer's responsibility to check against an Epsilon instead of
using '==' on floating point values.

Regards - Octavio

"David Veeneman" <da****@nospam.com> escribió en el mensaje
news:ub**************@TK2MSFTNGP14.phx.gbl...
Are System.Double operators overloaded to perform epsilon comparisons, or
do these comparisons have to be performed by the programmer. In other
words, if I have two doubles, A and B, and I test "A > B", does C# do a
strict mathematical comparison, or does it do a "A - B > Double.Epsilon"
comparison? Thanks

Nov 17 '05 #3
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
I don't believe that epsilon is used in comparisons. If you need to
assure a degree of precision, then use the Decimal class, which will
guarantee precision (and therefore, remove the need for epsilons).


Decimal doesn't guarantee precision - it certainly doesn't prevent
rounding errors etc. It just changes the set of numbers which can be
exactly represented.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4
They are not. IMO it's a good thing that they aren't since that would
be counter-intuitive, but I certainly would applaud an additional set
of standard methods to perform epsilon comparisons on floats &
doubles. I asked David Notario but I don't think he'll do it. :)

On Tue, 16 Aug 2005 14:57:46 -0500, "David Veeneman"
<da****@nospam.com> wrote:
Are System.Double operators overloaded to perform epsilon comparisons, or do
these comparisons have to be performed by the programmer. In other words, if
I have two doubles, A and B, and I test "A > B", does C# do a strict
mathematical comparison, or does it do a "A - B > Double.Epsilon"
comparison? Thanks

--
http://www.kynosarges.de
Nov 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Dave | last post by:
Hello all, I would like to solicit suggestions on how to most efficiently accomplish something. I have profiled the project I'm working on and have found that calls to fabs() are taking a very...
3
by: Hans Ginzel | last post by:
Hello, let us consider function int foo(char *name, void *data) { ... printf(name, data); /* Should be *data? */ ... }
0
by: Syanide | last post by:
here's a bit info for you fellas: eg.. you have Square classes u wanna add public static int operator+ (Square s1, Square s2) { // your code here } comparision operators..
44
by: Daniel | last post by:
I am grappling with the idea of double.Epsilon. I have written the following test: public void FuzzyDivisionTest() { double a = 0.33333d; double b = 1d / 3d; Assert.IsFalse(a == b,...
2
by: mbelew | last post by:
I'm seeing a very strange behavior with double precision subtraction. I'm using csUnit for testing. If I run the test by itself, the test passes. When I run the batch of tests, the test fails. ...
2
by: Fredrik Melin | last post by:
Is there any way to extend or write a own "System.Decimal"? In the doc its declared as <Serializable> Public Structure Decimal Implements IFormattable, IComparable, IConvertibleBut how do you...
6
by: R.Biloti | last post by:
Hi folks I wrote the naive program to show up the unit roundoff (machine precision) for single and double precision: #include <stdio.h> int main (void) { double x;
52
by: lcw1964 | last post by:
Greetings, all, I am trying to port a little bit of math code to gcc, that in the original version used the long double version of several functions (in particular, atanl, fabsl, and expl). I...
7
by: Kürşat | last post by:
Hi, I have a strange problem about a simple sum operation on a double variable. There is a loop in my application like this : double _max = 0.4; double _step = 0.1; for (double d = 0.0; i...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.