473,385 Members | 1,764 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,385 software developers and data experts.

C# floating point consistency

I spent the wee hours of last night tracking down a lock-up bug that was
causing SorterObjectArray.QuickSort to loop indefinitely. It was comparing
an object with itself, and yet the IComparer function was returning -1! The
function was calculating the area of RectangleF on the object by
multiplying width and height and it turned out that the areas were coming
out different. Why? Because the second calculation is staying in the 80bit
register, while the first calculation was being written and recalled from a
32bit float in ram.

The workaround, in this specific case, is easy. I just compare to see if the
two variables point to the same object, but I'm concerned that C#/.NET
doesnt have a /Op option, like C++ does, to truncate all registers acting as
floats to 32bits. Have I missed it?

Jamie Briant
Nov 16 '05 #1
1 1575
On Sun, 11 Apr 2004 15:25:17 -0700, "news.microsoft.com"
<jab<dontspamme>@species.org> wrote:
The workaround, in this specific case, is easy. I just compare to see if the
two variables point to the same object, but I'm concerned that C#/.NET
doesnt have a /Op option, like C++ does, to truncate all registers acting as
floats to 32bits. Have I missed it?


You haven't. You might compare against a maximum threshold rather
than for equality, which is a smart thing to do anyway when you're
using FP calculations. But in general, C# and .NET are just not
particularly well suited to numerical applications.
--
http://www.kynosarges.de
Nov 16 '05 #2

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

Similar topics

15
by: David O'Farrell | last post by:
Is this only on solaris ? Python 2.3.3 (#1, Mar 19 2004, 16:18:33) on sunos5 Type "help", "copyright", "credits" or "license" for more information. >>> a= >>> print a.count(333),...
4
by: Dave | last post by:
Hi folks, I am trying to develop a routine that will handle sphere-sphere and sphere-triangle collisions and interactions. My aim is to develop a quake style collision engine where a player can...
5
by: Anton Noll | last post by:
We are using Visual Studio 2003.NET (C++) for the development of our software in the fields digital signal processing and numerical acoustics. One of our programs was working correctly if we are...
13
by: Dylan Nicholson | last post by:
I just posted regarding a possible floating point error (not sure where), and have since discovered that: float f = 5.15002; double d = 5.15002; if (float(d) < f) puts("huh 1?"); float f2 =...
687
by: cody | last post by:
no this is no trollposting and please don't get it wrong but iam very curious why people still use C instead of other languages especially C++. i heard people say C++ is slower than C but i can't...
10
by: Peter Ammon | last post by:
I'm fuzzy on exactly what I can depend on when doing floating point comparisons. I know that calculated values can differ, e.g. I'm not guaranteed that 1. + 2. == 3. What about comparisons with...
15
by: michael.mcgarry | last post by:
Hi, I have a question about floating point precision in C. What is the minimum distinguishable difference between 2 floating point numbers? Does this differ for various computers? Is this...
1
by: news.microsoft.com | last post by:
I spent the wee hours of last night tracking down a lock-up bug that was causing SorterObjectArray.QuickSort to loop indefinitely. It was comparing an object with itself, and yet the IComparer...
32
by: ma740988 | last post by:
template <class T> inline bool isEqual( const T& a, const T& b, const T epsilon = std::numeric_limits<T>::epsilon() ) { const T diff = a - b; return ( diff <= epsilon ) && ( diff >= -epsilon );...
39
by: rembremading | last post by:
Hi all! The following piece of code has (for me) completely unexpected behaviour. (I compile it with gcc-Version 4.0.3) Something goes wrong with the integer to float conversion. Maybe somebody...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.