Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Calculating a float for Infinity in DBP?

Author
Message
CodemanV
18
Years of Service
User Offline
Joined: 25th Aug 2005
Location: South Wales Valleys, UK
Posted: 12th Sep 2006 22:59
Hello

Currently polishing off some 2D collision functions in DBP and I've hit a snag.

Some of the routines require variables that store a value close to infinity.
e.g. C++ : (float) CloseEnoughToInfinity = 1e+10;

Anyone know the equivalent in DBP?

I've declared infinity as a global double float and tried using
infinity = Exp(0x1e)
OR
infinity = SqRt(0.00000000000000000000000000000000000000000001)

But I don't know if any of the above are correct. The value only needs to be calculated once and then referenced throughout the program.

I've never had to calculate infinity before so I am a bit clueless on this.

Any ideas?
Thanks for looking.
H4ck1d
18
Years of Service
User Offline
Joined: 27th Dec 2005
Location: Yes
Posted: 12th Sep 2006 23:11
An infinite number would take an infinite amount of time to calculate...

However, if you mean you want to use an extrememly small value, you could use scientific notation, I would assume...

There are 10 types of people, those who understand binary and those that don't.
The programmer's national anthem is 'AAAAAAAAHHHHHHHH'
Never forget: 2 + 2 = 5 for extremely large values of 2.
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Sep 2006 23:12
Create a memblock 4 bytes in size, write the hex value 0x7f800000 to it, then read the value back as a float.



Negative infinite needs a value of 0xff800000 and to get a NAN, use 0x7f800001 (there are lots of variations on NAN)

CodemanV
18
Years of Service
User Offline
Joined: 25th Aug 2005
Location: South Wales Valleys, UK
Posted: 12th Sep 2006 23:28
@IanM - Thanks very much for that - just what was required. I owe you 2 pints now.

Cheers!

Login to post a reply

Server time is: 2024-04-19 17:52:40
Your offset time is: 2024-04-19 17:52:40