SA-MP Forums Archive
How do I save a floating point number using fblockwrite, and what exactly are floating point values? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How do I save a floating point number using fblockwrite, and what exactly are floating point values? (/showthread.php?tid=352737)



How do I save a floating point number using fblockwrite, and what exactly are floating point values? - [HLF]Southclaw - 20.06.2012

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


Re: How do I save a floating point number using fblockwrite, and what exactly are floating point values? - Y_Less - 20.06.2012

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.


Re: How do I save a floating point number using fblockwrite, and what exactly are floating point values? - [HLF]Southclaw - 20.06.2012

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!