Divide operator doesnt work properly?
#1

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.?
Reply
#2

looks right u cant use whole numbers when using float

use instead :

pawn Код:
printf("%f", 10/5.0);
Reply
#3

use floatdiv(float1,float2)
Reply
#4

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)