Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fix16.h
00001 #ifndef __FIX16_H__ 00002 #define __FIX16_H__ 00003 #define FIX_SHIFT 16 00004 00005 typedef int32_t fix16_t; 00006 00007 static const fix16_t fix16_one = 1 << FIX_SHIFT; 00008 static const fix16_t fix16_100 = 100 << FIX_SHIFT; 00009 static const fix16_t fix16_half = 0x00008000; 00010 00011 static inline fix16_t fix16_add(fix16_t x, fix16_t y) { return x + y; } 00012 static inline fix16_t fix16_sub(fix16_t x, fix16_t y) { return x - y; } 00013 static inline fix16_t fix16_mul(fix16_t x, fix16_t y) { return (fix16_t)(((int64_t)x * y) >> FIX_SHIFT); } 00014 static inline fix16_t fix16_div(fix16_t x, fix16_t y) { return (fix16_t)(((int64_t)x << FIX_SHIFT) / y); } 00015 00016 inline fix16_t fix16_abs(fix16_t value) { return value > 0 ? value : -value; } 00017 00018 static inline fix16_t fix16_from(int x) { return x << FIX_SHIFT; } 00019 static inline fix16_t fix16_from(float x) { return (fix16_t)(fix16_one * x); } 00020 00021 static inline int fix16_to_int(fix16_t x) { return x >> FIX_SHIFT; } 00022 static inline float fix16_to_float(fix16_t x) { return (float)x / fix16_one; } 00023 00024 00025 00026 00027 #endif //__FIX16_H__
Generated on Tue Jul 12 2022 21:15:25 by
