How to tell the compiler to use float instead of double for constants.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-12-22 11:24 AM
Hi,
i noticed then when i declare a constant like this
#define PI 3.141592653
compiler use double instead of float wich is slowing down code execution. Is there a way to tell compiler to use float by default. instread of casting everywere in my code ?
I use keil µVision and C51
Tanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-12-22 11:39 AM
float pi = 3.14159f;
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-12-22 8:55 PM
This also works with define.
#define PI 3.14159f
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-12-22 11:01 PM
If you really want to optimize, you'll use something like:
#define PI_x10k = 314159
In practice, most android low level drivers use a format called Q31: 32 bit, 16 bit integers, 16 bit fractional.
1 = 0x0001 0000
0.25 = 0x0000 0100
4 = 0x0004 0000
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-12-23 5:58 PM
I use keil µVision and C51
You can't use C51 with STM32!!
:(
A complex system designed from scratch never works and cannot be patched up to make it work.
