Help.
I have a simple floating point calculation and depending on what thread it gets executed on, I get a different result. Here are the pieces of code: - class OmniCamera
-
{
-
private float m_PixelSize;
-
private float m_ImageHeight;
-
-
...
-
-
/// prints out the hex value of the floating point number.
-
private static string HexString(float val)
-
{
-
byte[] bytes = BitConverter.GetBytes(val);
-
string s = string.Empty;
-
for (int i = bytes.Length - 1; i >= 0; i--)
-
{
-
s += bytes[i].ToString("X2");
-
}
-
return s;
-
}
-
public bool WorldFromImage(Vector2 screenPosition, out Vector3 worldPoint)
-
{
-
worldPoint = new Vector3();
-
...
-
-
worldPoint.Y = (screenPosition.Y * this.m_PixelSize) - (this.m_ImageHeight / 2.0f);
-
-
Debug.WriteLine("worldPoint.Y: " + HexString(worldPoint.Y) +
-
" screenPosition.Y: " + HexString(screenPosition.Y) +
-
" m_PixelSize: " + HexString(this.m_PixelSize) +
-
" m_ImageHeight: " + HexString(this.m_ImageHeight));
-
Debug.WriteLine("worldPoint.Y: " + worldPoint.Y.ToString("r") +
-
" screenPosition.Y: " + screenPosition.Y.ToString("r") +
-
" m_PixelSize: " + this.m_PixelSize.ToString("r") +
-
" m_ImageHeight: " + this.m_ImageHeight.ToString("r"));
-
-
...
-
-
return true;
-
}
-
}
-
Here is the output of the code when worldFromImage( ...) gets executed from the worker thread:
worldPoint.Y: BFAA07A7 screenPosition. Y: 43EB1D26 m_PixelSize: 3D0240B8 m_ImageHeight: 420240B8
worldPoint.Y: -1.32835853 screenPosition. Y: 470.227722 m_PixelSize: 0.0318 m_ImageHeight: 32.5632
Here is the output of the code when worldFromImage( ...) gets executed from the main app thread:
worldPoint.Y: BFAA07A8 screenPosition. Y: 43EB1D26 m_PixelSize: 3D0240B8 m_ImageHeight: 420240B8
worldPoint.Y: -1.32835865 screenPosition. Y: 470.227722 m_PixelSize: 0.0318 m_ImageHeight: 32.5632
As you can see the right hand side of the equation has exactly the same values. But we get a different result from the different threads. I thought c# floating point followed the IEEE floating point standard, and I thought that guarenteed that floating point operations always returned the same value.
Any insight would be greatly appreciated. I would like to understand this behaviour.
-thanks
steve
3 1621 Plater 7,872
Recognized Expert Expert
Are you using Singles or Doubles, if you mix and match them, there will be conversion issues I think.
Are you using Singles or Doubles, if you mix and match them, there will be conversion issues I think.
Everything is singles (floats). But even if i was mixing and matching I would expect the same result each time through.
Plater 7,872
Recognized Expert Expert
Yeah it *should* be the same, as long as its called with identical data.
Seems like this line is the issue yes?
worldPoint.Y = (screenPosition .Y * this.m_PixelSiz e) - (this.m_ImageHe ight / 2.0f);
I did the following and always go the same number: -
float m_PixelSize=13.24572F;
-
float m_ImageHeight=7.5757F;
-
float screenPosition = 3.4F;
-
for (int i = 0; i < 10; i++)
-
{
-
float Y = (screenPosition * m_PixelSize) - (m_ImageHeight / 2.0f);
-
System.Diagnostics.Debug.WriteLine(Y.ToString() + "=(" + screenPosition + "*" + m_PixelSize + ")-(" + m_ImageHeight + "/2.0F)");
-
}
-
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: JS |
last post by:
We have the same floating point intensive C++ program that runs on
Windows on Intel chip and on Sun Solaris on SPARC chips. The program
reads the exactly the same input files on the two platforms. However,
they generate slightly different results for floating point numbers.
Are they really supposed to generate exactly the same results? I
guess so because both platforms are supposed to be IEEE floating point
standard (754?) compliant. ...
|
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 using the
Debug-Version of the program, but it fails (or leads to false
results) if we are using the Release-Version. After a long
debugging session we found out, that our program was working
correctly, but the floating point processing...
|
by: meltedown |
last post by:
I would like the floating divs to float and then the header to come
after them , on the left. That's what I thought clearing the floats was
for, but in this example, the header is to the right of the floating
divs, nothing is cleared. What am I doing wrong ?
Here is the url:http://www.reenie.org/test/test5.php
Here is the code:
<html>
<head>
|
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 believe that. in pieces
of the application where speed really matters you can still use "normal"
functions or even static methods which is basically the same.
in C there arent the simplest things present like constants, each struct and
enum...
|
by: Vinoth |
last post by:
I'm working in an ARM (ARM9) system which does not have Floating point
co-processor or Floating point libraries. But it does support long long int
(64 bits).
Can you provide some link that would discuss about ways to emulate floating
point calculations with just long int or long long int. For eg., if i've a
formula X=(1-b)*Y + b*Z in floating point domain, i can calculate X with
just long ints (but, some data may be lost in final division;...
| |
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 the EPSILON? I know in float.h a FLT_EPSILON is defined to be
10^-5. Does this mean that the computer cannot distinguish between 2
numbers that differ by less than this epsilon?
|
by: jacob navia |
last post by:
Hi people
I continue to work in the tutorial for lcc-win32, and started to try to
explain the floating point flags.
Here is the relevant part of the tutorial. Since it is a difficult part,
I would like your expert advise before I publish any serious nonsense.
Any comments are welcome, style, organization, hard errors, etc.
|
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 );
}
int main()
{
std::deque<double> pt ;
|
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 out there understands what happens.
Essentially, when I subtract the (double) function value GRID_POINT(2) from
a variable which has been assigned the same value before this gives a
non-zero result and I really do not understand why.
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |