c语言中 1.f ; 65536.f 的意思

问题遇到的现象和发生背景

mpu6050的程序中看到的

问题相关代码,请勿粘贴截图

static int accel_self_test(long *bias_regular, long *bias_st)
{
int jj, result = 0;
float st_shift[3], st_shift_cust, st_shift_var;

get_accel_prod_shift(st_shift);
for(jj = 0; jj < 3; jj++) {
    st_shift_cust = labs(bias_regular[jj] - bias_st[jj]) / 65536.f;
    if (st_shift[jj]) {
        st_shift_var = st_shift_cust / st_shift[jj] - 1.f;
        if (fabs(st_shift_var) > test.max_accel_var)
            result |= 1 << jj;
    } else if ((st_shift_cust < test.min_g) ||
        (st_shift_cust > test.max_g))
        result |= 1 << jj;
}

return result;

}

1.f 就是float类型的1.0
65536.f 就是float类型的65536.0

还有就是由于算法库不同,除法等会要求除数为浮点数

因为整形相除的结果是整形,使用把65536.f转换为float类型。

加f表明该浮点数是float类型,否则默认为double类型

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632

C++ Floating-Point Constants
Floating-point constants specify values that must have a fractional part. These values contain decimal points (.) and can contain exponents.

Syntax

floating-constant :

fractional-constant exponent-partopt floating-suffixopt
digit-sequence exponent-part floating-suffixopt

fractional-constant :

digit-sequenceopt . digit-sequence
digit-sequence .

exponent-part :

e signopt digit-sequence
E signopt digit-sequence

sign : one of

digit-sequence :

digit
digit-sequence digit

floating-suffix :one of

f l F L

Floating-point constants have a “mantissa,” which specifies the value of the number, an “exponent,” which specifies the magnitude of the number, and an optional suffix that specifies the constant’s type. The mantissa is specified as a sequence of digits followed by a period, followed by an optional sequence of digits representing the fractional part of the number. For example:

18.46
38.

The exponent, if present, specifies the magnitude of the number as a power of 10, as shown in the following example:

18.46e0 // 18.46
18.46e1 // 184.6

If an exponent is present, the trailing decimal point is unnecessary in whole numbers such as 18E0.

Floating-point constants default to type double. By using the suffixes f or l (or F or L — the suffix is not case sensitive), the constant can be specified as float or long double, respectively.

Although long double and double have the same representation, they are not the same type. For example, you can have overloaded functions like

void func( double );

and

void func( long double );