?

Log in

No account? Create an account
Wizard question - dmv/blogs/lj

> Recent Entries
> Archive
> Friends
> Profile
> dmv/index

Links
dmv/index

Alt. Info Streams
Twitter
Memestream
Flickr Stream

August 7th, 2002


Previous Entry Share Next Entry
01:43 pm - Wizard question
In C++

Our floating point library needs a value for inf and -inf. Presently, this was done by

min_real_val = -1.0 / 0.0;

and the obvious counter to that. This causes the compiler (our compiler, even) to complain... but it works (I believe). Is there a better way to get these values?

(12 comments | Leave a comment)

Comments:


[User Picture]
From:daemonv
Date:August 7th, 2002 01:06 pm (UTC)

More Monkeys!

(Link)
Itanium assembly is funny.

And I'm shocked to have no responses... :(
[User Picture]
From:skamille
Date:August 7th, 2002 02:12 pm (UTC)

Re: More Monkeys!

(Link)
Ah, I didn't know you were doing Itanium stuff. I am stuck in itanium hell. Heeelllllllll.
[User Picture]
From:daemonv
Date:August 7th, 2002 07:12 pm (UTC)

Re: More Monkeys!

(Link)
Yes. The compiler I am modifying (Open64) is SGI's internal compiler which had the GCC frontend added, open sourced, and retargeted to ia64. While it is fun to have an account on an actual ia64 machine (the emulators suck) -- and it is amusing to have first person anectodal stories about how bad the ia32 emulation is -- it is not all fun.
[User Picture]
From:daemonv
Date:August 7th, 2002 01:41 pm (UTC)
(Link)
Based on these three results, I was able to find my answer.

inf := 0x7F800000 | 0x7FF0000000000000

-inf := 0xFF800000 | 0xFFF0000000000000


[User Picture]
From:ssaiscps
Date:August 7th, 2002 05:22 pm (UTC)
(Link)
inf = 0.0

while (0 == 0){
inf += 1.0
}

return inf
[User Picture]
From:combinator
Date:August 7th, 2002 05:56 pm (UTC)
(Link)
I'm not convinced that infinity is an integer.
[User Picture]
From:ssaiscps
Date:August 7th, 2002 06:00 pm (UTC)
(Link)
Of course its not. Its a float.
[User Picture]
From:daemonv
Date:August 7th, 2002 07:19 pm (UTC)
(Link)
I'm not convinced (0==0) is the proper conditional. If one wanted to take this approach, (inf >= 0) might make sense. Otherwise, I fear 0==0 would have some kind of run-in with Mr. C. Propagation and the Dead Code Eliminator (a plausible bandname).
[User Picture]
From:ssaiscps
Date:August 7th, 2002 07:24 pm (UTC)
(Link)
I've participated in arguments over whether code optimizers should remove infinite loops or not. I think that this doesn't actually work with finite precision floating point numbers anyways. Eventually it will just stop increasing. So really you need to double it every time to get that overflow you crave. Or is overflow different than infinity? Hopefully.
[User Picture]
From:daemonv
Date:August 7th, 2002 07:40 pm (UTC)
(Link)
Well, in the perfect compiler (see 'full employment theory for compiler writers') they would be.

I believe that, yes, inf is not just overflow. But it is pretty close. And raises interesting questions of what 'inf'++ means, or 'inf'--.
As I posted already, there are fixed values (and I believe NaN surrounds them).

[User Picture]
From:ssaiscps
Date:August 7th, 2002 07:52 pm (UTC)
(Link)
I thought that the perfect compiler would reduce all non-terminating, non-side-effectful programs into a single goto statement, not into nothing.
[User Picture]
From:daemonv
Date:August 7th, 2002 07:54 pm (UTC)
(Link)
Point, ssaicps.

> Go to Top
LiveJournal.com