ATLAS Offline Software
Loading...
Searching...
No Matches
FloatPacker.h
Go to the documentation of this file.
1// This file's extension implies that it's C, but it's really -*- C++ -*-.
2
3/*
4 Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
5*/
6
7// $Id$
14
15
16#ifndef CXXUTILS_FLOATPACKER_H
17#define CXXUTILS_FLOATPACKER_H
18
19
20#include <string>
21#include <stdint.h>
22
23
24
25namespace CxxUtils {
26
27
58{
59public:
61 typedef uint32_t Packdest;
62
63
74 FloatPacker (int nbits,
75 int nmantissa,
76 double scale = 1,
77 bool is_signed = true,
78 bool round = false);
79
80
90 Packdest pack (double src, std::string* err = nullptr) const;
91
92
100 double unpack (Packdest val, std::string* err = nullptr) const;
101
102
103private:
106
108 double m_scale;
109
112
115
118
121
124
127
130
133
136
139};
140
141
142} // namespace CxxUtils
143
144
145#endif // not CXXUTILS_FLOATPACKER_H
int m_nmantissa
Number of bits in the mantissa + sign bit.
double unpack(Packdest val, std::string *err=nullptr) const
Unpack the value VAL.
Packdest pack(double src, std::string *err=nullptr) const
Pack a value.
Packdest m_npack_ones
Mask with that many low bits set.
int m_min_exp
Minimum exponent value.
int m_nexp
Number of exponent bits.
uint32_t Packdest
Type into which we pack.
Definition FloatPacker.h:61
FloatPacker(int nbits, int nmantissa, double scale=1, bool is_signed=true, bool round=false)
Constructor.
bool m_is_signed
Should we use a sign bit?
double m_invscale
Inverse of scale.
int m_npack
Number of bits in mantissa (exclusive of any sign bit).
int m_max_exp
Maximum exponent value.
Packdest m_nexp_ones
Mask with that many low bits set.
Packdest m_signmask
Mask containing the sign bit (or 0 if there's no sign bit).
bool m_round
Should we round instead of truncating?
double m_scale
Scale factor for stored numbers.