// Copyright (2019-2023) Paul Scherrer Institute #ifndef JUNGFRAUJOCH_TO_FIXED_H #define JUNGFRAUJOCH_TO_FIXED_H #include #include inline uint16_t to_fixed(double val, uint16_t fractional_bits) { // If val is result of division by zero, only reasonable value of output is zero (otherwise number could be interpreted improperly) uint32_t int_val = std::isfinite(val) ? (std::lround(val * (1< UINT16_MAX) int_val = UINT16_MAX; return int_val; } #endif //JUNGFRAUJOCH_TO_FIXED_H