XROAD
xroad_decimal.h
Go to the documentation of this file.
1 
6 #pragma once
7 #include <stdint.h>
8 #include "xroad_conv.h"
9 
10 #ifdef __cplusplus
11 extern "C"
12 {
13 #endif
14 
21 static inline int64_t xroad_double_to_decimal(double val, int32_t denom)
22 {
23  return (int64_t)(val * denom + (val >= 0 ? 0.5 : -0.5));
24 }
25 
32 static inline double xroad_decimal_to_double(int64_t val, int32_t denom)
33 {
34  return (double)val / denom;
35 }
36 
37 #ifdef __cplusplus
38 }
39 #endif