473,409 Members | 1,935 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,409 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 1576
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: 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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.