[riot-notifications] [RIOT-OS/RIOT] arduino-due problem with time functions? (#14133)

Marian Buschsieweke notifications at github.com
Mon May 25 20:22:16 CEST 2020


When you have to use `float` or `double`, then go for it. But here it is not needed. In fact, every API in xtimer works on integer types anyway. So just keep the time values in `uint32_t` or (if you need a higher range) in `uint64_t` and keep the resolution at µs. If you want to print the time in ms with a decimal place, you could do something like this:

```C
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>

static inline void print_us_as_ms(uint32_t time_us)
{
    uint32_t time_ms = time_us / 1000;
    uint32_t remainder = time_us % 1000;
    printf("%" PRIu32 ".%03" PRIu32 " ms", time_ms, remainder);
}
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/RIOT-OS/RIOT/issues/14133#issuecomment-633676154
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.riot-os.org/pipermail/notifications/attachments/20200525/3f6af127/attachment.htm>


More information about the notifications mailing list