Forum Discussion
Altera_Forum
Honored Contributor
22 years agoLong to Float
Hi,
I have a custom instruction which returns a float, but NIOS seems to grab this and treat it like a long, converted to float (if that makes sense) # include "system.h" int main (void) { float c = ALT_CI_IEEE_FPADD(a,http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/cool.gif ; printf("Answer = %f", c); return 0; } I get 0x40490fda returned by my CI, but c is printed as 1078530010 (that number!) how do I cast it as a float so I get 3.1415926 back? Regards, Steve.3 Replies
- Altera_Forum
Honored Contributor
How about this:
unsigned int ui = ALT_CI_IEEE_FPADD(a, http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/cool.gif ; float f = *((float*)&ui); Seems like an ugly hack to me but it works! Maybe there is a better way. - Altera_Forum
Honored Contributor
I could of swore I saw something about it not returning floating point data, but I may not have had my 6 cups of coffee before reading that.
I would use the hack that James suggested myself. - Altera_Forum
Honored Contributor
Thanks James,
Worked a treat! - if you want to see it all in action go to IP downloads there is a FP add and mult with CI project for download. Regards, Steve.