Page 1 of 1

libpacket & floats

Posted: Wed Mar 15, 2006 12:08 pm
by tumnes
I was playing around with making some vif packets using the library provided in ps2sdk. For some reason when I try to append a float, it gets all messed up. My guess is the compiler is trying to convert it to an unsigned int. So I a list of vertices:
float *vertices = {...};
and when I try to do:
packet_append_32(&packet, vertices);
It puts something strange in where the float should be.

Now I was able to get around it by doing this:
u32 *vertices2 = vertices;
packet_append_32(&packet, vertices2);
And the results were as expected.

Now my question is: What is the proper way to do this?

Posted: Wed Mar 15, 2006 12:27 pm
by cheriff
You pretty much got it. When gcc sees you passing floats to a function expecting ints, it automatically does the conversion. For example 5.0f -> 5 which have different binary representations.

I usually keep several pointers of differing types to the same array/packet usually 32/64/128bit and floats to make putting stuff into them eaire.

Alternatively, you could use casting to the same effect:

Code: Select all

packet_append_32(&packet, ((u32*)vertices2)[i]); 
Would do the same thing, but is quit ugle IMO. Each to his own.[/code]