Divide operator doesnt work properly? - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Divide operator doesnt work properly? (
/showthread.php?tid=272899)
Divide operator doesnt work properly? -
pen_theGun - 30.07.2011
Do i something wrong or does divide operator work incorrect?! Here are some examples
pawn Код:
printf( "%f", 5.0/8 ); // OK => 0.625000
printf( "%f", 5/8.0 ); // OK => 0.625000
printf( "%f", 5/8 ); // Wrong? => 0.000000
printf( "%d", 5/8 ); // Wrong? => 0
printf( "%d", 10/5 ); // OK => 2
printf( "%f", 10/5 ); // Wrong? => 0.000000
printf( "%f", float(10/5) ); // OK => 2.000000
Isnt job of print to provide me an correct output, instead of making float(10/5) etc.?
Re: Divide operator doesnt work properly? -
jamesbond007 - 30.07.2011
looks right u cant use whole numbers when using float
use instead :
Re: Divide operator doesnt work properly? -
cessil - 30.07.2011
use floatdiv(float1,float2)
Re: Divide operator doesnt work properly? - Double-O-Seven - 30.07.2011
I can tell you what's wrong: Nothing.
pawn Код:
printf( "%f", 5.0/8 ); // OK => 0.625000
printf( "%f", 5/8.0 ); // OK => 0.625000
printf( "%f", 5/8 ); // Wrong? => 0.00000 NOT WRONG! 5 / 8 == 0 is an integer division. (See below)
printf( "%d", 5/8 ); // Wrong? => 0 NOT WRONG! That's an integer divison. 5 / 8 is not an integer and smaller than 1.
printf( "%d", 10/5 ); // OK => 2
printf( "%f", 10/5 ); // Wrong? => 0.000000 NOT WRONG! 10 / 5 == 2 is an integer division.
// It's binary form is 0b0000...010 (30 zeros, 1 one and 1 zero.). However, 0b000...010 as integer is not the same number as floating point number which is in this case probably a number very close to 0.
printf( "%f", float(10/5) ); // OK => 2.000000
The only problem here is that you did not understand what exactly happens.