Where does 1.0f and 1.0 make a difference?

While studying the video compression codec, I came across float rateRatio = 1.0f. I want to know where it matters? I mean 1.0f and 1.0?

+5
source share
3 answers

Like everything said, one literal has a type float, and the other has a type double. Here is an example where it matters:

#include <stdio.h>

int main(void)
{
    int a = 16777217 * 1.0f;
    int b = 16777217 * 1.0;

    printf("%d %d\n", a, b);
}

prints on my machine:

16777216 16777217

An expression 16777217 * 1.0fis of type floatand 16777217cannot be represented exactly in float(in IEEE-754), while it can be represented exactly in double.

+15
source

One doubleanother float:

double x = 0.0;  // denotes a double
float y  = 0.0f; // denotes a float

, , , Windows , float 32- , double 64-. , .

+7

float y = 0.0

, , . , (0.0, 1.0f, 1.0 ..).

float f = 1.0;

1.0 double, f - float, float, double d = 1.0f, float double.

, 16777217 * 1.0f ( ouah) float, 1.0f float float int float, float s, float, , , . .

, 1.0f 1.0, double, , , 16777217 * 1.0 a double ( , , double), , 16777217.

+5
source

All Articles