Project
Loading...
Searching...
No Matches
TypeTruncation.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
15
16#ifndef MATHUTILS_INCLUDE_MATHUTILS_DETAIL_TYPETRUNCATION_H_
17#define MATHUTILS_INCLUDE_MATHUTILS_DETAIL_TYPETRUNCATION_H_
18
19#ifndef GPUCA_GPUCODE_DEVICE
20#include <cstdint>
21#endif
22
23namespace o2
24{
25namespace math_utils
26{
27namespace detail
28{
29
30static float truncateFloatFraction(float x, uint32_t mask = 0xFFFFFF00)
31{
32 // Mask the less significant bits in the float fraction (1 bit sign, 8 bits exponent, 23 bits fraction), see
33 // https://en.wikipedia.org/wiki/Single-precision_floating-point_format
34 // mask 0xFFFFFF00 means 23 - 8 = 15 bits in the fraction
35 constexpr uint32_t ProtMask = ((0x1u << 9) - 1u) << 23;
36 union {
37 float y;
38 uint32_t iy;
39 } myu;
40 myu.y = x;
41 myu.iy &= (ProtMask | mask);
42 return myu.y;
43}
44
45} // namespace detail
46} // namespace math_utils
47} // namespace o2
48
49#endif /* MATHUTILS_INCLUDE_MATHUTILS_DETAIL_TYPETRUNCATION_H_ */
GLint GLenum GLint x
Definition glcorearb.h:403
GLint GLuint mask
Definition glcorearb.h:291
const int iy
Definition TrackUtils.h:69
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...