So I tried to follow an example from: Fixed Point Arithmetic in C Programming, but I get the following error left shift count >= width of type
.
I did find others having this issue here on stackoverflow but I don't understand this error?
#include "contiki.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
//Define sizeof - macros
#define SHIFT_AMOUNT 16 // 2^16 = 65536
#define SHIFT_MASK ((1 << SHIFT_AMOUNT) - 1) // 65535 (all LSB set, all MSB clear)
static int price = 500 << SHIFT_AMOUNT;
void calcTest(){
price += 10 << SHIFT_AMOUNT;
price *= 3;
price /= 4; // now our price is ((500 + 10) * 3) / 4 = 382.5
printf("price integer is %d\n", price >> SHIFT_AMOUNT);
printf ("price fraction is %d\n", price & SHIFT_MASK);
}
//Defining two processors, one for making the 'knock' and one to listen
PROCESS(data_comp, "data_comp");
AUTOSTART_PROCESSES(&data_comp);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(data_comp, ev, data)
{
static struct etimer timer;
PROCESS_BEGIN();
/* Setup a periodic timer that expires after 10 seconds. */
etimer_set(&timer, CLOCK_SECOND * 10);
while(1) {
calcTest();
/* Wait for the periodic timer to expire and then restart the timer. */
PROCESS_WAIT_EVENT_UNTIL(etimer_expired(&timer));
etimer_reset(&timer);
}
PROCESS_END();
}