Jump to content
  • Advertisement
Sign in to follow this  
LackOfGrace

Visual Studio 2005 and INFINITY

This topic is 3925 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi i could get a valid INFINITY define under visual studio 2003 using some hacks found on this forum now i changed to visual studio 2005 and cant for my life get a valid INFINITY define anyone got infinity to work under visual studio 2005? (ive also had problems with the compiler not finding global variables in headers, whats up with that?)

Share this post


Link to post
Share on other sites
Advertisement
What language? C++? And what do you mean infinity? The floating point value? Or do you need it as a double? And what do you need it for?

As for the compiler not finding globals in a header file, can you provide an example?

Share this post


Link to post
Share on other sites
Do you want a value representing infinity as a floating point number? If that is the case and you use C++, then couldn't you just use:
std::numeric_limits<float>::infinity();
?

Quote:
(ive also had problems with the compiler not finding global variables in headers, whats up with that?)

You need to give us more information to help you with that.

Share this post


Link to post
Share on other sites
Quote:

anyone got infinity to work under visual studio 2005?

Working with infinities is generally not a good idea, as they (and NaNs, etc) can (historically) cause some severe performance degradation on certain processors. They're also nonsensical and propagate strange conditions into your code that need to be properly handled in rather obnoxious and inelegant ways.

GCC's libc has an INFINITY macro in math.h. I don't know if it's standard, offhand. If it isn't, that probably explains why you don't have it. If you're using C++, you want to use std::numeric_limits<T>::infinity() (for some T where std::numeric_limits<T>::has_infinity is true, e.g., float or double). This is in the C++ header limits (#include <limits>).

Quote:

(ive also had problems with the compiler not finding global variables in headers, whats up with that?)

Well, you really shouldn't be doing that, either. But if you are, it just sounds like you're doing it wrong. Post an example before you lash out at the tools, because it doesn't reflect well on you.

Share this post


Link to post
Share on other sites
well, my application is in C++.

but the infinity hacky stuff is residing in a external library (chipmunk physics) wich is made with C.

the global variable problem is when writing something like

// INFINITY HACK
float tmp = 1.0;
float inf = 1.0 / ( tmp - 1.0);
#define INFINITY inf

writing that would define the INFINITY keyword, but when im using it vs tells me that inf is not defined

could be the jump from extern "C" to c++
but i dunno ( havent checked that problem through, so could be some sort of linkage problem on my side )

INFINITY in the library was defined as
#define INFINITY (1e1000) (wich throws a constant too big error)
i do think its intended to be "true" infinity or else something like FLT_MAX would work

i know that this sounds like REALLY bad coding practice, but its just to make an external library working

Share this post


Link to post
Share on other sites
Quote:
Original post by LackOfGrace
well, my application is in C++ but its going to be used in a external library (chipmunk physics library) wich is made with C.

the global variable problem is when writing something like

// INFINITY HACK
float tmp = 1.0;
float inf = 1.0 / ( tmp - 1.0);
#define INFINITY infinity

writing that would define the INFINITY keyword, but when im using it vs says that its inf is not defined

could be the jump from extern "C" to c++
but i dunno ( havent checked that problem through, so could be some sort of linkage problem on my side )


i know that this sounds like REALLY bad coding practice, but its just to make an external library working
No, writing that causes the preprocessor to do a search and replace from INFINITY to infinity. And infinity isn't defined anywhere. inf is defined, however, and it'll cause you all sorts of trouble with variables defined in multiple source files because the headers are being pulled into every source file that includes them.

You still haven't said why you need infinity though...

Share this post


Link to post
Share on other sites
sorry, typo error
i meant

// INFINITY HACK
float tmp = 1.0;
float inf = 1.0 / ( tmp - 1.0);
#define INFINITY inf

yes yes i know, this is lousy as hell, but its just an example


and well, i dont really know why i need infinity.
all i know is that the physics library i want to get working produces errors with the INFINITY define not really beeing infinity

( by the way , i just love the reply times here at gamedev :3 )

Share this post


Link to post
Share on other sites
Quote:
Original post by LackOfGrace
sorry, typo error
i meant

// INFINITY HACK
float tmp = 1.0;
float inf = 1.0 / ( tmp - 1.0);
#define INFINITY inf
If that's your exact code, and that's in a header file, it's getting dragged into every source file you include it into, and will cause linker errors.

What's the error you get? And why do you need infinity anyway?

EDIT: Ah, you edited your post [smile]
Does the physics API say it needs you to use infinity? Does it not provide its own define for infinity? As jpetrie said, it's really not a good idea to use special floating point NaNs...

Share this post


Link to post
Share on other sites
if it would have been accual code i would have used an #ifdef check before the INFINITY define

and again the physics library i want to get working produces errors with the INFINITY define not really beeing infinity

the physics library uses INFINITY when dealing with static bodies, dont ask me why, it just does
and the reason why im having these problems is that it isnt written using visual stuido and therefore could define infinity as (1.0/0.0) (wich visual studio dont accept)

( edit. i tend to edit my posts a number of times, since im currently in some sort of zombie mode ( the work day is almost over, no oxygen, overtime) )

Share this post


Link to post
Share on other sites
Quote:
Original post by LackOfGrace
if it would have been accual code i would have used an #ifdef check before the INFINITY define
That still won't help - the variables will still be instanced in multiple source files. The preprocessor guards work on a per-source file basis.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!