Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

隐式转换警告优化 #49

Open
Cherish-Gww opened this issue Oct 31, 2024 · 1 comment
Open

隐式转换警告优化 #49

Cherish-Gww opened this issue Oct 31, 2024 · 1 comment

Comments

@Cherish-Gww
Copy link

Cherish-Gww commented Oct 31, 2024

https://github.com/hpmicro/hpm_sdk/blob/276af9395fde9ca963ac5bf7ad1e516163168bfa/drivers/src/hpm_enc_pos_drv.c#L52C1-L53C1

当打开-Werror=double-promotion编译参数时,该出会出现float to double的隐式转换。

建议修改为:

uint32_t encoder_rad_to_position(float rad)
{
    double tmp = (double)rad;
    const double _2pi = 6.283185307179586;

    while (tmp < 0) {
        tmp += _2pi;
    }
    while (tmp > _2pi) {
        tmp -= _2pi;
    }

    return (uint32_t)((tmp / _2pi) * (double)0xFFFFFFFF);
}
@Cherish-Gww Cherish-Gww changed the title 编译警告优化 隐式转换警告优化 Oct 31, 2024
@chenzhihong007
Copy link

好的,谢谢提醒,将在下一个release修复。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants