Horde3D

Next-Generation Graphics Engine
It is currently 27.04.2024, 05:33

All times are UTC + 1 hour




Post new topic Reply to topic  [ 9 posts ] 
Author Message
PostPosted: 03.10.2008, 04:02 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
I don't know you know or not, but currently I'm busy with optimizing utMath.Recently I've checked the SSE optimized utMath [utMath_rc3] for problems and comparing the returned results from original utMath with utMath_rc3.But sometimes [not too much] utMath_rc3 returns -0 instead of 0.This happend a few times on Matrix4f class : Inverted() .

I've tested the code with MinGW/GCC 3.4.5 compiler and there isn't any -0 , only MSVC [2005] returns -0 !

Do you have any idea about why MSVC compiled code generates -0 ?

[I'm using winxp sp2 + PentiumIII 750MHz + 256MB RAM SD]


Top
 Profile  
Reply with quote  
PostPosted: 03.10.2008, 16:12 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
-0 is the same as 0, it is just an artefact of the binary representation of numbers. Some standard library implementations print -0 as 0, and some don't.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 03.10.2008, 16:20 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
I fear that this will be problematic in future and generate runtime errors because they are float types :|


Top
 Profile  
Reply with quote  
PostPosted: 03.10.2008, 18:52 
Offline

Joined: 22.11.2007, 17:05
Posts: 707
Location: Boston, MA
Siavash wrote:
I fear that this will be problematic in future and generate runtime errors because they are float types :|
Why would it cause any problems? They are exactly the same number, just with a slightly different representation in bits. For a float you have some number of bits containing the value, and an additional bit for the sign. Flipping the sign bit negates the number, so flipping the sign bit on 0 gives you -0.

You can check for yourself that the sign on zero doesn't matter for any basic operations:

n + 0.0 = n and n - 0.0 = n
n * 0.0 = 0.0 and n * (-0.0) = -0.0
n / 0.0 = INF and n/(-0.0) = INF
0.0 == -0.0 => True

Remember, -0 does not exist - it is merely an artefact of the binary representation of floating point numbers, and affects nothing except the print function. If you look at the IEEE spec for floating point, you will also see that there can be multiple representations for INF and NAN.

_________________
Tristam MacDonald - [swiftcoding]


Top
 Profile  
Reply with quote  
PostPosted: 03.10.2008, 19:02 
Offline
Engine Developer

Joined: 10.09.2006, 15:52
Posts: 1217
From Wikipedia:

Quote:
−0 is the representation of negative zero or minus zero, a number that, in computing, exists in some signed number representations for integers, and in most floating point number representations. In mathematical terms there is no concept of a negative (or positive) zero, and −0 is equal to, and represented as, zero.

In common usage, −0 may be used to denote a negative number rounded to zero, or a number approaching zero from the negative direction. In statistical mechanics, certain systems in a state of population inversion may be considered to have an absolute temperature of −0, the hottest possible absolute temperature (see negative temperature).


Top
 Profile  
Reply with quote  
PostPosted: 03.10.2008, 20:34 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
Thank you very much dear marciano and swiftcoder :idea:


Top
 Profile  
Reply with quote  
PostPosted: 04.10.2008, 09:51 
Offline

Joined: 18.05.2008, 17:47
Posts: 96
I am more concerned about matrix multiplication and floats :?


Top
 Profile  
Reply with quote  
PostPosted: 08.10.2008, 23:43 
Offline

Joined: 26.03.2008, 02:58
Posts: 160
If i may be so bold as to recommend you read Essential Mathematics for Games (2nd edition) first chapter deals with numerical representations (i think this chapter is available for free, but i am not certain). It tackles this topic and others that you may find interesting.


Top
 Profile  
Reply with quote  
PostPosted: 09.10.2008, 16:10 
Offline

Joined: 21.08.2008, 11:44
Posts: 354
Thanks a lot dear DDd :wink:


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 30 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group