2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
24 * Cast the in-memory representation of the given float directly to an int.
26 * This is useful for printing the hex representation of a float number (which is considerably cheaper
27 * than a full decimal float formatter, in both code size and output length).
29 uint32_t castFloatBytesToInt(float f
)
31 union floatConvert_t
{
38 return floatConvert
.u
;
42 * ZigZag encoding maps all values of a signed integer into those of an unsigned integer in such
43 * a way that numbers of small absolute value correspond to small integers in the result.
45 * (Compared to just casting a signed to an unsigned which creates huge resulting numbers for
46 * small negative integers).
48 uint32_t zigzagEncode(int32_t value
)
50 return (uint32_t)((value
<< 1) ^ (value
>> 31));