Quote:
Originally Posted by ...
wow, lotta testy people today...
the only thing thats broken about that is your assumptions...
adding 0.0f to the return value of the macro will only cause the value that it created ( 0x85000000 ) to be cast to a float (2231369728.0f) and then add it to 0.0f, resulting in... well I assume you know at least basic math.
The whole point of the question is that you cannot modify bits directly in a float, but you can also not cast rvalues to a float using the methods I mentioned previously.
There is no need to turn this innocent question into a flame war.
Ok, let's start this off right then:
1) You post some vague ........, like so:
Quote:
but what about when I want to cast non lvalue bits to a float.
What exactly is a "non lvalue bits"? You want to make the right side a float? Or what exactly? Ok, so ........ing add 0.0 to it, and now it's a float.
2) You then say:
Quote:
pretend I want to make a macro that generates a negative float
What the hell is a "negative float"? A negative floating point number? Well, that's tough too. How about subtracting whatver it is from 0.0f?
3) Then you say:
Quote:
and then lets say I want to call a function that accepts a float and I want to pass in whatever this function returns.
Man, where to start with this? First off, this doesn't even parse as an English sentence. It's wrong. Well, ok, treat it as C. Well that doesn't work either, because MACROS do not return anything! They're not functions! They can evaluate to something, but they don't "return" anything.
4) Then you go on to say:
Quote:
The MAKE_NEG_FLOAT macro resolves to an integer, and then the func will cast that to a float rather than converting it to a float with the same bits. My question is this: is there any way, given the setup or a similar setup of code, that would allow me to convert the non-lvalue integer return of a macro directly to a float without casting?
Which I suppose means: "I have some floating point number, and I want to do bit shifting on it, and convert it back to a float." I guess. Is that what you're trying to do? Well you can't, because it's not defined by the standard, which means: ANYTHING YOU DO WILL DIFFER AT WILL! Seriously. If it's not defined, you have no control over what happens. It's prefectly fine for it to change each run time. It probably won't, but you can't assume that. Because it's not defined.
The bytes of a floating point number aren't stored as they are as an integer. That's why you can't shift them. That's why you can't mask them off. That's why anything you do to them isn't defined.
Oh, but you don't want to hear that. That's too bad. See, other people read this forum too. So forgive me if I point out things that people want to do that are wrong according to the standard. No, wait a minute, I don't give a ........ what you think. If you don't want to hear it's wrong, don't try to do something that's wrong. Or rather, don't ask people how to do something that's wrong, if you don't want them to tell you it's wrong.
Oh, wait, it gets better...
5) You also spit out this gem:
Quote:
adding 0.0f to the return value of the macro will only cause the value that it created ( 0x85000000 ) to be cast to a float (2231369728.0f) and then add it to 0.0f, resulting in... well I assume you know at least basic math.
Well now, had you actually said you just wanted to mung up the the bits and then take these munged up bits, turn them back into a floating point number, in the first place we'd have been all clear wouldn't we?
In short: No. Why would there be? Why would there be a way to take any random integer value and assume it's not really an integer, but a floating point number? Why on earth would the C language let you do this without a cast. Because that is what you want:
Quote:
is there any way, given the setup or a similar setup of code, that would allow me to convert the non-lvalue integer return of a macro directly to a float without casting?
What? How does this even make sense? Oh, right. There is a way! I forgot about it!
Code:
#include <stdstupid_float_magic.h>
I always forget that!
[edit]
Wait wait wait! It's even better! I forgot this one:
Quote:
I can't think of a reason I would ever need to do this, but lets pretend
And you're miffed because some one told you it's undefined. What a ........ing idiot.
[/edit]
Quzah.