Home > Back-end >  Consult everybody bosses: floating-point and integer arithmetic, the issue of * 1.0
Consult everybody bosses: floating-point and integer arithmetic, the issue of * 1.0

Time:04-01

Double m;
Int t, I;
M= 1.0 * I/t;

If there is no * 1.0 accuracy is not

I want to ask, is this related to casting, if did not have the * 1.0 , m is transformed from type double type int

Beginners' new, please teach more

CodePudding user response:

M=(double)/I (double) t;
Also go

Constants are type
1.0 is a double type
1.0 f is a float type
1 is a plastic
1 u is unsigned integer
1 l is long integer

1.0 * and * 1.0 is not the same thing!

M=1.0 * I/t;
And
I/t * m=1.0;
Is not the same thing,


CodePudding user response:

1.0 to take is actually tells the compiler, the operation according to the floating point calculation to deal with, rather than integer,

Instead of integer programming, m m=the right hand side is according to the integer arithmetic or according to the floating-point arithmetic to calculate problem,
1.0 is the default type double,

CodePudding user response:

Arithmetic operations and relational operations, every operation step to perform implicit type promotion rules,
But the assignment operator, the results cast to the left to the right of the type, and then copy the value in the past,
  • Related