How do I save a floating point number using fblockwrite, and what exactly are floating point values?
#1

So, I was wondering what are floating point values? What defines how many decimals there are in a cell?
How many bits are there?

I also want to know how would I save one to a file if the bit size is different.


Thanks
Reply
#2

the best way to save floats is actually as ints:

pawn Код:
format(str, sizeof (str), "%d", floatnumber);
Then to read do:

pawn Код:
sscanf(in, "i", floatnumber);
If "floatnumber" is declared as a float this code will actually work by writing and reading the exact underlying bit pattern of the float, which is by far the best way to do it without loosing accuracy. For more information see IEEE 754.
Reply
#3

Ah I get it now, I thought they were more bits or something (to hold data for the exponent) But now I see it's done more cleverly. That also explains to me why when floats are printed with %d it just shows some massive integer.

Thanks!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)