/
Sangak
/
inav
Обзор
Документация
Войти
/
Sangak
/
inav
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
src/main/common/encoding.c
50 строк
2 KB
Pawel Spychalski (DzikuVx)
remove all traces of optimizations
07 апр 2023, 11:41
07 апр 2023, 11:41
393a90d
Код
Авторство
О чём код?
/* * This file is part of Cleanflight. * * Cleanflight is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Cleanflight is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>. */ #include "platform.h" #include "encoding.h" /** * Cast the in-memory representation of the given float directly to an int. * * This is useful for printing the hex representation of a float number (which is considerably cheaper * than a full decimal float formatter, in both code size and output length). */ uint32_t castFloatBytesToInt(float f) { union floatConvert_t { float f; uint32_t u; } floatConvert; floatConvert.f = f; return floatConvert.u; } /** * ZigZag encoding maps all values of a signed integer into those of an unsigned integer in such * a way that numbers of small absolute value correspond to small integers in the result. * * (Compared to just casting a signed to an unsigned which creates huge resulting numbers for * small negative integers). */ uint32_t zigzagEncode(int32_t value) { return (uint32_t)((value << 1) ^ (value >> 31)); }